Hon*_*Ooi 18
write.csv只需write.table用适当的参数调用引擎盖.所以你可以通过3次调用实现你想要的write.table.
write.table(df1, "filename.csv", col.names=TRUE, sep=",")
write.table(df2, "filename.csv", col.names=FALSE, sep=",", append=TRUE)
write.table(df3, "filename.csv", col.names=FALSE, sep=",", append=TRUE)
Run Code Online (Sandbox Code Playgroud)
实际上,你可以通过将数据帧与rbind组合成一个df,然后调用write.csv一次来避免整个问题.
write.csv(rbind(df1, d32, df3), "filename.csv")
Run Code Online (Sandbox Code Playgroud)
Dee*_*ena 11
我们使用sink文件:
# Sample dataframes:
df1 = iris[1:5, ]
df2 = iris[20:30, ]
# Start a sink file with a CSV extension
sink('multiple_df_export.csv')
# Write the first dataframe, with a title and final line separator
cat('This is the first dataframe')
write.csv(df1)
cat('____________________________')
cat('\n')
cat('\n')
# Write the 2nd dataframe to the same sink
cat('This is the second dataframe')
write.csv(df2)
cat('____________________________')
# Close the sink
sink()
Run Code Online (Sandbox Code Playgroud)