I am trying to write code that takes values from one column of each of many files and prints out a list of the values of a different column depending on the values found in the first. If that makes sense. I have read the files in, but I am having trouble managing the table. I would like to limit the table to just those two columns, because the files are very large, cumbersome and unnecessary. In my attempt to do so I had this line:
tmp<-stack(lapply(inputFiles,function(x) x[,3]))
But ideally I would like to include two columns (3 and 1), not just one, so that I may use a line, such as these ones:
search<-tmp[tmp$values < 100, "Target"]
write(search, file = "Five", ncolumns = 2)
But I am not sure how. I am almost certain that stack is not going to work for more than one column. I tried some different things, similar to this:
tmp<-stack(lapply(inputFiles,function(x) x[,3], x[,1]))
But of course that didn’t work.
But I don’t know where to look. Does anyone have any suggestions?
The taRifx package has a list method for
stackthat will do what you want. It stacks lists of data.frames.Untested code:
But you didn’t change anything! Why does this work?
lapply()returns a list. In your case, it returns a list where each element is a data.frame.Base R does not have a special method for stacking lists. So when you call
stack()on your list of data.frames, it callsstack.default, which doesn’t work.Loading the taRifx library loads a method of
stackthat deals specifically with lists of data.frames. So everything works fine sincestack()now knows how to properly handle a list of data.frames.Tested example: