|
"tapply" returns an array or vector, and "aggregate" returns a dataframe or
a time series, presumably depending on what was input.
"aggregate.data.frame" apparently always returns a dataframe. "aggregate"
syntax is similar to "tapply" syntax. I'm guessing, and may be wrong, that
you'd want to try:
aggregate(temp$tex,temp$id,cumsum)
or
aggregate.data.frame(temp$tex,temp$id,cumsum)
Or if you're not trying to get the sum as it cumulates, but only the
result, you might try replacing "cumsum" with "sum."
I write this without experience, and I'm interested in the result.
>>> <vincent.duval@fr.netgrs.com> 08/18/03 10:11AM
>>> Hi, I know this is something that has been discuss many time
earlier in this list but I haven't been able to find out any answer from the
archives. So maybe someone could give me a hand with my prolem. I have a
dataframe, with repeated observations ,from 2 to 5 observations, for each
subject: Number of observation vary depending of the subject. What I am
trying to do is to get the cumumative sum of the observations for each
subject. I managed to get the result I want through the "tapply" function.
But it sorts out a list that I would like to transforme as a dataframe with
one colonne for ID and the second for the cumulative
sum.
tapply(temp$tex,list(temp$id),cumsum) # temp$tex is 1 at every
column which gave me the following output.
$"23236": [1] 1
2
$"23467": [1] 1 2 3 4 5
$"23487": [1] 1 2 3 4
5
$"23505": [1] 1 2 3 4 5
$"23258": [1] 1
2
$"23425": [1] 1 2 3 4 5
$"23630": [1] 1 2 3 4
5
$"6061": [1] 1 2 3 4 5
$"23120": [1] 1
2
$"23191": [1] 1 2
This output gave the correct results, but I
can not manage to get transform such list into a dataframe, or maybe there is
other ways around to get the expected result. Anyhelp would be very
wellcome,
Thanks a
lot,
Vincent
-------------------------------------------------------------------- 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
|