3

Currently "complete.cases" or "na.omit" does not work if some columns of the data frame have list elements.

Error output: Error in FUN(X[[i]], ...) : invalid subscript type 'list'

Psidom
  • 209,562
  • 33
  • 339
  • 356
sharp
  • 61
  • 8
  • 1
    Why are there lists in your data.frame? That seems like a bad idea. It will surely break many things. You should at least provide a [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) so we know what your data looks like. What counts as missing in columns that have lists? – MrFlick May 17 '16 at 22:56
  • @MrFlick I tend to agree, but list inside data frames has [at least one influential advocate](https://blog.rstudio.org/author/hadleywickham/) (just find `purrr` on that page for examples). – Gregor Thomas May 17 '16 at 22:59
  • Well then I guess we have to wait till Hadley releases the `complete_cases` package – MrFlick May 17 '16 at 23:00
  • 2
    `list` objects in `data.frames` are unusual, but perfectly valid structures. It is an interesting question imo, as dealing with something like `dat <- data.frame(a=c(NA,2,3), b=I(list(1:2, NA, 3:4)))` is not straightforward. – thelatemail May 17 '16 at 23:00
  • @thelatemail - thank you for the reproducible example. I have a similar problem. unable to use complete.cases(dat) – sharp May 17 '16 at 23:06
  • 2
    Which begs the question of OP: do you want to check the lists for missing values at the top level (or deeper?) or are you content just checking the non-list columns? – Gregor Thomas May 17 '16 at 23:06
  • @Gregor - good point - `dat <- data.frame(a=c(NA,2,3), b=I(list(1:2, c(1,NA), 3:4)))` might be an example of a more complex data.frame. – thelatemail May 17 '16 at 23:07
  • 1
    Also, OP, if `na.omit` isn't working for you you may need your own reproducible example: `na.omit(dat)` works just fine using thelatemail's `dat` (by ignoring the list column). A look at `stats:::na.omit.data.frame` show that it passes non-atomic columns: `if (!is.atomic(x)); next`. – Gregor Thomas May 17 '16 at 23:08
  • Yes, na.omit works for me but not complete.cases! I dont have any NAs inside the list, so that is not a problem. thanks for your help! – sharp May 17 '16 at 23:23
  • In that case please edit your question where you state "*...`na.omit` does not work*". – Gregor Thomas May 18 '16 at 05:44
  • na.omit still does not remove NA's when inside the list... so the question holds if NA's are inside the list. so i guess the questions holds in general – sharp May 19 '16 at 06:50

0 Answers0