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.
Thank you! Elisa 2013/11/20 Carl Witthoft [via R] <ml-node+s789695n4680803h80@n4.nabble.com>> 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 > > > > ------------------------------ > If you reply to this email, your message will be added to the discussion > below: > > http://r.789695.n4.nabble.com/Multiple-if-statement-in-loop-condition-tp4680797p4680803.html > To unsubscribe from Multiple if statement in loop condition, click here<http://r.789695.n4.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=4680797&code=ZGFsbWFzby5lbGlzYUBnbWFpbC5jb218NDY4MDc5N3w3NzM3NDgyMzQ=> > . > NAML<http://r.789695.n4.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml> >-- View this message in context: http://r.789695.n4.nabble.com/Multiple-if-statement-in-loop-condition-tp4680797p4680808.html Sent from the R help mailing list archive at Nabble.com. [[alternative HTML version deleted]]
On Nov 20, 2013, at 4:24 AM, Carl Witthoft wrote:> 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.Arguably it is due to the superfluous "(" after the "&". Further evidence perhaps of the value of adding spaces before and after parentheses. Also evidence of the value of an R-aware editor. -- David.> > 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. > > ______________________________________________ > 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.David Winsemius Alameda, CA, USA