I have a data frame which looks like this:
codes <- c('TFAA1', 'TFAA2', 'TFAA3', 'TFAA4', 'TFAB1', 'TFAB2', 'TFAB3', 'TFAB4')
scores <- c(4,3,2,2,4,5,1,2)
example <- data.frame(codes, scores)
I want to create a new column called code_group whereby everything that starts with TFAA gets called "Group1" and everything that starts with TFAB gets called "Group2".
Have been playing with the recode function from the car package, and the grepl function but I'm failing miserably. Here's my attempt so far....
recode <- (codes, "%in% TFAA='Group1'; %in% TFAB='Group2'")