w <- women
w
## height weight
## 1 58 115
## 2 59 117
## 3 60 120
## 4 61 123
## 5 62 126
## 6 63 129
## 7 64 132
## 8 65 135
## 9 66 139
## 10 67 142
## 11 68 146
## 12 69 150
## 13 70 154
## 14 71 159
## 15 72 164
# Cuantas variables
# Cuantas observaciones
# Que tipo de datos es
str(w)
## 'data.frame': 15 obs. of 2 variables:
## $ height: num 58 59 60 61 62 63 64 65 66 67 ...
## $ weight: num 115 117 120 123 126 129 132 135 139 142 ...
class(w)
## [1] "data.frame"
# Es el promedio aritmético de valore numéricos
mean(w$height)
## [1] 65
max(w$height)
## [1] 72
min(w$height)
## [1] 58
sort(w$height)
## [1] 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
median(w$height)
## [1] 65
w <- women # Volveremos a generar w
# Agregandodos registros
w <- rbind(w, c(70, 146)) # height y weight
# Otra forma
w<- rbind.data.frame(w, c(71, 164))
w
## height weight
## 1 58 115
## 2 59 117
## 3 60 120
## 4 61 123
## 5 62 126
## 6 63 129
## 7 64 132
## 8 65 135
## 9 66 139
## 10 67 142
## 11 68 146
## 12 69 150
## 13 70 154
## 14 71 159
## 15 72 164
## 16 70 146
## 17 71 164
moda <- table(w$height)
moda # Se repite mas veces
##
## 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
## 1 1 1 1 1 1 1 1 1 1 1 1 2 2 1
set.seed(10) # Semilla para todas generen lo mismo
numeros <- sample(70:100, size = 100, replace = TRUE)
numeros
## [1] 85 79 83 91 72 76 78 78 89 83 90 87 73 88 81 83 71 78 82 95 96 89 94
## [24] 81 82 91 95 77 93 81 86 72 75 97 83 93 95 99 91 85 78 77 70 92 77 74
## [47] 70 85 73 94 80 99 77 84 75 88 84 84 82 85 70 73 84 82 95 93 87 83 72
## [70] 76 72 86 89 86 71 86 81 99 77 76 96 84 76 89 76 70 94 78 75 75 85 92
## [93] 88 86 81 95 77 86 93 70
# sacamos la moda de numeros
moda <- table(numeros)
# plot()
# plot(numeros)
plot(x=1:100, y=numeros, type = "p") # Es igual
plot(x=1:100, y=numeros, type = "l") # Es igual
#### Generando un histograma
hist(x=numeros, breaks=10, col = "pink")
hist(x=numeros, breaks=70, col = "pink")
barplot(height = numeros, col = "blue",
xlab = "Numeros", ylab = "valores", main = "Los numeros generados", names.arg = numeros)
w <- women
barplot(w$height, col = "blue", xlab = "Personas", ylab = "Alturas", names.arg = 1:length(w$height), main = "Height de w")
numeros
## [1] 85 79 83 91 72 76 78 78 89 83 90 87 73 88 81 83 71 78 82 95 96 89 94
## [24] 81 82 91 95 77 93 81 86 72 75 97 83 93 95 99 91 85 78 77 70 92 77 74
## [47] 70 85 73 94 80 99 77 84 75 88 84 84 82 85 70 73 84 82 95 93 87 83 72
## [70] 76 72 86 89 86 71 86 81 99 77 76 96 84 76 89 76 70 94 78 75 75 85 92
## [93] 88 86 81 95 77 86 93 70
stem(numeros) # Se visualzia la moda
##
## The decimal point is 1 digit(s) to the right of the |
##
## 7 | 000001122223334
## 7 | 555566666777777888889
## 8 | 01111122223333344444
## 8 | 55555666666778889999
## 9 | 0111223333444
## 9 | 55555667999
boxplot(numeros)
median(numeros)
## [1] 83
quantile(numeros)
## 0% 25% 50% 75% 100%
## 70 77 83 89 99
summary(numeros)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 70.00 77.00 83.00 83.29 89.00 99.00
datos <- data.frame(nombre=c("Hugo", "Paco", "Luis", "Paty", "Robert", "Mary"), genero=c('M', 'M', 'M', 'F', 'M', 'F'))
datos
## nombre genero
## 1 Hugo M
## 2 Paco M
## 3 Luis M
## 4 Paty F
## 5 Robert M
## 6 Mary F
table(datos)
## genero
## nombre F M
## Hugo 0 1
## Luis 0 1
## Mary 1 0
## Paco 0 1
## Paty 1 0
## Robert 0 1
genero <- table(datos$genero)
# Determina mediante pastel graph n[umero de personas por genero
# pie()
pie(genero, main = "Personas por cada Género", labels = names(datos$genero))