当前位置: 动力学知识库 > 问答 > 编程问答 >

Write multiple R-summaries to a single excel file

问题描述:

How can I write several summaries to an Excel file, to have:

  1. In the first column (Min, 1st Qu, Median, Mean, 3rd Qu, Max), and in the subsequent columns only the numerical values.
  2. On the top row I need the name of the variables that I am summarizing.

网友答案:

i guess it would be something like

df<-data.frame("a"=rnorm(10), "b"=rnorm(10), "c"=rnorm(10))
output<-apply(X=df, MARGIN=2,FUN=summary)
write.table(output, file="output.csv", dec=",", sep=";")

depending on your excel version, the 'dec' and 'sep' parameters for export might vary.

网友答案:

You could create a data.frame with row names "Min", "1st Qu", etc. und column names of your variables and then call the usual export functions such as write.csv in base R, WriteXLS in the WriteXLS package or write.xlsx in the xlsx package. Be sure to use the row.names=TRUE argument.

分享给朋友:
您可能感兴趣的文章:
随机阅读: