I have a number of dataframes (imported from CSV) that have the same structure. I would like to loop through all these dataframes and keep only two of these columns.
The loop below does not seem to work, any ideas why? Would ideally like to do this using a loop as I am trying to get better at using these.
frames <- ls()
for (frame in frames){
frame <- subset(frame, select = c("Col_A","Col_B"))
}
Cheers in advance for any advice.
list, notls; 2) you need to supply the indices to frame, as inframes[[frame]] <- subset(...); 3) "frame in frames" doesn't make sense since you just created a null list withframes <- list()-- it should be likefor (frame in 1:5)ls, which I would not recommendcolClassesto only read the columns you want. Details here.rm(list = ls())followed byframes <- lapply(files, read.table), wherefilesis a vector of file names