Hi,
I am wondering how I might set about comparing characters/words and creating new results depending on the values.
My test example, which doesn't work, is as follows:
library(tidyverse)
#Create a new variable
number <- c("one","two","three","four","five")
chr_columns <- tibble(number)
# A tibble: 5 × 2
number total
<chr> <chr>
1 one
2 two
3 three #Five
4 four
5 five
My non functioning code is below.
chr_columns <- chr_columns %>%
mutate(total = case_when(
number="three" & number="two" %in% number ~ "Five"
))
head(chr_columns)
I have searched high and low, and I'm stuck, though I can only imagine there's a far more effective way to approach this problem? FWIW I only plan on using 'And' comparisons. I could convert the words to numbers, but this feels like more of a challenge.
Any advise much appreciated!