[R] dynamic aggregation of many variables

Petr Pikal petr.pikal at precheza.cz
Mon Nov 20 17:59:59 CET 2006


Hi
 as I did not see any response I try to write one.

Your code does not work for me, it gives me an error.

> week1 <- grep("(_PRO_001)",names(dmx3),perl=T)
Error in names(dmx3) : object "dmx3" not found

Seems that I do not have dmx3 available.

However if you want to do some computation based on a common value 
you shall consult

aggregate, tapply, by or doBy package

and provide some simple example which everybody can reproduce.
Even sending us 

str(dmx3) could result in better understanding of your problem and 
maybe some more concise answer. Maybe also reshaping your data could 
lead to some better aggregation possibilities.

HTH
Petr




On 15 Nov 2006 at 12:43, Christian Schulz wrote:

Date sent:      	Wed, 15 Nov 2006 12:43:01 +0100
From:           	Christian Schulz <ozric at web.de>
To:             	"'r-help at stat.math.ethz.ch'" <r-help at stat.math.ethz.ch>
Subject:        	[R] dynamic aggregation  of many variables

> Hi,
> 
> i have many variables for in example 4weeks and want to do
> aggregations, like mean standard , deviation etc..
> 
> With mean it works but how i can  calculate the standard deviation for
> the 4weeks and for every  ID.
> 
> many thanks & regards, christian
> 
> week1 <- grep("(_PRO_001)",names(dmx3),perl=T)
> week1table <- subset(dmx3,select=c(ID,week1))
> 
> week2 <- grep("(_PRO_002)",names(dmx3),perl=T)
> week2table <- subset(dmx3,select=c(ID,week2))
> 
> week3 <- grep("(_PRO_003)",names(dmx3),perl=T)
> week3table <- subset(dmx3,select=c(ID,week3))
> 
> week4 <- grep("(_PRO_004)",names(dmx3),perl=T)
> week4table <- subset(dmx3,select=c(ID,week4))
> mws <- 
> (week1table[,2:117]+week2table[,2:117]+week3table[,2:117]+week4table[,
> 2:117])/4
> 
> ______________________________________________
> R-help at stat.math.ethz.ch 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.

Petr Pikal
petr.pikal at precheza.cz



More information about the R-help mailing list