Search code examples
rlistrbind

Keeping only data.frames in list of list


My list looks something like that and I would like to remove those type=character so that I can use rbindlist.

enter image description here

I tried the following, but is_df became empty 'List of 0'.

is_df <- sapply(lst2, is.data.frame)

finaldf <- do.call("rbind.fill", lst2[is_df])

Solution

  • We can use keep with bind_rows

    library(purrr)
    library(dplyr)
    keep(lst2, is.data.frame) %>% 
          bind_rows