[R] Problem in loop
Petr PIKAL
petr.pikal at precheza.cz
Thu Mar 22 10:59:25 CET 2012
Hi
>
> Dear R users
> I want change the entries in a matrix. I did a matrix
>
>
>
> A=0 1 5
>
> .3 0 0
>
> 0 .5 0
>
>
>
> A1<-A
>
>
> A2<-A*0.90
> A2
>
> 1 2 3
>
> 1 0.00 0.90 4.5
>
> 2 0.27 0.00 0.0
>
> 3 0.00 0.45 0.0
>
>
>
> I need replace elements one by one in a loop
>
> I tried the following using package POPBIO,
>
> total <-matrix(0, nrow=5, ncol=60)
>
> for(i in 1:10){
>
> A1<-A
^^^^^^^^^^^
here you change A1 in each loop to A, is it what you want?
Regards
Petr
>
> A1[1,2] <- A2[1,2]
>
> A1[1,3]<-A2[1,3]
>
> A1[2,1]<-A2[2,1]
>
> A1[3,2]<-A2[3,2]
>
> n <-runif(3)
>
> n <- n/sum(n)
>
> p1<-pop.projection(A1,n,60)
>
> total[i,] <- p1$pop.sizes}
>
> matplot2(total, legend=NA,xlab=c(years))
>
>
>
> but i not view change in population
>
>
>
>
>
> Thanks in advance
>
> Fidel M.
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org 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.
More information about the R-help
mailing list