Skip to content
Back to formatted view

Raw Message

Message-ID: <F6E79BFD88B88B46A6B4C26B49D65B680364B1ADB2@EX-MB06.ohsu.edu>
Date: 2010-12-08T22:55:18Z
From: Jim Moon
Subject: sd() for numeric row entries
In-Reply-To: <alpine.DEB.2.00.1012081434320.26761@springer.Berkeley.EDU>

This is very helpful, Phil.  Being new to R and trying to get a handle on *apply, by, aggregate...  this is great.  Thank you.



Jim


-----Original Message-----
From: Phil Spector [mailto:spector at stat.berkeley.edu] 
Sent: Wednesday, December 08, 2010 2:36 PM
To: Jim Moon
Cc: r-help at r-project.org
Subject: Re: [R] sd() for numeric row entries

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]]