mutate() two products in one column for male and female

Hello friends,

Please, I tried many times the way of select "BusinnessMen Magazine" for men and "BusinessWomen Magazine" for women

Just Appear for "BusinessWomen Magazine" for Female sex, but I don´t know how to select "BusinessMen Magazine" for male sex.

This works as the picture:

people2 <- people1 %>%
filter(gender == "Female") %>%
mutate(Product = (Business_Women_Magazine <- data.frame(BW, BWP, stringsAsFactors = FALSE))

But how can I try this:
Business_Men_Magazine <- data.frame(BM, BMP, stringsAsFactors = FALSE)))

Both magazines in just one column

If anyone can help me, it will be very useful, thanks!

I ´ve just resolved it, anyway I can share the answer, maybe could be useful

people2 <- people1 %>%
mutate(product = case_when(
gender == "Female"~ "BusinessWomen Magazine",
gender == "Male" ~ "BusinessMan Magazine"

Thank you community, nice people!

I think what you want is something like this.

people2 <- people1 %>% 
  mutate(Product = ifelse(gender == "female", "BusinessWoman Magazine", "BusinessMan Magazine"),
         BP = ifelse(gender == "female", 500, 400))

Oops, I see you answered while I was typing.

1 Like

It works too, thanks my friend!! but your code in two columns. (And the problem was in one column) Anyway !! thanks!! =)

This topic was automatically closed 21 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.