s-news
[Top] [All Lists]

Re: [s-news] S-News Daily Digest V2 #1954

To: David L Lorenz <lorenz@usgs.gov>, s-news@lists.biostat.wustl.edu
Subject: Re: [s-news] S-News Daily Digest V2 #1954
From: Doug Bolgiano <dougb@psbcresearch.org>
Date: Fri, 16 Jan 2009 12:56:58 -0800
In-reply-to: <OF2F1B93BE.B0448717-ON86257540.0068ADF2-86257540.00690EDD@usgs.gov>
References: <20090115112005.D3D7612427E@smtp.biostat.wustl.edu> <cb444ad00901160951l7abe84ado69ab3d9d1956318c@mail.gmail.com> <OF2F1B93BE.B0448717-ON86257540.0068ADF2-86257540.00690EDD@usgs.gov>
David -

That's exactly what I want.  It hadn't occurred to me to use a generic function with lapply to get acf component from each list.  Thanks.

Doug

On Fri, Jan 16, 2009 at 11:07 AM, David L Lorenz <lorenz@usgs.gov> wrote:

Doug,
  Is this what you want? You'll need to recreate the rownames.
Dave
t(as.data.frame(
    lapply(
      lapply(DATA, function(x, lag) acf(x,lag), lag=3),
    function(x) x$acf[,,1])))



Doug Bolgiano <dougb@psbcresearch.org>
Sent by: s-news-owner@lists.biostat.wustl.edu

01/16/2009 11:51 AM

To
cc
Subject
Re: [S] [s-news] S-News Daily Digest V2 #1954





extracting components from a list of lists

I use tapply with the acf function (lag =3) and the subject index of a data frame to calculate autocorrelations for a variable measured repeatedly on each subject (n = 180).  The result is a list of lists (which are the output of the acf function), one for each subject.  I want to extract the $acf component from each subject's list and form a matrix where rows index subjects and columns index lags.  

I have tried using the subscript operators [] and [[ ]] to extract the acf componets.  Do I have to resort to looping through the subject lists and extracting the acf component from each list individually or is there a more efficient way to do this?

Doug Bolgiano
Puget Sound Blood Center
Seattle, WA  98104



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