用一个空的dataframe-cbine.fill绑定一个dataframe?
rbind.fill
plyr
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
慕沐林林
江户川乱折腾