mis_valores <- {x <- 1:10; y <- x^2 } otros_valores <- { lista <- mis_valores + 2 } temp_f <- c(20, 33, 47, 49, 34, 52, 57, 33, 29, 76) prep_p <- c(.5, 2.7, .4, .5, 2, 4.7, 1, 4.7, 1.7, 2) temp_c <- {5*(temp_f - 32)/9} prep_m <- {prep_p * 25.4} #{x <- as.integer(readline("Ingrese un numero entero: ")); if (x %% 2 == 0) cat(x, "es numero par\n") else cat(x, "es numero impar\n")} #{x <- as.integer(readline("Ingrese un numero entero: ")); #y <- as.integer(readline("Ingrese otro numero entero: ")); #if (x %% y == 0) cat(x, "/", y, "es exacta\n") else cat(x, "/", y, "no es exacta\n")} #{a <- NULL; if (0 == 1 && a > 5) cat(a, "es mayor que 5\n")} #{ #altura <- as.numeric(readline("Ingrese altura: ")); #peso <- as.numeric(readline("Ingrese peso: ")); #edad <- as.numeric(readline("Ingrese edad: ")); #IMC <- peso / altura ^ 2; #cat("Riesgo: "); #if (IMC < 22 && edad < 45) cat("bajo\n") #else if (IMC >= 22 && edad >= 45) cat("alto\n") #else cat("medio\n") #} x <- c(49,79,03,35,878,04,43,03) y <- c(76,34,56,98,009,56,43,76) {ifelse(x >= y, x, y)} potencia_vec <- function(x, n=2){ y <- x^n } riesgo_car <- function(altura, peso, edad){ IMC <- peso / altura ^ 2; if (IMC < 22 && edad < 45) riesgo <- "bajo" else if (IMC >= 22 && edad >= 45) riesgo <- "alto" else riesgo <- "medio" } convertir <- function(x){ for (i in 1:length(x)){ if (x[i] < 0) x[i] <- -1 * x[i] } x } suma <- function(x){ s <- 0; for (i in 1:length(x)){ s <- s + x[i] } s } indice <- function(x, val){ ind <- 0; for (i in 1:length(x)){ if (x[i] == val && ind == 0) {ind <- i} } ind } imprimir <- function(){ i <- 1 repeat { if (i == 5) break print(i); i <- i + 1; } } potencias2 <- function(){ i <- 0 while (2^i < 1000){ print(paste(i, 2^i)) i <- i + 1 } } dados <- function(puntaje){ comb <- 0; for (i in 1:6){ for (j in i:6){ if (i + j == puntaje){ cat(i, j, "\n"); comb <- comb + 1 } } } comb }