Skip to content
Back to formatted view

Raw Message

Message-ID: <4B4E455A.3070307@gmx.de>
Date: 2010-01-13T22:12:42Z
From: Stephan Kolassa
Subject: Operating on each row of data frame
In-Reply-To: <be9b52411001131314r52839830q3cfbbd08906911bb@mail.gmail.com>

Hi,

does this do what you want?

d <- cbind(d,apply(d[,c(2,3,4)],1,mean),apply(d[,c(2,3,4)],1,sd))

HTH,
Stephan


Abhishek Pratap schrieb:
> Hi All
> 
> I have a data frame in which there are 4 columns .
> 
> Column 1 : name
> 
> Column 2-4 : values
> 
> I would like to calculate mean/Standard error  of values in column 2-4 and
> store them in column 5,6 respectively.
> 
> 
> 
> I have done the following but doesn't seem to work
> 
> mean_N_SE <-function(x)
> {
> 
> name <- x[1]
> vals <- c(x[2:4])
> temp_mean <- mean(vals)
> SE <-  sqrt(var(x)/length(x))
> 
> }
> 
> apply(d,1,mean_N_SE) where d = data frame.
> 
> 
> Can someone help me with this.
> 
> Thanks!
> -Abhi
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> 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.
>