s-news
[Top] [All Lists]

Re: lapply question

To: Dave Evens <devens8765@yahoo.com>
Subject: Re: lapply question
From: Patrick Burns <pburns@pburns.seanet.com>
Date: Tue, 19 Jul 2005 14:56:11 +0100
Cc: s-news@lists.biostat.wustl.edu
In-reply-to: <20050719133526.3914.qmail@web61315.mail.yahoo.com>
References: <20050719133526.3914.qmail@web61315.mail.yahoo.com>
User-agent: Mozilla Thunderbird 1.0.2 (Windows/20050317)
Your problem with 'names' is that you are using a list
where you should use a vector.  That is:

names(alist) <- c('array 1', 'array 2')

On the 'lapply' question, you should be able to do it,
I would write a function that takes a matrix and practice
with it until I got the format I wanted.

Patrick Burns
patrick@burns-stat.com
+44 (0)20 8525 0696
http://www.burns-stat.com
(home of S Poetry and "A Guide for the Unwilling S User")

Dave Evens wrote:

Dear members,

I have numerous arrays that are organised in a list.
For example, suppose I have 2 arrays in a list called
alist

alist <- list(array(rpois(12,5), 6:8)
, array(rpois(15,5), 10:12))

with array dimnames

dimnames(alist[[1]]) <- list(LETTERS[1:6],
paste("namesd", 1:7, sep=""), paste("namese", 1:8,
sep=""))
dimnames(alist[[2]]) <- list(LETTERS[7:16],
paste("namesf", 1:11, sep=""), paste("namesg", 1:12,
sep=""))

My first question is: is it possible to name the
arrays themselves, e.g. if I try

names(alist) <- list("Array 1", "Array 2")

I get "\" and \"" at the beginning and end of each
name, i.e.
[1] "\"Array 1\"" "\"Array 2\""

Secondly, I would like to use the lapply function to
produce a report with:

____________________________________________________
Array 1
Dimension name: namese1

Row  Value              Value-Average(excluding Value)
A alist[[1]][1,1,1] alist[[1]][1,1,1]-mean(alist[[1]][1,-1,1])

...etc for all elements in the first row on the array

B alist[[1]][2,1,1] alist[[1]][2,1,1]-mean(alist[[1]][2,-1,1])

...etc

Dimension name: namese2
....
Dimension name: namese8
A...

Array 2

Dimension name: namesg1

...

Dimension name: namesg12
...

______________________
Can I use the apply to do this, something like

lapply(alist, function(k), apply(k, c(1,3), ...

but how do I layout the report using the array names,
dimension names etc and with each observation on a
separate line? Is this possible?

Thanks for any help in advance.

Dave











                
____________________________________________________
Start your day with Yahoo! - make it your home page http://www.yahoo.com/r/hs
--------------------------------------------------------------------
This message was distributed by s-news@lists.biostat.wustl.edu.  To
unsubscribe send e-mail to s-news-request@lists.biostat.wustl.edu with
the BODY of the message:  unsubscribe s-news





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