library(dslabs)
data("murders")

#1.

head(murders)
##        state abb region population total
## 1    Alabama  AL  South    4779736   135
## 2     Alaska  AK   West     710231    19
## 3    Arizona  AZ   West    6392017   232
## 4   Arkansas  AR  South    2915918    93
## 5 California  CA   West   37253956  1257
## 6   Colorado  CO   West    5029196    65
reg <- murders$region
frec_x_region <- table(reg)
frec_x_region
## reg
##     Northeast         South North Central          West 
##             9            17            12            13

2. Use el dataset movielens del paquete dslabs y responda.

#library(dslabs)
data("movielens")
head(movielens)
##   movieId                                   title year
## 1      31                         Dangerous Minds 1995
## 2    1029                                   Dumbo 1941
## 3    1061                                Sleepers 1996
## 4    1129                    Escape from New York 1981
## 5    1172 Cinema Paradiso (Nuovo cinema Paradiso) 1989
## 6    1263                        Deer Hunter, The 1978
##                             genres userId rating  timestamp
## 1                            Drama      1    2.5 1260759144
## 2 Animation|Children|Drama|Musical      1    3.0 1260759179
## 3                         Thriller      1    3.0 1260759182
## 4 Action|Adventure|Sci-Fi|Thriller      1    2.0 1260759185
## 5                            Drama      1    4.0 1260759205
## 6                        Drama|War      1    2.0 1260759151

a.¿Cuántas filas hay?

rows <- movielens
filas <- nrow(rows)
print(filas)
## [1] 100004

b. ¿Cuántas variables hay?

v <- movielens
cvar <- ncol(v)
print(cvar)
## [1] 7

c. ¿Qué tipo es la variable title?

class(movielens$title)
## [1] "character"

d. ¿Qué tipo es la variable genres?

class(movielens$genres)
## [1] "factor"

e. ¿Cuántos niveles hay en la variable genres?

nlevels(movielens$genres)
## [1] 901

3. Utilice el operador $ para acceder a los datos del tamaño de la población y almacenarlos en el objeto pop. A continuación, utilice la función order() para redefinir pop de modo que esté ordenado. Por último, utilice el operador [ ] para informar del menor tamaño de población.