s-news
[Top] [All Lists]

Re: tapply() on columns of matrix

To: "Eric Turkheimer" <ent3c@virginia.edu>
Subject: Re: tapply() on columns of matrix
From: David L Lorenz <lorenz@usgs.gov>
Date: Tue, 19 Dec 2006 09:07:35 -0600
Cc: s-news@lists.biostat.wustl.edu, s-news-owner@lists.biostat.wustl.edu
In-reply-to: <a42e7d400612190614i536ef03h4469b435bb33ba70@mail.gmail.com>

Eric,
  It is possible to use tapply() for this kind of analysis, but it is more straightforward to use by(). Look at the documentation for by(). The call that you want would be something like:

by(X, X[,3], function(x) var(x[,1:2])

Dave


"Eric Turkheimer" <ent3c@virginia.edu>
Sent by: s-news-owner@lists.biostat.wustl.edu

12/19/2006 08:14 AM

To
s-news@lists.biostat.wustl.edu
cc
Subject
[S] tapply() on columns of matrix





I have a matrix with three columns.  I would like to compute the covariance between the first two, separately according to values of the third.  The best I can figure out is to split the matrix up into a list using split(), and then use sapply().  I was wondering if there was a more direct way.  A little more generally, how can you use tapply to evaluate bivariate functions?

Thanks,
Eric

--
Eric Turkheimer, PhD
Department of Psychology
University of Virginia
PO Box 400400
Charlottesville, VA  22904-4400

434-982-4732
434-982-4766 (FAX)

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