i'm preparing data pca, need standardize it. i've been following else's code in vegan not getting mean of 0 , sd of 1, should be.
i'm using data set called musci has 13 variables, 3 of labels identify data.
log.musci<-log(musci[,4:13],10) stand.musci<-decostand(log.musci,method="standardize",margin=2) when check mean=0 , sd=1...
colmeans(stand.musci) sapply(stand.musci,sd) i mean values ranging -8.9 3.8 , sd values listed na (for every data point in data set rather each variable). if leave out last variable in standardization, i.e.
log.musci<-log(musci[,4:12],10) the means don't change, sds have value of 1.
any ideas of i've gone wrong?
cheers!
you data matrix.
## sample data dat <- as.matrix(data.frame(a=rnorm(100, 10, 4), b=rexp(100, 0.4))) so, either convert data.frame , use sapply operate on columns
dat <- data.frame(dat) scaled <- sapply(dat, scale) colmeans(scaled) # b # -2.307095e-16 2.164935e-17 apply(scaled, 2, sd) # b # 1 1 or use apply columnwise operations
scaled <- apply(dat, 2, scale)
Comments
Post a Comment