[R] Saving each output of a loop into something that can be graphed

John Kane jrkrideau at yahoo.ca
Mon Oct 5 16:35:28 CEST 2009


Define a matrix to hold the data and insert it into the loop?

Something like 

mymat <- matrix(rep(NA, 20), nrow=10)
for(i in 1:10){
a <- i
b <- i+1
mymat[i,] <- c(a,b)
}

matplot(mymat)



--- On Mon, 10/5/09, RRRRRR99 <redhwanzaman at hotmail.com> wrote:

> From: RRRRRR99 <redhwanzaman at hotmail.com>
> Subject: [R] Saving each output of a loop into something that can be graphed
> To: r-help at r-project.org
> Received: Monday, October 5, 2009, 2:27 AM
> 
> Hi, 
> 
> from the code below; whats happening is i want to plot how
> the [1,9] entry
> changes as the matrx changes, print[] gives the values one
> after the other,
> but only the last value is saved so my graph has only one
> point. does anyone
> know how i can merge all the outputs into one dataframe or
> something?
> 
> Q<-matrix(c(-0.59,5.44,0,0,0,0,0,0,0,0.59,-8.16,2.51,0,0,0,0,0,0,0,2.72,-5.64,9.45,0,0,0,0,0,0,0,3.13,-13.23,6.91,0,0,0,0,0,0,0,3.15,-14.88,10.22,0,0,0,0,0,0,0.63,7.97,-19.81,30.19,0,96.77,0,0,0,0,0,7.67,-98.12,0,19.35,0,0,0,0,0,0,37.74,-315.79,0,0,0,0,0,0,1.92,30.19,315.79,-116.12),nrow=9,ncol=9)
> T<-Q*.01
> for (i in (1:10)){
> R<-MatrixExp(i*T)
> S<-print(R[1,9])
> }
> 
> 
> any help would be greatly appreciated.
> -- 
> View this message in context: http://www.nabble.com/Saving-each-output-of-a-loop-into-something-that-can-be-graphed-tp25745700p25745700.html
> Sent from the R help mailing list archive at Nabble.com.
> 
> ______________________________________________
> 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.
> 


      __________________________________________________________________
[[elided Yahoo spam]]




More information about the R-help mailing list