I'm trying to update Sam's role in the tibble below from PM to TC. For some reason, I have no idea how to get this to work, even though it seems simple. Here is my data frame.
df <- tibble(
Name = c("Sam","Jane","Sam","Sam","James","Mary","Swain"),
Role = c("PM","TC","PM","PM","RX","TC","TC"),
Number = c(1:7)
)
Then I have this if_else statement which is supposed to conditionally update Role to "TC" when Name = "Sam." But all it's doing is changing all the row values to TC regardless of name. I don't know why or how to fix it.
df$Role <- if_else(df$Name == "Sam", df$Role <- "TC", df$Role)