用一個空的dataframe-cbine.fill綁定一個dataframe?我想我在找一個模擬的rbind.fill(在Hadley‘splyr(包裝)cbind..我看過了,但沒有cbind.fill.我想做的是:#set these just for this exampleone_option <- TRUEdiff_option <- TRUEreturn_df <- data.frame()if (one_option) {
#do a bunch of calculations, produce a data.frame, for simplicity the following small_df
small_df <- data.frame(a=1, b=2)
return_df <- cbind(return_df,small_df)}if (diff_option) {
#do a bunch of calculations, produce a data.frame, for simplicity the following small2_df
small2_df <- data.frame(l="hi there", m=44)
return_df <- cbind(return_df,small2_df)}return_df可以理解,這會產生一個錯誤:Error in data.frame(..., check.names = FALSE) : arguments imply differing number of rows: 0, 1我現在的修復方法是替換線路return_df <- data.frame()帶著return_df <- data.frame(dummy=1)然后代碼就能工作了。然后,我只需從return_df最后。在添加虛擬代碼并運行上述代碼之后,我得到 dummy a b l m1 1 1 2 hi there 44然后我只需要處理掉假人,例如:> return_df[,2:ncol(return_df)]
a b l m1 1 2 hi there 44我肯定我錯過了一個更簡單的方法來做這件事。編輯:我想我不是在找Cbinn,因為這意味著安娜的值將在cbind之后創建,這不是我想要的。
用一個空的dataframe-cbine.fill綁定一個dataframe?
慕尼黑8549860
2019-07-16 10:13:23