Five latest papers from my personal top journal Sept. 2010: Multivariate Behavioral Research

Samstag, 4. September 2010

Centering

Since there was a small discussion about centering commands in different statistical packages:

I do not know, whether this is the simples solution in R, but here is the shortest solution I came up with (without thinking about that too deeply):

#create a data matrix (not part of the process -- usually you have that already...)
a<-c(1,2,3,4,5)
b<-c(6,7,8,9,10)
test<-data.frame(cbind(a,b))

#Calculate mean of column a and place it as a new variable in the data frame:
test$meana<-mean(test$a)

#Or, if this is really about centering:
test$meana<-(test$a-mean(test$a))

The solution can spare some letters by attaching "test", but mostly I think, that's it.