x <- 3
y <- 2
x
## [1] 3
y
## [1] 2
suma <- x+y
suma
## [1] 5
resta <- x-y
resta
## [1] 1
multiplicacion <- x*y
multiplicacion
## [1] 6
division <- x/y
division
## [1] 1.5
division_entera <- x%/%y
division_entera
## [1] 1
residuo <- x%%y
residuo
## [1] 1
potencia <- x^2
potencia
## [1] 9
potencia <- x**2 # tambien se puede con **
potencia
## [1] 9
raiz_cuadrada <- sqrt(x)
raiz_cuadrada
## [1] 1.732051
raiz_cubica <- x^(1/3)
raiz_cubica
## [1] 1.44225
exponencial <- exp(1)
exponencial
## [1] 2.718282
absoluto <- abs(x) # Quita el negativo
absoluto
## [1] 3
signo <- sign(x)
signo
## [1] 1
redondeo_arriba <- ceiling(division)
redondeo_arriba
## [1] 2
redondeo_abajo <- floor(division)
redondeo_abajo
## [1] 1
truncar <- trunc(division)
truncar
## [1] 1
pi
## [1] 3.141593
radio <- 5
area_circulo <- pi * radio^2
area_circulo
## [1] 78.53982
a <- c(1,2,3,4,5) # Juntarlos
a
## [1] 1 2 3 4 5
b <- c(1:100) # Secuencia de enteros
b
## [1] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
## [19] 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
## [37] 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
## [55] 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
## [73] 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
## [91] 91 92 93 94 95 96 97 98 99 100
c <- seq(2,5,by=0.5) # Secuencia especifica
c
## [1] 2.0 2.5 3.0 3.5 4.0 4.5 5.0
d <- rep (1:2, times = 3) # Repetir vector
d
## [1] 1 2 1 2 1 2
e <- rep(1:2, each = 3) # Repetir elementos
e
## [1] 1 1 1 2 2 2
f <- c("pera","manzana","kiwi","fresa")
f
## [1] "pera" "manzana" "kiwi" "fresa"
longitud <- length(a)
longitud
## [1] 5
promedio <- mean(a)
promedio
## [1] 3
rango <- max(a)-min(a)
rango
## [1] 4
resumen <- summary(a)
resumen
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 1 2 3 3 4 5
orden_ascendente <- sort(a)
orden_ascendente
## [1] 1 2 3 4 5
orden_descendente <- sort(a,decreasing = TRUE)
orden_descendente
## [1] 5 4 3 2 1
g <- c(1,2,3,4,5)
suma_vectores <- a+g
suma_vectores
## [1] 2 4 6 8 10
plot(a,g,main="Ventas por Mes",xlab = "Mes",ylab = "M USD",type = "b")
calificacion <-71
if (calificacion>=70){
print("Pasa")
}else{
print("No Pasa")
}
## [1] "Pasa"
df <- data.frame(a,g) # Tienen que medir lo mismo
df
## a g
## 1 1 1
## 2 2 2
## 3 3 3
## 4 4 4
## 5 5 5
Registra el nombre, peso, altura, calcula su IMC y asigna su categoria
nombre = c("Kamilah", "Luis", "Santiago","Marcelo")
peso = c(57, 84, 85,64)
altura = c(1.77, 1.84, 1.70,1.76)
BMI = c(18.19,23.6,29.4,20.7)
df <- data.frame(nombre,altura,peso)
df$IMC <- df$peso/df$altura^2
df$Clasificacion <- ifelse(
df$IMC < 18.5, "Peso bajo",
ifelse(
df$IMC < 25, "Normal",
ifelse(
df$IMC < 30, "Sobrepeso",
ifelse(
df$IMC < 35, "Obesidad grado 1",
ifelse(
df$IMC < 40, "Obesidad grado 2",
"Obesidad grado 3")))))