x <- 3
y <- 2
# resta -, Multiplicación *. División /
division_entera <- x %/% y
division_entera
## [1] 1
redondear_arriba <- ceiling(x/y)
redondear_arriba
## [1] 2
redondear_abajo <- floor(x/y)
redondear_abajo
## [1] 1
residuo <- x %% y
residuo
## [1] 1
potencia <- x**2
potencia
## [1] 9
raiz <- x**(1/2)
raiz
## [1] 1.732051
exponencial <- exp(1)
exponencial
## [1] 2.718282
absoluto <- abs(x)
absoluto
## [1] 3
signo <- sign(x)
signo
## [1] 1
#constantes
pi
## [1] 3.141593
radio <- 10
area_circulo <- pi*radio**2
area_circulo
## [1] 314.1593
#vectores
a <- c(1,2,3,4,5)
a
## [1] 1 2 3 4 5
b <- c(1:100) #los : significan numeros enteros del 1 al 100
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(1,100, by = 0.5) #ahora se ponen con .5 todos los numeros
c
## [1] 1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 6.0 6.5
## [13] 7.0 7.5 8.0 8.5 9.0 9.5 10.0 10.5 11.0 11.5 12.0 12.5
## [25] 13.0 13.5 14.0 14.5 15.0 15.5 16.0 16.5 17.0 17.5 18.0 18.5
## [37] 19.0 19.5 20.0 20.5 21.0 21.5 22.0 22.5 23.0 23.5 24.0 24.5
## [49] 25.0 25.5 26.0 26.5 27.0 27.5 28.0 28.5 29.0 29.5 30.0 30.5
## [61] 31.0 31.5 32.0 32.5 33.0 33.5 34.0 34.5 35.0 35.5 36.0 36.5
## [73] 37.0 37.5 38.0 38.5 39.0 39.5 40.0 40.5 41.0 41.5 42.0 42.5
## [85] 43.0 43.5 44.0 44.5 45.0 45.5 46.0 46.5 47.0 47.5 48.0 48.5
## [97] 49.0 49.5 50.0 50.5 51.0 51.5 52.0 52.5 53.0 53.5 54.0 54.5
## [109] 55.0 55.5 56.0 56.5 57.0 57.5 58.0 58.5 59.0 59.5 60.0 60.5
## [121] 61.0 61.5 62.0 62.5 63.0 63.5 64.0 64.5 65.0 65.5 66.0 66.5
## [133] 67.0 67.5 68.0 68.5 69.0 69.5 70.0 70.5 71.0 71.5 72.0 72.5
## [145] 73.0 73.5 74.0 74.5 75.0 75.5 76.0 76.5 77.0 77.5 78.0 78.5
## [157] 79.0 79.5 80.0 80.5 81.0 81.5 82.0 82.5 83.0 83.5 84.0 84.5
## [169] 85.0 85.5 86.0 86.5 87.0 87.5 88.0 88.5 89.0 89.5 90.0 90.5
## [181] 91.0 91.5 92.0 92.5 93.0 93.5 94.0 94.5 95.0 95.5 96.0 96.5
## [193] 97.0 97.5 98.0 98.5 99.0 99.5 100.0
d <- rep(0, times = 40) #se repite ese num de veces el mismo numero
d
## [1] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
## [39] 0 0
nombres <- c("angela", "juan", "ana")
nombres
## [1] "angela" "juan" "ana"
edad <- c(21, 20, 22)
edad
## [1] 21 20 22
tabla <- data.frame (nombres,edad) #es para hacer una tabla
tabla
## nombres edad
## 1 angela 21
## 2 juan 20
## 3 ana 22
summary(tabla) #analizar tablas
## nombres edad
## Length:3 Min. :20.0
## Class :character 1st Qu.:20.5
## Mode :character Median :21.0
## Mean :21.0
## 3rd Qu.:21.5
## Max. :22.0
str(tabla) #estructura de la tabal
## 'data.frame': 3 obs. of 2 variables:
## $ nombres: chr "angela" "juan" "ana"
## $ edad : num 21 20 22
tabla$edad #de la tabla, me regresa los valores de edad, en la columna de edad con meses
## [1] 21 20 22
tabla$meses <- tabla$edad*12
tabla
## nombres edad meses
## 1 angela 21 252
## 2 juan 20 240
## 3 ana 22 264
#ejercicio 1
#generar una tabla con el nombre de los pacientes, su pedo, su IMC, y su clasificación
# ifelse(condicion, cierto, falso)
nombre <- c("David", "Carlos", "José", "Rafa", "Caleb")
altura <- c(1.70, 1.72, 1.80, 1.75, 1.99)
peso <- c(50, 70, 80, 100, 340)
tabla <- data.frame (nombre,altura,peso)
tabla
## nombre altura peso
## 1 David 1.70 50
## 2 Carlos 1.72 70
## 3 José 1.80 80
## 4 Rafa 1.75 100
## 5 Caleb 1.99 340
tabla$imc <- tabla$peso / tabla$altura**2
tabla
## nombre altura peso imc
## 1 David 1.70 50 17.30104
## 2 Carlos 1.72 70 23.66144
## 3 José 1.80 80 24.69136
## 4 Rafa 1.75 100 32.65306
## 5 Caleb 1.99 340 85.85642
tabla$clasificacion <- ifelse(tabla$imc<18.5, "bajo peso",
ifelse(tabla$imc<=24.9, "normal",
ifelse(tabla$imc<=29.9, "sobrepeso", "obesidad")))
tabla
## nombre altura peso imc clasificacion
## 1 David 1.70 50 17.30104 bajo peso
## 2 Carlos 1.72 70 23.66144 normal
## 3 José 1.80 80 24.69136 normal
## 4 Rafa 1.75 100 32.65306 obesidad
## 5 Caleb 1.99 340 85.85642 obesidad
# continuacion de vectores
longitud <- length(a)
longitud
## [1] 5
orden_ascendente <- sort(tabla$imc)
orden_ascendente
## [1] 17.30104 23.66144 24.69136 32.65306 85.85642
orden_descentende <- sort(tabla$imc, decreasing = TRUE)
orden_descentende
## [1] 85.85642 32.65306 24.69136 23.66144 17.30104
#grafica
plot(altura,peso, main="Grafica de altuta y peso",xlab="altura",ylab="peso")
This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.
When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
summary(cars)
## speed dist
## Min. : 4.0 Min. : 2.00
## 1st Qu.:12.0 1st Qu.: 26.00
## Median :15.0 Median : 36.00
## Mean :15.4 Mean : 42.98
## 3rd Qu.:19.0 3rd Qu.: 56.00
## Max. :25.0 Max. :120.00
You can also embed plots, for example:
Note that the echo = FALSE parameter was added to the
code chunk to prevent printing of the R code that generated the
plot.