[R] how to "multiply" list of matrices by list of vectors
smartpink111 at yahoo.com
Wed Feb 6 15:13:30 CET 2013
I got an error message with:
vlist <- apply(mm, list)
Error in match.fun(FUN) : argument "FUN" is missing, with no default
vlist <- apply(mm,2,list)
----- Original Message -----
From: David Romano <dromano at stanford.edu>
To: r-help at r-project.org
Sent: Wednesday, February 6, 2013 12:50 AM
Subject: [R] how to "multiply" list of matrices by list of vectors
I'd like to be able to apply lda to each 2D matrix slice of a 3D array, and
then use the scalings to obtain the corresponding lda scores.
I can use 'apply' to get a list of the lda output for each 2D slice, and
can create a list of the resulting scalings, but I'm not sure how to
multiply them in a vectorized way.
Here's how I made a list of 2D matrices (suggestion on improving this would
be welcome, too!):
> aa <- array(1:24,c(4,2,3))
> mlist <- apply(aa,2,list)
> mlist <- lapply(mlist, unlist)
> mlist <- lapply(mlist, function(x) matrix(x,4,2))
and here's how I made a list of vectors:
> mm <- matrix(1:6,2,3)
> vlist <- apply(mm, list)
> vlist <- lapply(vlist, unlist)
Now I'd like to make the list whose i-th element is mlist[[i]]%*%vlist[[i]]
without having to loop through the indices.
Any help would be appreciated!
[[alternative HTML version deleted]]
R-help at r-project.org mailing list
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
More information about the R-help