如何阻止prettyR describe()在控制台中打印

huangapple go评论63阅读模式
英文:

How to prevent prettyR describe() from printing in console

问题

I am using the prettyR package's describe function to calculate the mean, standard deviation, median, kurtosis and skewness of a dataset. The code I use is as follows:

library(prettyR)

a <- describe(data, num.desc = c("mean", "sd", "median", "kurtosis", "skewness"))

The dataset in question, however, is very long, so the function proceeds to print the whole list of data in the R console under "description of structure." This takes a long time and makes it hard to read results of previous code in the console due to lots of scrolling required. The output in the console looks as follows:

Description of structure(list(x=c(...)), row.names = c(...), class = "data.frame")

Is there any way to prevent the above output from printing in the console? I just want the 'a' object so I can call it to look at the mean etc. Any help would be much appreciated as the R documentation has been getting me nowhere! Thanks.

英文:

I am using the prettyR package's describe function to calculate the mean, standard deviation, median, kurtosis and skewness of a dataset. The code I use is as follows:

library(prettyR)

a &lt;- describe(data,num.desc=c(&quot;mean&quot;,&quot;sd&quot;,&quot;median&quot;,&quot;kurtosis&quot;,&quot;skewness&quot;))

The dataset in question however is very long so the function proceeds to print the whole list of data in the R console under "description of structure". This takes a long time and makes it hard to read results of previous code in the console due to lots of scrolling required. The output in the console looks as follows:

Description of structure(list(x=c(...)),row.names=c(...),class=&quot;data.frame&quot;)

Is there any way to prevent the above output from printing in the console? I just want the a object so I can call it to look at the mean etc. Any help would be much appreciated as the R documentation has been getting me nowhere!

Thanks.

答案1

得分: 1

Badly implemented cat, should be message, not so pretty. Wouldn't use such packages, also not maintained since 4 years.

However can be silenced with capture.output into something.

nul <- capture.output(des <- prettyR::describe(mtcars))

des

Numeric

mean median var sd valid.n

mpg 20.09 19.20 36.32 6.03 32

cyl 6.19 6.00 3.19 1.79 32

disp 230.72 196.30 15360.80 123.94 32

hp 146.69 123.00 4700.87 68.56 32

drat 3.60 3.70 0.29 0.53 32

wt 3.22 3.33 0.96 0.98 32

qsec 17.85 17.71 3.19 1.79 32

vs 0.44 0.00 0.25 0.50 32

am 0.41 0.00 0.25 0.50 32

gear 3.69 4.00 0.54 0.74 32

carb 2.81 2.00 2.61 1.62 32

Better use psych::describe(mtcars).

英文:

Badly implemented cat, should be message, not so pretty. Wouldn't use such packages, also not maintained since 4 years.

However can be silenced with capture.output into something.

nul &lt;- capture.output(des &lt;- prettyR::describe(mtcars))

des
#  Numeric 
#        mean median      var     sd valid.n
# mpg   20.09  19.20    36.32   6.03      32
# cyl    6.19   6.00     3.19   1.79      32
# disp 230.72 196.30 15360.80 123.94      32
# hp   146.69 123.00  4700.87  68.56      32
# drat   3.60   3.70     0.29   0.53      32
# wt     3.22   3.33     0.96   0.98      32
# qsec  17.85  17.71     3.19   1.79      32
# vs     0.44   0.00     0.25   0.50      32
# am     0.41   0.00     0.25   0.50      32
# gear   3.69   4.00     0.54   0.74      32
# carb   2.81   2.00     2.61   1.62      32

Better use psych::describe(mtcars).

huangapple
  • 本文由 发表于 2023年6月27日 18:58:23
  • 转载请务必保留本文链接:https://go.coder-hub.com/76564171.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定