Re: [R] calculate sd for each row on some columns of a dataframe

From: Henrique Dallazuanna <wwwhsd_at_gmail.com>
Date: Thu, 28 Feb 2008 08:34:52 -0300

Try this:

lapply(list(letters[1:3], letters[2:4]), function(x)apply(df[,x], 1, sd))

On 28/02/2008, Albert Vilella <avilella_at_gmail.com> wrote:
> Hi,
>
> I've got a dataframe like this:
>
> df = data.frame(a=rnorm(100,1),b=rnorm(100,10),c=rnorm(100,100),d=rnorm(100,-100))
>
> and I want to calculate sd1 for (a,b,c) for each entry, and sd2 for
> (b,c,d) for each entry.
>
> I don't seem to find the answer using aggregate or apply,
>
> How can I do this?
>
> Thanks in advance,
>
> Cheers,
>
> Albert.
>
> ______________________________________________
> 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.
>

-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

______________________________________________
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.
Received on Thu 28 Feb 2008 - 11:37:28 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 28 Feb 2008 - 13:30:18 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive