I'm having an issue with dplyr::filter
I have a list of dataframes, such as :
df<- data.frame(a =1:3, b = 3:1, level= letters[1:3])
df2 <- data.frame(a =1:6, b = 21:26, level= letters[1:3])
listofdf <- list(df,df2)
I'm trying to create a function to select specific rows in my dataframe, this means that the argument I put in as the column name is necessarily a string.
Function looks something like this, it is meant to be used on a list of dataframes :
selectOTUlevel <- function(OTU,DATA,column){
for (i in 1:length(DATA)){
DATA <- DATA %>% filter(column == OTU)
}
return(DATA)
}
I've tried creating the same function another way :
selectOTU <- function(OTU,DATA,column){
for (i in 1:length(DATA)){
DATA[[i]] <- DATA[[i]][DATA[[i]]$column == OTU,]
}
return(DATA)
}
But I can't seem to solve this issue. I've tried this solution (https://www.r-bloggers.com/2020/09/using-dplyrfilter-when-the-condition-is-a-string/) but it doesn't work either.
Maybe if someone could enlighten me about what I'm doing wrong, I would be delighted !