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

2005-12-05 Thread Serguei Kaniovski
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

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

2005-12-05 Thread Christian Hennig
Hi, I guess that res[i,j] needs integers as indexes. I would try it like this: (corrected) 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 1:length(run_rows)) { for(j in 1:length(run_cols)) {

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

2005-12-05 Thread Barry Rowlingson
Serguei Kaniovski wrote: Hi, I have a more complex example, but the problem boils down to this FOR-loop not filling in the res-matrix for(i in run_rows) { for(j in run_cols) { res[i,j]=i+j have a look at what i and j are in such a loop: for(i in run_rows){ +

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

2005-12-05 Thread jim holtman
try this: (you were trying to index with non-integer numbers) 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 1:length(run_rows)) { for(j in 1:length(run_cols)) { res[i,j] = run_rows[i] + run_cols[j] #niether

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

2005-12-05 Thread Barry Rowlingson
Christian Hennig wrote: 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 1:length(run_rows)) { for(j in 1:length(run_cols)) { res[i,j]=run_rows[i]+run_cols[j] } } Or the one-liner: res = outer(run_rows,run_cols,+)

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

2005-12-05 Thread Dimitris Rizopoulos
: +32/(0)16/336899 Fax: +32/(0)16/337015 Web: http://www.med.kuleuven.be/biostat/ http://www.student.kuleuven.be/~m0390867/dimitris.htm - Original Message - From: Serguei Kaniovski [EMAIL PROTECTED] To: r-help@stat.math.ethz.ch Sent: Monday, December 05, 2005 12:47 PM Subject: [R] What