Skip to content
Prev 82901 / 398503 Next

Looking for a sort of tapply() to data frames

Hi,
On 12/15/05, Gabor Grothendieck <ggrothendieck at gmail.com> wrote:
Thanks! that helps a lot.  But I still run into problems with this. 
Sorry for bothering you with newbie questions, if my problems are
trivial, point me to a suitable guide (I did read the introductory
materials on R).

First: it works for colMeans, but it does not work for a function like this:

do.call("rbind", by(df, df$Day, function(x) cor(df$val1, df$val2))

it says "Error in do.call(....) : second argument must be a list". I
do not understand this, as the second argument is "b" of the class
"by", as it was in the case of colMeans, so it did not change...?

Second: in case of colMeans (where it works) it returns a matrix, and
I have troubles getting it back to the data.frame, so I can access
blah$Day.  Instead, I have smth like that:
V2 V3 V4 V5       V7
Tue 19 15  2  0 1.538462
Wed  5  3  6  1 1.285714

...and I do not know how to acces, for example, values for "Tue",
except with [1,] -- which is somewhat problematic.  For example, I
would like to display the 3 days for which V7 is highest.  How can I
do that?
Ops. Sorry, I didn't guess it from the manual :-)
But why is df[,1,drop=FALSE] a list?  I don't get it...
Yeah, I figured out that one.
I think I am not confident enough with the basic data types in R, I
need to understand them before I go over to specialized packages :-)

Again, thanks a lot,
January

--
------------ January Weiner 3  ---------------------+---------------
Division of Bioinformatics, University of Muenster  |  Schlo??platz 4
(+49)(251)8321634                                   |  D48149 M??nster
http://www.uni-muenster.de/Biologie.Botanik/ebb/    |  Germany