2017-03-21 68 views
1

我試圖將列表轉換爲矢量,以便我可以將它附加到數據框但它引發錯誤。列入清單後,它變得更短,我不知道爲什麼。未登記後矢量不同長度

謝謝,任何幫助,非常感謝。

> 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" ... 
+0

「last_state」中的矢量是否爲空?運行'table(sapply(last_state,length))'並查看是否有任何0長度的向量混合在那裏。 –

回答

2

原來一些值都爲空的

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

工作。