my question is exactly as follows
library(caret)
data(cars)
head(cars)
colnames(cars)
Expected Answer
cars$type <- names(cars[14:18])[max.col(cars[14:18])]
but using the name of the columns such as below which is not working. how to get around with this? many thanks in advance.
cars$type <- cars[c("convertible", "coupe", "hatchback", "sedan", "wagon" )][apply(cars[c("convertible", "coupe", "hatchback", "sedan", "wagon" )], 1, match, x = 1)]
head(cars)