[R] difficult "for"

Grzes gregorio99 at gmail.com
Sun Aug 23 22:36:00 CEST 2009


Hi,
My english isn't briliant and my problem is very dificult to descripe but I
try ;)
My first question is: May I write loop "for" like this or similar - for (i
in sth : sth[length(sth)],  k in sth else : length(sth else) ) -  I'd like
to have two independent conditions in the same loop "for". 

My secound question depend on program below. I'd like to write every result
in matrix but I also want to call my function "odleg" use vector "e3" -
exactly using values which are inside.

Can anyone please guide me, how to do that? 
Thanks 

## Function 
odleg <- function (Xa,Xb,Ya,Yb){ 
d <- ((Xa-Xb)^2+(Ya-Yb)^2)^(1/2) 
return (d) 
} 

# Database 
ma=matrix(c(0.51139630,-0.12937287, 0.19530080,
0.02273691,-0.43634186,-0.01717149,-0.27597035,-0.41732933,-0.15476464,-0.15692965),nrow
= 5, ncol=2) 

e3<- c(1,2,4) 
for (i in e3[1] : e3[length(e3)]; (k in 1 : length(e3))){ 
for (j in e3[1] : e3[length(e3)]; (l in 1 : length(e3))){ 

me1[k,l] = odleg
(nepitabds$points[i,1],nepitabds$points[j,1],nepitabds$points[i,2],nepitabds$points[j,2]) 
}}
-- 
View this message in context: http://www.nabble.com/difficult-%22for%22-tp25107157p25107157.html
Sent from the R help mailing list archive at Nabble.com.




More information about the R-help mailing list