s-news
[Top] [All Lists]

Re: Mixing tapply and diff

To: "Tristan Lorino" <tristan.lorino@lcpc.fr>
Subject: Re: Mixing tapply and diff
From: "Dimitris Rizopoulos" <dimitris.rizopoulos@med.kuleuven.be>
Date: Thu, 16 Feb 2006 09:41:52 +0100
Cc: <s-news@lists.biostat.wustl.edu>
References: <1583438515.20060216093556@lcpc.fr>
you already have it; you could use:

vals <- tapply(as.vector(SDF1$V1), SDF1$V2, diff)
out <- data.frame(id = rep(unique(SDF1$V2), sapply(vals, length)), diff = vals)
out


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/(0)16/336899
Fax: +32/(0)16/337015
Web: http://www.med.kuleuven.be/biostat/
    http://www.student.kuleuven.be/~m0390867/dimitris.htm


----- Original Message ----- From: "Tristan Lorino" <tristan.lorino@lcpc.fr>
To: "S-News" <s-news@lists.biostat.wustl.edu>
Sent: Thursday, February 16, 2006 9:35 AM
Subject: [S] Mixing tapply and diff


Hi,

I have two columns: one concerning quantitative data (V1), the other
concerning the identification of the repeated measures made on the
same units (V2) ; here, there is 3 measures on the first unit, 4
measures on the 2d unit, and so one...

 V1 V2
1  5  1
2  3  1
3  6  1
4  4  2
5  7  2
6  8  2
7  9  2
8  6  3
9  5  3
10  2  4
11 31  4

I would like to obtain (ideally...) a data frame or matrix with the
ident variable and the difference between measures made on the same
unit: something as returned by

tapply(as.vector(SDF1$V1),SDF1$V2,diff)
$"1":
[1] -2  3

$"2":
[1] 3 1 1

$"3":
[1] -1

$"4":
[1] 29

but in a suitable way (data array), that means:

ident  diff
1      -2
1      3
2      3
2      1
2      1
.....

Thank you for your help,
Tristan

--
Laboratoire Central des Ponts et Chaussées
[Division ESAR ? Section AGR]
Route de Bouaye BP 4129
44341 Bouguenais Cedex
France
Tél 33 (0)2 40 84 56 18
Fax 33 (0)2 40 84 59 92

--------------------------------------------------------------------
This message was distributed by s-news@lists.biostat.wustl.edu.  To
unsubscribe send e-mail to s-news-request@lists.biostat.wustl.edu with
the BODY of the message:  unsubscribe s-news



Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm


<Prev in Thread] Current Thread [Next in Thread>