|
Another idea would be
coef(lm(cbind(price, volume, yield) ~ as.factor(code) - 1,
mydat))
but
this is limited to the special case of the mean. Andy's idea is easier to
generalize.
One way or the other, the data need to be split into
groups. Here's one possible way:
sapply(split(mydata, mydata$code), colMeans)
Andy
A friend of mine has a data
set
With variables
:
code price volume
yield
where code is an integer and can
take on
say 20 different
values.
He wants the means of price,
volume, yield
But within each code
value.
Obviously, he can break it up by
each code and then
take the means but he was
hoping
there was a
quicker
way to do this ?
Thanks.
mark
------------------------------------------------------------------------------ Notice:
This e-mail message, together with any attachments, contains information of
Merck & Co., Inc. (One Merck Drive, Whitehouse Station, New Jersey, USA
08889), and/or its affiliates (which may be known outside the United States as
Merck Frosst, Merck Sharp & Dohme or MSD and in Japan, as Banyu) that may
be confidential, proprietary copyrighted and/or legally privileged. It is
intended solely for the use of the individual or entity named on this message.
If you are not the intended recipient, and have received this message in
error, please notify us immediately by reply e-mail and then delete it from
your
system. ------------------------------------------------------------------------------
|