library(readxl) TV_and_movie_habits <- read_xlsx (“C:/Users/USUARIO/Desktop/TV and movie habits.xlsx”)
library(readxl)
TV_and_movie_habits <- read_xlsx("C:/Users/USUARIO/Desktop/TV and movie habits.xlsx")
#Taller 1 - TV and Movie Habits
library(tidyverse)
str(TV_and_movie_habits)
## tibble [25 × 5] (S3: tbl_df/tbl/data.frame)
## $ id : num [1:25] 1 2 3 4 5 6 7 8 9 10 ...
## $ Tv Source : chr [1:25] "Hulu Plus" "Amazon Prime" "Hulu Plus" "Netflix" ...
## $ Hours per week : num [1:25] 14 18 20 5 12 10 8 7 24 30 ...
## $ Binge Frequency: chr [1:25] "Not at all" "Sometimes" "Frequently" "Frequently" ...
## $ Sex : chr [1:25] "Male" "Female" "Female" "Male" ...
#### id: Variable cualitativa (categórica), nominal
#### TV Source: Variable cualtivativa (categórica), nominal
#### Hours per week: Variable numérica, continua de razón
#### Binge frequency: Variable cualitativa (categórica), ordinal
#### Sex: Variable cualitativa (categórica), binaria
table(TV_and_movie_habits$Sex)
##
## Female Male
## 13 12
porcentaje <- c (52,48)
etiqueta <- paste( porcentaje, "%", sep = "")
colores <- c ("pink","blue")
pie (porcentaje, labels = etiqueta, clockwise = TRUE, col = colores, main = "Sexo de los participantes")
legend ("topright", c("female", "male"), cex = 0.5, fill = colores)
table(TV_and_movie_habits$`Binge Frequency`)
##
## Frequently Not at all Sometimes
## 11 2 12
#Gráfico diagrama de barras
Eje_Y <- c (12,11,2)
Eje_X <- c ("Sometimes","Frequently", "Not at all")
barplot (Eje_Y, xlab = "Frecuencia de atracones compulsivos de series de TV o películas", ylab = "Frecuencia", main = "Diagrama de barras - Atracones de series de TV o películas", names.arg = Eje_X, col = "orange", border = "brown")
table(TV_and_movie_habits$`Tv Source`)
##
## Amazon Prime Cable Hulu Plus iTunes Netflix
## 3 2 3 9 8
porcentajess <- c (12,8,12,36,32)
etiqueta <- paste (porcentajess, "%", sep = "")
colores <- c ("lightblue", "lightgrey", "lightyellow","lightgreen","white")
pie (porcentajess, labels = etiqueta, clockwise = TRUE, col = colores, main = "Plataformas de streaming populares")
legend ("topright", c("Amazon Prime", "Cable", "Hulu Plus", "Itunes", "Netflix"), cex = 0.5, fill = colores)
summary(TV_and_movie_habits$`Hours per week`)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 2.00 10.00 14.00 14.64 19.00 30.00
table(TV_and_movie_habits$`Hours per week`)
##
## 2 5 7 8 10 12 13 14 15 17 18 19 20 21 22 23 24 30
## 1 1 1 2 3 2 1 3 1 1 2 1 1 1 1 1 1 1
TV_and_movie_habits$hoursperweek_new <- ifelse(TV_and_movie_habits$`Hours per week` >= 16, 1, 0)
table(TV_and_movie_habits$hoursperweek_new)
##
## 0 1
## 15 10
TV_and_movie_habits$hours_per_week_new_label <- factor(TV_and_movie_habits$hoursperweek_new, labels = c("no","yes"))
table (TV_and_movie_habits$hours_per_week_new_label)
##
## no yes
## 15 10
# Gráfico diagrama de barras
Eje_Y <- c (15,10)
Eje_X <- c ("No hay riesgo","Riesgo")
barplot (Eje_Y, xlab = "Índice de salud mental", ylab = "Frecuencia", main = "Diagrama de barras - Riesgo para la salud mental", names.arg = Eje_X, col = "Gray", border = "red")
legend ("topright", c("Riesgo = pantallas >16h", "No riesgo = pantallas <16h"), cex = 0.5)