可能有更好的方法可以做到这一点,但这似乎可行而且很简单。(我的代码有四行,以便更容易查看步骤;这四行可以轻松组合。)
# first re-create your data frame:
A = matrix( ceiling(10*runif(8)), nrow=4)
colnames(A) = c("country", "year_var")
dfa = data.frame(A)
# now re-create the list you made from the individual rows of the data frame:
df1 = dfa[1,]
df2 = dfa[2,]
df3 = dfa[3,]
df4 = dfa[4,]
df_all = list(df1, df2, df3, df4)
# to recreate your original data frame:
x = unlist(df_all) # from your list create a single 1D array
A = matrix(x, nrow=4) # dimension that array in accord w/ your original data frame
colnames(A) = c("country", "year_var") # put the column names back on
dfa = data.frame(A) # from the matrix, create your original data frame