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 tiene
# cuantas desviaciones
#que tipo de dato 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"
mean(w$heigth)
## Warning in mean.default(w$heigth): argument is not numeric or logical:
## returning NA
## [1] NA
max(w$heigth)
## Warning in max(w$heigth): ningun argumento finito para max; retornando -Inf
## [1] -Inf
min(w$heigth)
## Warning in min(w$heigth): ningún argumento finito para min; retornando Inf
## [1] Inf
sort(w$heigth)
## NULL
mean(w$height)
## [1] 65
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
moda <- table(w$height)
moda # se repuite 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 1 1 1
# es multimodal
#Agregando un dato
w<-women #volvemos a generar
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
max(moda)
## [1] 2
set.seed(10)
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 los numeros
table(numeros)
## numeros
## 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
## 5 2 4 3 1 4 5 6 5 1 1 5 4 5 5 5 6 2 3 4 1 3 2 4 3
## 95 96 97 99
## 5 2 1 3
#plot()
# plot(numeros)
plot(x=1:100, y=numeros, type="b") #es igual b a ambos
plot(x=1:100, y=numeros, type="p") #es igual p a puntos
plot(x=1:100, y=numeros, type="l") #es igual l a lineas
## Generando un histograma (grafica de barras)
hist(x=numeros, breaks=30, col = "purple")
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")
## Regresando a los numeros para ver ## Grafica de hojas y de cajas
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 visualiza 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 numero de personas por genero
#pie()
pie(table(datos$genero), main = "Personas por cada genero")