I have a data.frame object in the list, I'm going to filter based on the last column (AKA, grade) of each of them accordingly. The subset for the list is intuitive for me, but I want to have two different sets (i.e. pass / fail) as a result of filtering for each data.frame object. I think that the way I used is not elegant, and is looking for a better / effective solution for it. Can someone tell me how to achieve a more elegant solution for this kind of problem? Many thanks!
toy details:
mylist <- list(df1=data.frame( from=seq(1, by=4, len=16), to=seq(3, by=4, len=16), score=sample(30, 16)),
df2=data.frame( from=seq(3, by=7, len=20), to=seq(6, by=7, len=20), score=sample(30, 20)),
df3=data.frame( from=seq(4, by=8, len=25), to=seq(7, by=8, len=25), score=sample(30, 25)))
my initial attempt:
pass <- lapply(mylist, function(ele_) {
ans <- subset(ele_, ele_$score > 20)
ans
})
It turns out that I also want to have my opposite set, where the instances do not satisfy the filter condition, and put pass, fail for each data.frame object in one list.
: data.frame , .
, data.frame ? - ?