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])))
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
|