r - loop over colums with semi like columnnames -


i have following variable , dataframe

welltypes <- c("lc","hc") qccast <- data.frame(   lc_mean=1:10,   hc_mean=10:1,   bc_mean=rep(0,10) ) 

now want see welltypes selected(in case lc , hc, different ones.)

for(i in 1:length(welltypes)){ qccast$welltypes[i]_mean } 

this not work, know. how loop on columns?

and has happen variable wise, because welltypes of unkown size.

the second argument $ needs column name of first argument. haven't run code, expect welltypes[i]_mean syntax error. $ similar [[, can use paste create column name string , subset via [[.

for example:

qccast[[paste(welltypes[i],"_mean",sep="")]] 

depending on rest of code, may able instead.

for(i in paste(welltypes,"_mean",sep="")){   qccast[[i]] } 

Comments

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -