louieco2
louieco2

Reputation: 31

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

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)

Upvotes: 3

Views: 1605

Answers (1)

Henk
Henk

Reputation: 3656

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)

Upvotes: 1

Related Questions