[R] mean and sd for a Dataframe

David Winsemius dwinsemius at comcast.net
Thu Feb 10 07:47:14 CET 2011


On Feb 10, 2011, at 12:24 AM, Ramya wrote:

>
> hi there,
> I need to subtract each value in the dataframe from the mean of the  
> column
> and divide by the
> standard deviation of the column.
>
>
>> dim(a)
> [1] 22011    52
>
> data2 <- sapply(seq(from = 2, by = 1, length = 50), function(e){
> rbind((a[[e]] - mean(a[,e]))/sd(a[,e]))
> })
>
> Does this look right????

It looks like the "hard way" ( and it's not clear why one would need  
rbind, either):

?scale

scale(a)


>
> Any help would be appreciated.
>
> Thanks
> RT
>
>
> -- 
> View this message in context: http://r.789695.n4.nabble.com/mean-and-sd-for-a-Dataframe-tp3298594p3298594.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list