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

时间:2018-11-04 21:54:56

标签: r function

我试图用下面的输出在R中编写摘要打印功能。我不确定如何使每个输出用新行打印。到目前为止,我的代码也在下面。任何帮助,将不胜感激。 输出: 意思 中位数 敏 最高 标准偏差 分位数(分别为0.05和0.95) 偏度

到目前为止,这是我的代码

    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))
}

1 个答案:

答案 0 :(得分:0)

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")
}