[R] sd() for numeric row entries

Phil Spector
2010-12-08T22:36:16Z

Jim -
    Suppose the data frame is named "df".  Then

df$std_dev = apply(df,1,sd,na.rm=TRUE)

will do what you want, although it will generate
some warning messages due to the first column.

df$sd_dev = apply(df[,sapply(df,is.numeric)],1,sd)

does the same, but won't produce warnings.

 					- Phil Spector
 					 Statistical Computing Facility
 					 Department of Statistics
 					 UC Berkeley
 					 spector at stat.berkeley.edu


On Wed, 8 Dec 2010, Jim Moon wrote:

> How might one calculate standard deviation, row-wise, for the numeric
values in a data frame such as this one
>         V1     V2     V3     V4     V5
> 1 rs11089130 0.4565 0.4574 0.4569 0.4572
> 2   rs738829 0.6548 0.6519 0.6448 0.6549
> 3   rs915674 0.7503 0.7500 0.7517 0.7502
>
> and place the standard deviation in a 6th column called ???std_dev????
>
> Regards,
> Jim
>
>
> 	[[alternative HTML version deleted]]