Short question:
I can substitute certain variable values like this:
values <- c(\"a\", \"b\", \"a\", \"b\", \"c\", \"a\", \"b\")
df <- data.frame(v
What about:
df[!df[, 1] %in% c("a", "b"), ] <- "x"
values
1 a
2 b
3 a
4 b
5 x
6 a
7 b
Your example is a bit unclear and not reproducible. However, based on guessing what you actually want, I could suggest trying this option using the data.table package:
df[values %in% c("a", "b"), values := "x"]
or the dplyr package:
df %>% mutate(values = ifelse(values %in% c("a","b"), x, values))