[R] test

ONKELINX, Thierry Thierry.ONKELINX at inbo.be
Fri Jan 14 15:13:10 CET 2011


Here is a more elegant solution using the plyr package.

my.data <- expand.grid(Thesis = 1:3, Day = c(0, 14), Run = 1:10)
my.data$A <- rpois(nrow(my.data), 10)
my.data$B <- rpois(nrow(my.data), 10)
my.data$C <- rpois(nrow(my.data), 10)

library(plyr)
ddply(my.data, .(Thesis, Day), function(x){
	Baseline <- unlist(x[1, c("A", "B", "C")])
	data.frame(t(apply(x[-1, c("A", "B", "C")], 1, function(z){z - Baseline})))
})

Best regards,

Thierry

----------------------------------------------------------------------------
ir. Thierry Onkelinx
Instituut voor natuur- en bosonderzoek
team Biometrie & Kwaliteitszorg
Gaverstraat 4
9500 Geraardsbergen
Belgium

Research Institute for Nature and Forest
team Biometrics & Quality Assurance
Gaverstraat 4
9500 Geraardsbergen
Belgium

tel. + 32 54/436 185
Thierry.Onkelinx op inbo.be
www.inbo.be

To call in the statistician after the experiment is done may be no more than asking him to perform a post-mortem examination: he may be able to say what the experiment died of.
~ Sir Ronald Aylmer Fisher

The plural of anecdote is not data.
~ Roger Brinner

The combination of some data and an aching desire for an answer does not ensure that a reasonable answer can be extracted from a given body of data.
~ John Tukey
  

> -----Oorspronkelijk bericht-----
> Van: r-help-bounces op r-project.org 
> [mailto:r-help-bounces op r-project.org] Namens K. Elo
> Verzonden: vrijdag 14 januari 2011 14:52
> Aan: r-help op r-project.org
> Onderwerp: Re: [R] test
> 
> Dear Romezo,
> 
> a solution maybe not that elegant and effective, but seems to work:
> 
> test_calculate<-function() {
>    tarrow<-1
>    TARGET<-data.frame("Thesis"=0, "Day"=0,"A"=0,"B"=0,"C"=0)
>    for (i in c(unique(my.data$Thesis))) {
>      for (j in c(unique(my.data$Day[ my.data$Thesis==i ]))) {
>        TEMPDF<-subset(my.data, Thesis==i & Day==j)
>        for (k in c(1:(nrow(TEMPDF)-1))) {
>          for (l in c((k+1):nrow(TEMPDF))) {
>            TARGET[tarrow,]<-cbind(i,j,(TEMPDF[k,3]-TEMPDF[l,3]),
> (TEMPDF[k,4]-TEMPDF[l,4]), (TEMPDF[k,5]-TEMPDF[l,5]))
>            tarrow<-tarrow+1
>          }
>        }
>      }
>    }
>    print(TARGET)
> }
> 
> (Please note: my.data is your original data frame)
> 
> Kind regards,
> Kimmo
> 
> ______________________________________________
> R-help op 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.
> 


More information about the R-help mailing list