Re: [R] more on vector vs array

From: Adaikalavan Ramasamy <ramasamy_at_cancer.org.uk>
Date: Tue 09 Aug 2005 - 20:05:28 EST

Nice one. But I think you could replace the last line (the one with do.call) with the simpler

 w <- which( dat[ ,2] > dat[ ,3] )
 w
 [1] 6 11 13 14 16 18 20

 dat[ w, ]

    station temp.x temp.y

 6        b     18     16
 11       c     17     15
 13       d     16     14
 14       d     17     14
 16       d     17     14
 18       e     16     15
 20       e     19     15

Thank you.

Regards, Adai

On Tue, 2005-08-09 at 10:19 +0200, Dimitris Rizopoulos wrote:
> you could use something like this:
>
> dat1 <- data.frame(station = rep(letters[1:5], 4), temp =
> round(rnorm(20, 15, 3)))
> dat2 <- data.frame(station = letters[1:5], temp = round(rnorm(5, 15,
> 4)))
> ################
> dat <- merge(dat1, dat2, by = "station")
> do.call("rbind", lapply(split(dat, dat$station), function(x){
> out <- x[x$temp.x > x$temp.y, ]
> if(nrow(out)) out else rep(NA, length(x))
> }))
>
>
> I hope it helps.
>
> Best,
> Dimitris
>
> ----
> Dimitris Rizopoulos
> Ph.D. Student
> Biostatistical Centre
> School of Public Health
> Catholic University of Leuven
>
> Address: Kapucijnenvoer 35, Leuven, Belgium
> Tel: +32/16/336899
> Fax: +32/16/337015
> Web: http://www.med.kuleuven.be/biostat/
> http://www.student.kuleuven.be/~m0390867/dimitris.htm
>
>
> ----- Original Message -----
> From: "alessandro carletti" <alxmilton@yahoo.it>
> To: "rHELP" <R-help@stat.math.ethz.ch>
> Sent: Tuesday, August 09, 2005 9:58 AM
> Subject: [R] more on vector vs array
>
>
> >
> > Ok, thanks,
> > I'll try with a simplier example:
> >
> > I have a vector with 4 levels
> >
> > dataframe 1
> > station temp
> > aaa 12
> > aaa 13
> > bbb 12
> > bbb 20
> > aaa 23
> > bbb 21
> > ccc 30
> > ccc 18
> > ddd 15
> > aaa 11
> > ddd 15
> > ddd 10
> >
> >
> > and a thresholds vector
> >
> > station thr
> > aaa 20
> > bbb 18
> > ccc 25
> > ddd 10
> >
> >
> > I vant to select from dataframe 1 each value (level by
> > level) > its own threshold value.
> > How to do it automatically? (vector temp and vector
> > thr have different length)
> >
> > Thanks
> >
> > ______________________________________________
> > R-help@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
> >
>
> ______________________________________________
> R-help@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
>



R-help@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 Received on Tue Aug 09 20:16:26 2005

This archive was generated by hypermail 2.1.8 : Sun 23 Oct 2005 - 15:10:47 EST