id first middle last Age
1 Carol Jenny Smith 15
2 Sarah Carol Roberts 20
3 Josh David Richardson 22
I am t
Another option using mutate
and if_else()
as you suggested:
library(tidyverse)
data = read_table(" id first middle last Age
1 Carol Jenny Smith 15
2 Sarah Carol Roberts 20
3 Josh David Richardson 22")
data %>%
mutate(carol = if_else(first == "Carol" | middle == "Carol" | last == "Carol",
"yes",
"no"))
Result:
# A tibble: 3 x 6
id first middle last Age carol
1 1 Carol Jenny Smith 15 yes
2 2 Sarah Carol Roberts 20 yes
3 3 Josh David Richardson 22 no