Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vector different length after unlist

Tags:

r

I'm trying to convert a list to a vector so I can attach it to a dataframe but it's throwing an error. After unlisting the list, it became shorter and I'm not sure why.

Thanks, any help is greatly appreciated.

> mongo_jr$last_state <- unlist(last_state)
Error in `$<-.data.frame`(`*tmp*`, "last_state", value = c("created",  : 
  replacement has 203819 rows, data has 203823

> str(last_state)
List of 203823

x <- unlist(last_state)

> str(x)
 chr [1:203819] "created" "created" "created" "created" "created" "created" "created" "created" ...
like image 227
Joseph Noirre Avatar asked Mar 21 '17 18:03

Joseph Noirre


1 Answers

It turns out some of the values were null

transition_duration[sapply(last_state, is.null)] <- NA
mongo_jr$last_state <- unlist(last_state)

worked.

like image 115
Joseph Noirre Avatar answered Oct 17 '22 22:10

Joseph Noirre