I have a data frame that contains about a 100 columns called some_text_microorganism_growth. They are characters but really are an ordered factor (NG<SG<LG<MG<HG) with an equivalent numerical value of (0,2.5,6,12,25,40). I can convert these column by column but I need to use: contains("growth") to do it for all the columns. Any thoughts?
Edited data:
df<-data.frame(ABC_growth=rep(c("MG","LG","NG"), each=5), ZFG_growth=rep(c("GG","LG","SG"),each=5),OtherCol=rep(c("AB*","CD;","other+"),each=5)
#Note not all factors appear in each column but they are common across all columns. The full set is: (NG<SG<LG<MG<HG)
For one column I do:
df$ABC_growth<-factor(dfH$ABC_growth) #convert to factor
df$ABC_growth <-ordered(dfH$ABC_growth,levels= c("SG","LG","MG","HG")) # order
levels(df$ABC_growth) <- c("2.5","12","40","100")
What do you think?