[R] R: the first and last case

From: Guazzetti Stefano <Stefano.Guazzetti_at_ausl.re.it>
Date: Wed 26 Jul 2006 - 23:13:11 EST


could it be

 dat[unlist(tapply(1:nrow(dat), ind, range)),] ?

stefano

>-----Messaggio originale-----
>Da: r-help-bounces@stat.math.ethz.ch
>[mailto:r-help-bounces@stat.math.ethz.ch]Per conto di
>Mauricio Cardeal
>Inviato: 26 July, 2006 14:22
>A: r-help@stat.math.ethz.ch
>Oggetto: [R] the first and last case
>
>
>Hi all
>
>Sometime ago I asked for a solution about how to aggregate
>data and the
>help was wonderful. Now, IŽd like to know how to extract for each
>individual case below the first and the last observation to
>obtain this:
>
>ind y
>1 8
>1 9
>2 7
>2 11
>3 9
>3 10
>4 8
>4 5
>
># Below the example:
>
>ind <- c(1,1,1,2,2,3,3,3,4,4,4,4)
>y <- c(8,10,9,7,11,9,9,10,8,7,6,5)
>dat <- as.data.frame(cbind(ind,y))
>dat
>attach(dat)
>mean.ind <- aggregate(dat$y, by=list(dat$ind), mean)
>mean.ind
>
>Thanks
>Mauricio
>
>______________________________________________
>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 and provide commented, minimal, self-contained, reproducible code.



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 and provide commented, minimal, self-contained, reproducible code. Received on Wed Jul 26 23:18:41 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Thu 27 Jul 2006 - 00:17:05 EST.

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