-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMeanSD
39 lines (38 loc) · 981 Bytes
/
MeanSD
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
MeanSD<-function(x,roundDig=2,drop0=F,groupvar=NULL,
range=F,rangesep='ARRR')
{
out<-''
# if(is.na(roundDig))
# {
# out<-paste(roundR(mean(x,na.rm=T)),
# roundR(sd(x,na.rm=T)),
# sep='\u00B1')
# } else
# {
if(is.null(groupvar))
{
meansd<-roundR(
matrix(c(mean(x,na.rm=T),
sd(x,na.rm=T),
min(x,na.rm=T),
max(x,na.rm=T)),
ncol=4,byrow=F),level=roundDig,
drop0=drop0)
} else
{
meansd<-roundR(
matrix(c(by(x,groupvar,mean,na.rm=T),
by(x,groupvar,sd,na.rm=T),
by(x,groupvar,min,na.rm=T),
by(x,groupvar,max,na.rm=T)),
ncol=4,byrow=F),level=roundDig,
drop0=drop0)
}
out<-paste(meansd[,1],meansd[,2],sep='\u00B1')
if(range)
{
out<-paste0(out,rangesep, ' [',apply(matrix(meansd[,3:4],ncol=2),1,paste,collapse=' -> '),']') #\u22ef
}
# }
return(out)
}