解开列表后,向量长度不同

7
我试图将一个列表转换为向量,以便把它附加到数据框中,但是出现错误。在对列表进行解压缩后,它变得更短了,我不知道原因。感谢您的帮助,非常感谢。
> 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" ...

last_state 中的任何向量是否为空?运行 table(sapply(last_state,length)) 并查看其中是否混杂着长度为 0 的向量。 - Bishops_Guest
1个回答

5
原来有些值是空的。
transition_duration[sapply(last_state, is.null)] <- NA
mongo_jr$last_state <- unlist(last_state)

完成了。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接