create a frame with intervals from one columm of one dataframe

Hello!

Kan anyone help me?

I have a dataframe (df), and want to create one factor with the name CATEGORIA, from column (review_scores_rating), like this:

if review_scores_rating<=49 change to (NO ACONSEJABLE)
if 50<=review_scores_rating <=75 change to (ESTANDAR)
if 76<=review_scores_rating <=100 change to (TOP)

I have tryed a lot, but did not make it...

Thank you.

You can do it with something like this:

library(dplyr)

df %>% 
    mutate(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'
    ))

If you need more specific help, please provide a proper REPRoducible EXample (reprex) illustrating your issue.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.