I am using library(data.table)
and I would like to do a for
loop that calculates the mean
of columns 1:4
, based on col5
values.
colnames(DT) # "col1" "col2" "col3" "col4" "col5"
for (i in 1:4){
o=colnames(DT)[[i]]
l=DT[,mean(o), by=col5]
print(l)
}
The problem is that DT
does not take colnames
as character
vectors ("col"). Any advice is appreciated.