Re: [R] how to automatically select certain columns using for loop in dataframe

2009-04-09 Thread milton ruser
In fact you can use only for (each_name in col_names) { sub.data <- subset( all.data, select = c( paste("NUM_", each_name, sep = '') , paste("NAME_", each_name, sep = '') ) ) sub.data.2<-subset(sub.data, !is.na(sub.data[,2])) p

Re: [R] how to automatically select certain columns using for loop in dataframe

2009-04-09 Thread milton ruser
Hi Ferry, It is not so elegant, but you can try for (each_name in col_names) { sub.data <- subset( all.data, !is.na( paste("NAME_", each_name, sep = '') ), select = c( paste("NUM_", each_name, sep = '') , paste("NAME_", each_name, sep

[R] how to automatically select certain columns using for loop in dataframe

2009-04-09 Thread Ferry
Hi, I am trying to display / print certain columns in my data frame that share certain condition (for example, part of the column name). I am using for loop, as follow: # below is the sample data structure all.data <- data.frame( NUM_A = 1:5, NAME_A = c("Andy", "Andrew", "Angus", "Alex", "Argo"),