Vector of matrix

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Vector of matrix

Vieilledent Ghislain
Dear statisticians,

I would like to save results for a "for loop" in a vector previously created.
My result would be of class "matrix".

I tried the following script:

Script:
#Creation of a previous vector
n.Tree<-2
VectorX<-rep(1,n.Tree)

#loop
for (i in 1:2) {
        Ti<-MatOccurTree[Tree[i],1] #number of observation for Tree i
        Xi<-matrix(data=1,nrow=Ti,ncol=2)
        Xi[,2]<-treedata2$lnE[IdentTree==Tree[i]]
        VectorX[i]<-Xi
}

Console:
> VectorX[i]<-Xi
Warning message:
le nombre d'objets à remplacer n'est pas multiple de la taille du remplacement
"number of object to replace isn't a multiple of the length of the replacement"

Would you have any solution to create a vector of matrix "VectorX" ?

Thanks for your help.

Ghislain Vieilledent.

        [[alternative HTML version deleted]]


______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: Vector of matrix

Jacques VESLOT
It seems that Xi is a matrix; so it can't be included in a vector.

You need to create a list for the result of your "for" loop.

res <- list()

for ( i in ...) {

res[[i]] <-  Xi }


 

Vieilledent Ghislain a écrit :

>Dear statisticians,
>
>I would like to save results for a "for loop" in a vector previously created.
>My result would be of class "matrix".
>
>I tried the following script:
>
>Script:
>#Creation of a previous vector
>n.Tree<-2
>VectorX<-rep(1,n.Tree)
>
>#loop
>for (i in 1:2) {
> Ti<-MatOccurTree[Tree[i],1] #number of observation for Tree i
> Xi<-matrix(data=1,nrow=Ti,ncol=2)
> Xi[,2]<-treedata2$lnE[IdentTree==Tree[i]]
> VectorX[i]<-Xi
>}
>
>Console:
>  
>
>>VectorX[i]<-Xi
>>    
>>
>Warning message:
>le nombre d'objets à remplacer n'est pas multiple de la taille du remplacement
>"number of object to replace isn't a multiple of the length of the replacement"
>
>Would you have any solution to create a vector of matrix "VectorX" ?
>
>Thanks for your help.
>
>Ghislain Vieilledent.
>
> [[alternative HTML version deleted]]
>
>  
>
>------------------------------------------------------------------------
>
>______________________________________________
>[hidden email] mailing list
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html