Home > Back-end >  Filter list with multiple objects with a column condition in r
Filter list with multiple objects with a column condition in r

Time:12-11

I have a large list with 13 elements and each element has 181 rows and 31 columns. I am trying to filter each element based on one specific column. For example, I want to filter the elements' rows based on the column named X with the following condition X<=0.30. If it was a data frame, for instance, I would do "filter(X<=0.30)".

Here are some of the codes I tried where "out" is my data frame and "X" is the variable with the condition (X<=0.30):

out_new<-(list.filter(out,X<=0.30))

out_new<-out[sapply(out, X)<=0.30]

However these codes return a list of 0. I am not sure what I am doing wrong or missing. So any help is very much appreciated. Thank you.

CodePudding user response:

I am presuming u have a list of data-frame and you want to filter each df based on one specific column.

my_function<-function(df){
  df<-df %>% filter(X<=0.30)
}

map(list_name,my_function)
  • Related