Suppose I have this data frame:
df <- data.frame(a=c(1,2))
df$b <- list(NULL, NULL)
Note that sum(is.null(df$b)
is 0
because b
is a list, not a vector.
How do I get it to be a vector? Some things I tried that didn't work:
# does nothing
df <- df %>% flatten(b)
# removes column b!
df <- df %>% mutate(b=unlist(b))
# destroys df
df <- df %>% unnest(cols=c(b))
# doesn't run
df <- df %>% mutate_at(vars=c('b'), funs(unlist))
There are already several questions that ask this, but their solutions did not work for me.
I am trying to get through data from jsonlite
, similar data to this question.