I want to compute the rowMeans of several columns that are identified through the header of a_9_1, a_9_2, a_9_3 up to a a_9_16. The code that I am using is

df$em<-rowMeans(df[,c(paste("a_9",seq(1,16,1, sep="_"))], na.rm=T)

but it gives me the following error message:

Error in `[.data.table`(df, , c("a_9", seq(1, 16, 1, sep = "_"))) : 
  column(s) not found: a_9, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16
In addition: Warning message:
In seq.default(1, 16, 1, sep = "_") :
 extra argument ‘sep’ will be disregarded 

I would appreciate any help.

0 Answers