简体   繁体   English

如何在R中编写摘要功能?

[英]How do I write a summarize function in R?

I am trying to write a summarizing print function in R to with the outputs below. 我试图用下面的输出在R中编写汇总打印功能。 I'm not sure how to get it to print with a new line for each output. 我不确定如何使每个输出用新行打印。 My code so far is below as well. 到目前为止,我的代码也在下面。 Any help would be appreciated. 任何帮助,将不胜感激。 Outputs: Mean Median Min Max Standard deviation Quantiles (at 0.05 and 0.95) Skewness 输出:平均中位数最小最大标准偏差分位数(在0.05和0.95时)偏斜度

Here is my code so far 到目前为止,这是我的代码

    printInfo <- function(myVector)
{
 print( 
  mean(myVector)
  median(myVector)
  min(myVector)
  max(myVector)
  sd(myVector)
  quantile(myVector, probs = c(0.05, 0.95))
  library(moments)
  skewness(myVector))
}
library(moments)

printInfo <- function(myVector)
{
  cat( 
    "mean: ", mean(myVector), "\n",
    "median: ", median(myVector), "\n",
    "min: ", min(myVector), "\n",
    "max: ", max(myVector), "\n",
    "sd: ", sd(myVector), "\n",
    "quantile: ", quantile(myVector, probs = c(0.05, 0.95)), "\n",
    "skewness: ", skewness(myVector), "\n")
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM