[R] Multiple if statement in loop condition

Carl Witthoft carl at witthoft.com
Wed Nov 20 13:24:00 CET 2013


What this message means is that a "{" showed up when some other bracket was
unpaired.  In this case, if you check your code, you'll see that 
"if(MatriceDist[i,j] > 0 & ((vectorID[i] > 0 | vectorID[j] > 0))"  is
lacking a closing ")"  for the if clause.

 

Phalaen wrote
> Hi! 
> I am a Phd student in the university of Padua and I am trying to write a
> little script (the first!) to make a simulation on epidemiology.
> I'd like to change the values of a vector of 883 values basing on a
> neighbour matrix constructed with nb2mat from a shapefile: if i and j (two
> cells) are neighbour (matrix) and i or j have a positive value in the
> vector, I'd like to transform the value of both i and j to 1 (positive),
> otherwise the value of i and j should remain 0. When I launch the next
> little script:
> 
> for(i in 1:883)
>  { for(j in 1:883)
>   { if(MatriceDist[i,j] > 0 & ((vectorID[i] > 0 | vectorID[j] > 0)) {
> 	 vectorID[i] = 1 & vectorID[j] = 1
> 		print(vectorID)
>  } } } 
> 
> the answer from the software is:
> Error: unexpected '{' in:
> " { for(j in 1:883)
>  { while(MatriceDist[i,j] > 0 & ((vectorID[i] > 0 | vectorID[j] > 0)) {"
> 
> I think that it is an error in the statement for if but I can not
> understand how to solve it...
> Thank you everyone!
> Elisa





--
View this message in context: http://r.789695.n4.nabble.com/Multiple-if-statement-in-loop-condition-tp4680797p4680803.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list