I have a dataframe with only one row. How can I find which column contains the same value as another specified column in the same dataframe?
For example, I want to find which flavour is the favorite flavor in this df. The answer should be the column name flavour2 since it coincides with 'Apple':
df <- data.frame(flavour1 = c("Grape"),
flavour2 = c("Apple"),
flavour3 = c("Strawberry"),
favourite = c("Apple"))
Thank you!
colnames(df)[grep(df$favourite, df[1:3])]The output:[1] "flavour2"