Copy and paste the following code into R to create your own summary statistics command, called “sumstats”.
You might have to hit enter after you paste to get back to a “>” prompt. It will only work on QUANTITATIVE (NUMERIC) variables.
To use: sumstats(datasetname)
Or to use only specific variables,
sumstats(datasetname[c(1,4,6,7)]) will use the 1st, 4th, 6th, and 7th variables.
sumstats= function(y){
sumst=sapply(y, function(x){ sumstat=c(mean(x,na.rm=TRUE),median(x,na.rm=TRUE), sd(x,na.rm=TRUE),min(x,na.rm=TRUE),max(x,na.rm=TRUE))
names(sumstat)=c("Mean","Median","SD","Min","Max")
sumstat})
aperm(sumst)
}