Extract dataframes from lists with dataframes under certain criteria in R

5

I've organized my list of dataframes like this:

df.1<-as.data.frame(matrix(rnorm(10),10,80))
df.1.in.list<-split.default(df.1, gl(10, 8))

In the df.1.in.list list I would like to keep the dataframes where the first element of column 8 is 2 or -2. Keeping the list character for df.1.in.list

In other words, remove dataframes that do not fall under this criterion.

Well, there are probably no such cases in this example that I generated. But my original dataframe has such cases. I would really like the idea to promote this selection.

How do I do this?

    
asked by anonymous 25.09.2018 / 23:43

1 answer

5

You can use the keep function of purrr :

library(purrr)

df.1.in.list %>%
  keep(~.x[1,8] %in% c(-2, 2))
    
26.09.2018 / 00:06