[R] lapply question
Dave Evens
devens8765 at yahoo.com
Wed Jul 20 11:57:35 CEST 2005
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=""))
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
...
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 it possible to give apply an array
and output a list?
Thanks for any help in advance.
Dave
More information about the R-help
mailing list