0

hello this is a basic question as I am new to R

I have an existing column within my dataframe called "shade" with different shades of pink, i want a new column called "basic colour" which prints PINK if the field contains a shade of pink. Same for shades of blue and green.

How would I do this?

Thanks :)

LB2820
  • 1
  • It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. – MrFlick Nov 04 '22 at 15:09
  • As somebody has already mentioned, it would be better to show what code you have tried so far or what you are looking for as desired output. – Shawn Hemelstrand Nov 16 '22 at 07:02

1 Answers1

0

We may do

df1$basic_color <- ifelse(grepl("pink", df1$shade), "PINK", NA_character_)
akrun
  • 874,273
  • 37
  • 540
  • 662