Your code is correct except that you need to store the results of functions. For example, if you run
df %>% mutate(host_identity_verified=recode(host_is_superhost, "0"="VERIFICA", "1"="NO VERIFICA"))
the result of the function is printed to the console, but it is not stored anywhere. Run this instead
df <- df %>% mutate(host_identity_verified=recode(host_is_superhost, "0"="VERIFICA", "1"="NO VERIFICA"))
and the result is stored in df.
library(dplyr)
df <- structure(list(host_is_superhost = c(0L, 0L, 0L, 0L, 1L, 0L,
1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L),
host_identity_verified = c(1L,
0L, 1L, 0L, 0L, 1L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L,
0L, 0L, 0L),
bathrooms = c(3L, 3L, 3L, 3L, 3L, 3L, 5L, 3L, 3L,
3L, 3L, 3L, 5L, 17L, 5L, 3L, 3L, 3L, 3L, 3L),
bedrooms = c(1L,
1L, 1L, 1L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 1L, 2L, 1L, 1L,
1L, 1L, 1L),
daily_price = c(94L, 125L, 100L, 120L, 70L, 200L,
700L, 250L, 100L, 280L, 320L, 240L, 290L, 290L, 220L, 84L, 60L,
99L, 110L, 110L),
security_deposit = c(1L, 31L, 1L, 48L, 13L,
48L, 1L, 73L, 13L, 1L, 1L, 1L, 1L, 1L, 1L, 38L, 1L, 56L, 1L,
1L),
minimum_nights = c(2L, 2L, 2L, 2L, 30L, 15L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 2L, 30L, 3L, 2L, 2L),
number_of_reviews = c(84L,
3L, 70L, 57L, 44L, 79L, 72L, 126L, 377L, 22L, 31L, 1L, 3L, 48L,
10L, 56L, 7L, 7L, 103L, 107L),
review_scores_rating = c(94L,
100L, 97L, 97L, 90L, 98L, 96L, 98L, 94L, 95L, 95L, 40L, 60L,
94L, 86L, 91L, 100L, 94L, 95L, 94L)),
row.names = c(NA, 20L), class = "data.frame")
#change the variables in “host_is_superhost” from 0, 1 to: “SI” y, “NO”. (using recode).
df <- df %>% mutate(host_is_superhost=recode(host_is_superhost, "0"="SI", "1"="NO"))
#change the variables in “host_identity_verified” from 0, 1 to: “VERIFICA” y “NO VERIFICA”.
df <- df %>% mutate(host_identity_verified=recode(host_is_superhost, "0"="VERIFICA", "1"="NO VERIFICA"))
##filter the dataset buy apartaments with minimal nights <=7.
ApNochesMenorIgual7<-df[(df$minimum_nights<=7),]
##create a cathegoric vector “CATEGORÍA”: if review_scores_rating <= 49 ~ 'NO ACONSEJABLE',
#review_scores_rating >= 50 & review_scores_rating <= 75 ~ 'ESTANDAR',
#review_scores_rating >= 76 & review_scores_rating <=100 ~ 'TOP'
df <- df %>% mutate(df, CATEGORIA = case_when(
review_scores_rating <= 49 ~ 'NO ACONSEJABLE',
review_scores_rating >= 50 & review_scores_rating <= 75 ~ 'ESTANDAR',
review_scores_rating >= 76 & review_scores_rating <=100 ~ 'TOP'
))
##Show a frequency table for CATEGORÍA.
table(df$CATEGORIA)
#>
#> ESTANDAR NO ACONSEJABLE TOP
#> 1 1 18
Created on 2022-10-31 with reprex v2.0.2