用一個(gè)空的dataframe-cbine.fill綁定一個(gè)dataframe?我想我在找一個(gè)模擬的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可以理解,這會(huì)產(chǎn)生一個(gè)錯(cuò)誤:Error in data.frame(..., check.names = FALSE) : arguments imply differing number of rows: 0, 1我現(xiàn)在的修復(fù)方法是替換線路return_df <- data.frame()帶著return_df <- data.frame(dummy=1)然后代碼就能工作了。然后,我只需從return_df最后。在添加虛擬代碼并運(yùn)行上述代碼之后,我得到 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我肯定我錯(cuò)過了一個(gè)更簡單的方法來做這件事。編輯:我想我不是在找Cbinn,因?yàn)檫@意味著安娜的值將在cbind之后創(chuàng)建,這不是我想要的。
用一個(gè)空的dataframe-cbine.fill綁定一個(gè)dataframe?
慕尼黑8549860
2019-07-16 10:13:23