you are right I forgot to unlist() 'vals', i.e.,
out <- data.frame(id = rep(unique(SDF1$V2), sapply(vals, length)),
diff = unlist(vals))
should work.
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:51 AM
Subject: [S] Re : Mixing tapply and diff
Message de Dimitris Rizopoulos, reçu le jeudi 16 février 2006 à
09:41 :
DR> you already have it; you could use:
DR> vals <- tapply(as.vector(SDF1$V1), SDF1$V2, diff)
DR> out <- data.frame(id = rep(unique(SDF1$V2), sapply(vals,
length)),
DR> diff = vals)
DR> out
Thank you... but I have an error message:
Problem in data.frameAux.list(x, na.strings = na.strings,
stringsAsFactors = str..: arguments imply differing number of rows:
2, 3, 1, 1
Use traceback() to see the call stack
12: eval(action, sys.parent())
11: doErrorAction("Problem in data.frameAux.list(x, na.strings =
na.stri
ngs, stringsAsFactors = str..: arguments imply differing number of
rows:
2, 3, 1, 1",
10: stop(paste("arguments imply differing number of rows:",
paste(nrows,
collapse = ", ")))
9: data.frameAux.list(x, na.strings = na.strings, stringsAsFactors =
str
ingsAsFactors)
8: data.frameAux.default(eval(as.name(paste("..", i, sep = ""))),
na.str
ings = na.strings, stringsAsFactors = stringsAsFactors[i])
7: data.frameAux(eval(as.name(paste("..", i, sep = ""))), na.strings
= n
a.strings, stringsAsFactors = stringsAsFactors[i])
6: data.frame(id = rep(unique(SDF1$V2), sapply(vals, length)), diff
= va
ls)
5: eval(i, local)
4: source(auto.print = auto.print, exprs =
substitute(exprs.literal))
3: script.run(exprs.literal = {
2: eval(expression(script.run(exprs.literal = {
1:
Message: Problem in data.frameAux.list(x, na.strings = na.strings,
strin
gsAsFactors = str..: arguments imply differing number of rows: 2, 3,
1,
1
--
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
--------------------------------------------------------------------
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
|