1. Crea el vector correspondiente a las ganancias de póker por día con el siguiente código.
2. El reto:
Las ganancias , expresadas en dólares, en una ruleta fueron las siguientes durante la semana:
lunes -48
martes 151
miércoles 198
jueves -16
viernes 134
sábado -153
domingo 126
Con la función combine c() crea un vector numérico de las ganancias denominado ruleta_gan. Posteriormente, asocia cada ganancia a los días de la semana que corresponden.
## [1] "numeric"
dia<- c("lunes","martes","miercoles","jueves","viernes","sabado","domingo")
ruleta_gan_dia <- data.frame(ruleta_gan,dia)
ruleta_gan_dia## ruleta_gan dia
## 1 -48 lunes
## 2 151 martes
## 3 198 miercoles
## 4 -16 jueves
## 5 134 viernes
## 6 -153 sabado
## 7 126 domingo
IDEAS:
¿Cuántos tipos de vectores necesitas para resolver lo anterior?
Utilice 2 tipos de vectores, el vector numeric
ruleta_gany el vector caracterdiay lo asocié mediante un data.frame¿Podrías hacerlo únicamente con la función combine c()?
Sí, pero se mantendría como un solo vector, es decir:
ruleta_gan_1 <- c("lunes","martes","miercoles","jueves","viernes","sabado","domingo",-48, 151, 198, -16, 134, -153, 126)y posteriormente transformarlo a matriz
## [,1] [,2] ## [1,] "lunes" "-48" ## [2,] "martes" "151" ## [3,] "miercoles" "198" ## [4,] "jueves" "-16" ## [5,] "viernes" "134" ## [6,] "sabado" "-153" ## [7,] "domingo" "126"
3. Crea un dataframe, con la función data.frame(), que contenga:
- Como primera columna una variable denominada ‘secuencia’ y que sea un vector de números de longitud 6 y que empiece en con el número 3.
- Como segunda columna una variable denominada ‘aleatorio’ y que sean 6 números aleatorios generados desde una distribución normal.
- Como tercera columna una variable denominada ‘letras’ que contengan las primeras 6 letras del abecedario.
## secuencia aleatorio letras
## 1 3 0.1514300 a
## 2 4 0.7250879 b
## 3 5 -0.7874959 c
## 4 6 -0.4955871 d
## 5 7 1.0740012 e
## 6 8 -0.6578101 f
4. Crea un dataframe denominado ‘potter’ a partir de los siguientes vectores:
sales_hp <- c(497066400, 426630300, 401608200, 399302200, 377314200,
359788300, 357233500, 328833900, 141823200, 189432500,
142414700, 135197600, 99635700, 92756000, 134119300,
138752100)
matriz_hp <- matrix(sales_hp, nrow = 8, byrow = F)
matriz_hp## [,1] [,2]
## [1,] 497066400 141823200
## [2,] 426630300 189432500
## [3,] 401608200 142414700
## [4,] 399302200 135197600
## [5,] 377314200 99635700
## [6,] 359788300 92756000
## [7,] 357233500 134119300
## [8,] 328833900 138752100
titles_hp <- c(
"1. HP and the Sorcerer's Stone",
"8. HP and the Deathly Hallows Part 2",
"4. HP and the Goblet of Fire",
"2. HP and the Chamber of Secrets",
"5. HP and the Order of the Phoenix",
"6. HP and the Half-Blood Prince",
"3. HP and the Prisoner of Azkaban",
"7. HP and the Deathly Hallows Part 1")## titles_hp X1 X2
## 1 1. HP and the Sorcerer's Stone 497066400 141823200
## 2 8. HP and the Deathly Hallows Part 2 426630300 189432500
## 3 4. HP and the Goblet of Fire 401608200 142414700
## 4 2. HP and the Chamber of Secrets 399302200 135197600
## 5 5. HP and the Order of the Phoenix 377314200 99635700
## 6 6. HP and the Half-Blood Prince 359788300 92756000
## 7 3. HP and the Prisoner of Azkaban 357233500 134119300
## 8 7. HP and the Deathly Hallows Part 1 328833900 138752100
## 'data.frame': 8 obs. of 3 variables:
## $ titles_hp: chr "1. HP and the Sorcerer's Stone" "8. HP and the Deathly Hallows Part 2" "4. HP and the Goblet of Fire" "2. HP and the Chamber of Secrets" ...
## $ X1 : num 4.97e+08 4.27e+08 4.02e+08 3.99e+08 3.77e+08 ...
## $ X2 : num 1.42e+08 1.89e+08 1.42e+08 1.35e+08 9.96e+07 ...
## [1] 8 3
## [1] 3
## [1] 8