[R] will vectorization help in this case?

From: Nachiketa Sahoo <nsahoo_at_gmail.com>
Date: Mon 23 Jan 2006 - 17:52:53 EST


Hi all,

I am doing a array marginalization over one dimension in the following manner:



for(l in 1:L)
{

   flst=list(Pzu, Pzi, array(Puzu[,as.character(r[[l,"u"]])], dim=dim(Puzu)[1], dimnames=dimnames(Puzu)[1]), array(Pizi[,as.character(r[[l, "i"]])], dim=dim(Pizi)[1], dimnames=dimnames(Pizi)[1]) );

    tempa = 1;
    for(j in 1:length(flst)) tempa = tempa %X% flst[[j]];

    tempPzu = apply(tempa, 1, sum);
    tPzu = tPzu + tempPzu;
    tPuzu[,as.character(r[[l,"u"]])] = tPuzu[,as.character(r[[l,"u"]])] + tempPzu;

    tempPzi = apply(tempa, 2, sum);
    tPzi = tPzi + tempPzi;
    tPizi[,as.character(r[[l,"i"]])] = tPizi[,as.character(r[[l,"i"]])] + tempPzi;

    for(j in 1:ncomp) tPrjzuzilst[[j]][,,r[[l,rbase+j]]] = tPrjzuzilst[[j]][,,r[[l,rbase+j]]] + tempa; }



My question involves the operation using tempPzu and tempPzi. Is my use of loop in this case to addup certain arrays together, too .. dumb? Is there another way of doing such things by vectorization?

Thanks in advance,
Nachiketa

        [[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 Received on Mon Jan 23 18:02:46 2006

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:42:09 EST