Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Proper use of the following functions:describeBy, statsBy, and stat.desc

Tags:

r

I am using R 3.2.0 and have been successful using the aggregate function but it gives minimum statistics, tapply gives more than the aggregate function but the summary statistics are limited. For the following data with 4 groups of different n’s can anyone show me how to use following functions properly: describeBy, statsBy, and stat.desc? Following is the data and incorrect syntax for the above functions that I used.

data <- c(62, 60, 63, 59, 63, 67, 71, 64, 65, 66, 68, 66, 71, 67, 68, 68, 56, 62, 60, 61, 63, 64, 63, 59)
grp <- factor(rep(LETTERS[1:4], c(4,6,6,8)))
df <- data.frame(group=grp, dt=data)
describeBy(data, df$dt, df$group, mean,median,min,max,sd)
statsBy(df,mean,median,min,max,sd)
stat.desc(df,basic=F)
like image 474
louieco2 Avatar asked Nov 27 '25 16:11

louieco2


1 Answers

library(DescTools)  # not asked for, but better
Desc(df, plot = T)

library(psych)
describeBy(df, df$group)
# statsBy tries to find correlations, but you have only 1 numerical variable here.

library(doBy)
library(pastecs)
summaryBy(dt ~ group, data = df, FUN = stat.desc)
like image 56
Henk Avatar answered Nov 29 '25 10:11

Henk



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!