I have a dataframe, say:
df <- tibble(question = 1:3, a = c('chicken', 'apple', 'beer'), b = c('chicken', 'banana', 'beer'), c = c('beef', 'apple', 'wine'))
question a b c
> <int> <chr> <chr> <chr>
1 1 chicken chicken beef
2 2 apple banana apple
3 3 beer beer wine
And I would like to replace the the values in row 2 with some mapping:
apple -> 1
banana -> 2
So that the resulting output is:
question a b c
> <int> <chr> <chr> <chr>
1 1 chicken chicken beef
2 2 1 2 1
3 3 beer beer wine
I've looked at case_match, but it appears to want a vector and my data is rows rather than columns. I think I can use across() to just get this to apply to all columns in a particular row, but not sure how to fit these pieces together.
EDIT: I'm not interested in replacing the value at a specific index of column and row. I'm interested in recoding all the values in a row by a particular mapping.