Skip to content

sd() for numeric row entries

3 messages · Jim Moon, Phil Spector

#
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:

            
#
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: