Is this what you want ?
> A1<-matrix(c(1,0,0,0,0,0,0,0,0),3)
> A2<-matrix(c(1,0,0,0,1,0,0,0,0),3)
> A3<-matrix(c(1,0,0,0,1,0,0,1,0),3)
> X <- matrix(1:24,8)
> XX<-list()
> for(i in 1:3){
+ XX[[i]]<-X%*%A[[i]]
+ }
> XX
[[1]]
[,1] [,2] [,3]
[1,] 1 0 0
[2,] 2 0 0
[3,] 3 0 0
[4,] 4 0 0
[5,] 5 0 0
[6,] 6 0 0
[7,] 7 0 0
[8,] 8 0 0
[[2]]
[,1] [,2] [,3]
[1,] 1 9 0
[2,] 2 10 0
[3,] 3 11 0
[4,] 4 12 0
[5,] 5 13 0
[6,] 6 14 0
[7,] 7 15 0
[8,] 8 16 0
[[3]]
[,1] [,2] [,3]
[1,] 1 9 9
[2,] 2 10 10
[3,] 3 11 11
[4,] 4 12 12
[5,] 5 13 13
[6,] 6 14 14
[7,] 7 15 15
[8,] 8 16 16
>
Ya-Hsiu Chuang wrote:
>Dear all,
>
>I have 2 matrices, one is a 8x3 matrix, called X; the other matrix is a 3x3
indicator matrix with the diagonal element as 0 or 1. when a variable is
included in the model, the corresponding diagonal element is 1, otherwise, it is
0. Let A be a set of matrices that contain the possible indicator matrix. e.g.,
>A= [A1, A2, A3],
>where A1= [1,0,0;0,0,0,0,0,0],
>A2 =[1,0,0;0,1,0,0,0,0],
>A3 =[1,0,0;0,0,0,0,1,0]
>
>In order to derive the new X matries depending on the indicator matrices, I
use for loops to multiply both X and A as following
>
>p<-3
>for ( i in 1:p){
> XX<- X%*%A[i]
> }
>
>However, it only shows the result when i=p. How can I derive the results
which include all possible value of XX[i], i=1,..,p, rather than just i=p
>
>thanks for any help
>
>Ya-Hsiu
>
>
>
> [[alternative HTML version deleted]]
>
>______________________________________________
>R-help@stat.math.ethz.ch mailing list
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>and provide commented, minimal, self-contained, reproducible code.
>
>
>
--
Ferdinand Alimadhi
Programmer / Analyst
Harvard University
The Institute for Quantitative Social Science
(617) 496-0187
falimadhi@iq.harvard.edu
www.iq.harvard.edu
[[alternative HTML version deleted]]