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
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$height) #promedio aritmetico de alturas
## [1] 65
max(w$height) #valor maximo de altura
## [1] 72
min(w$height) #valor minimo de altura
## [1] 58
sort(w$height)
## [1] 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
#la mediana es la distribucion intermedia de un conjunto de datos ordenados
median(w$height)
## [1] 65
#Valor que mas se repite
#hay muchas formas
#utilizando la funcion table
#agregar un dato
w<-rbind(w,c(70,146))
#otra forma de agregar
w<-rbind.data.frame(w,c(71,164))
moda<-table(w$height)
moda #se repite which.max(moda)
##
## 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)
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
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) #graficar los numeros
plot(x=1:100,y=numeros,type = "l") #Es lo mismo que lo anterior
###Generar un histograma
hist(x=numeros,col = 'pink')
hist(x=numeros,breaks = 30,col = 'pink')
hist(x=numeros,breaks = 70,col = 'pink')
###Graficas de barras
barplot(w$height,col="blue",xlab = "Persona",ylab = "Alturas",main = "Los numeros generados",names.arg = 1:length(w$height))
###Grafica de tallo y hojas
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
#grafica de tallo y hoja
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
#Otra distribucion de datos con variables categoricas
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)
##
## F M
## 2 4
#Determinar mediante una grafica de pastel el numero de personas por genero
pie(x=table(datos$genero),main = "Personas por cada genero")