我想我正在寻找rbind.fill(在Hadley的plyr包装中)的类比cbind.我看了,但没有cbind.fill.
我想做的是以下内容:
#set these just for this example
one_option <- TRUE
diff_option <- TRUE
return_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
Run Code Online (Sandbox Code Playgroud)
可以理解,这会产生错误:
Error in data.frame(..., check.names …Run Code Online (Sandbox Code Playgroud)