[R] Defining array for nested for.loop.

Jeff Newmiller jdnewmil at dcn.davis.CA.us
Mon Feb 17 04:53:22 CET 2014


Read the posting guide. This is not a homework help forum.
---------------------------------------------------------------------------
Jeff Newmiller                        The     .....       .....  Go Live...
DCN:<jdnewmil at dcn.davis.ca.us>        Basics: ##.#.       ##.#.  Live Go...
                                      Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/Batteries            O.O#.       #.O#.  with
/Software/Embedded Controllers)               .OO#.       .OO#.  rocks...1k
--------------------------------------------------------------------------- 
Sent from my phone. Please excuse my brevity.

On February 16, 2014 7:27:06 PM PST, Mathew Nagendran <mathew.nagendran at mail.utoronto.ca> wrote:
>Hey guys. The idea is I want to create a nested for.loop using pick.a
>values and m.control and m.sham at trunc1 to trunc6. How would I go
>about defining an array for this? I am unsure about what to put into
>length( ). In my last assignment it was a little bit more
>straightforward since I had:
>
>
>pick.a=seq(0.01,2,by=0.01) #set of a values defined
>
>pick.d=seq(0.01,1,by0.01) #set of d values defined
>
>output=array(NA,c(length(pick.a), length(pick.d))) ?
>
>-----------------------------------------------------------------------------------------------------------------------------------------
>
>
>#--New work here--#
>
>
>m.control=c(1.45,9.40,9.96,4.2,1.86,0.2)
>
>m.sham=c(3.39,23.94,23.62,10.08,2.99,1.09)
>
>
>t.control=function(m, a){(1-exp(-a*m))*((1-(1/30)*m))}
>
>t.ratio=function(ts, tc){(ts/tc)}
>
>pick.a=seq(0.01,2,by=0.01) #set of a values defined
>
>
>trunc1=-6
>
>trunc2=c(-5,-6)
>
>trunc3=c(-4,-5,-6)
>
>trunc4=c(-3,-4,-5,-6)
>
>trunc5=c(-2,-3,-4,-5,-6)
>
>trunc6=c(-1,-2,-3,-4,-5,-6)
>
>
>output=array(NA,c(length(pick.a), length()))
>
>
>for(count in 1:length(pick.a)){
>
>for(count1 in 1:6){
>
>if(count1==1){trunc=trunc1}
>
>if(count1==2){trunc=trunc2}
>
>if(count1==3){trunc=trunc3}
>
>if(count1==4){trunc=trunc4}
>
>if(count1==5){trunc=trunc5}
>
>if(count1==6){trunc=trunc6}
>
>  ts1=sum(t.control(m.sham[trunc],pick.a[count]))
>
>  tc1=sum(t.control(m.control[trunc],pick.a[count]))
>
>output[count,count1]=(ts1/tc1)
>
>}
>
>}
>
>dim(output)
>
>print(output)
>
>
>	[[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