I have data like these:
ID color_1 color_2 color_3 color_4
1 blue NA NA NA
5 green blue yellow NA
9 None NA NA NA
2 blue pink NA NA
11 green NA NA NA
I want to add a new column that counts the number of colors (None, 1, or 2 or more):
ID color_1 color_2 color_3 color_4 colors
1 blue NA NA NA 1
5 green blue yellow NA 2 or more
9 None NA NA NA None
2 blue pink NA NA 2 or more
11 green NA NA NA 1
I am thinking I can do something like this:
library(tidyverse)
data2 <- data %>%
mutate(colors = case_when(
color_1 == "None" ~ "None",
But I can't figure out how to do the counting part. Any help is appreciated!