Re: [R] What is wrong with this FOR-loop?

From: Dimitris Rizopoulos <dimitris.rizopoulos_at_med.kuleuven.be>
Date: Mon 05 Dec 2005 - 23:13:24 EST

your indexing is wrong; another way to achieve the same result is

outer(run_rows, run_cols, "+")

I hope it helps.

Best,
Dimitris



Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium

Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://www.med.kuleuven.be/biostat/
     http://www.student.kuleuven.be/~m0390867/dimitris.htm


> Hi, I have a more complex example, but the problem boils down to
> this
> FOR-loop not filling in the res-matrix
>
> run_rows<-seq(0,1,0.05)
> run_cols<-seq(0.3,0.6,0.05)
>
> res<-matrix(NA,length(run_rows),length(run_cols))
>
> for(i in run_rows)
> {
> for(j in run_cols)
> {
> res[i,j]=i+j
> #niether the above, nor res[[i,j]]=i+j work, why?
> }
> }
>
> Thank you,
> Serguei
>
> ______________________________________________
> 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
>

Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm



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 Dec 05 23:23:19 2005

This archive was generated by hypermail 2.1.8 : Tue 06 Dec 2005 - 02:26:58 EST