a<-rep(1,10)
a[10] <- 1.1 # avoid 0 sd
b<-rep(0,10)
b[10] <- 0.1
c<-c(1,0,1,0,1,0,1,0,1,0)
d<-c(0,1,0,1,0,1,0,1,0,1)
dat<-data.frame(a,b,c,d)
> dat
a b c d
1 1.0 0.0 1 0
2 1.0 0.0 0 1
3 1.0 0.0 1 0
4 1.0 0.0 0 1
5 1.0 0.0 1 0
6 1.0 0.0 0 1
7 1.0 0.0 1 0
8 1.0 0.0 0 1
9 1.0 0.0 1 0
10 1.1 0.1 0 1
> cor(dat)
a b c d
a 1.0000000 1.0000000 -0.3333333 0.3333333
b 1.0000000 1.0000000 -0.3333333 0.3333333
c -0.3333333 -0.3333333 1.0000000 -1.0000000
d 0.3333333 0.3333333 -1.0000000 1.0000000
> apply(t(dat), 1, sd)
a b c d
0.03162278 0.03162278 0.52704628 0.52704628
No comments:
Post a Comment