[R] Odp: Trouble With for() Loops

Petr PIKAL petr.pikal at precheza.cz
Wed Mar 3 16:42:24 CET 2010


Hi

r-help-bounces at r-project.org napsal dne 03.03.2010 08:27:27:

> Hello,
> 
> I'm trying to learn R (for fun!), and I've tried to find any previous 
> discussion of this problem (or something like it) and haven't found one.
> 
> When I run the following command, R seems to simply stop. I get no error 

> message, but I also have no ">" or "+" to type after (although I can 
> type). The only solution seems to be restarting the program. Here's the 
> code:
> 
> for(i in 1:150)
> for(j in 1:150)
> (average <-c(
> (if(NO[i]==1)
> {i*0}
> else
> {if(HA[i]==HA[j])
> {while(G[j]==1)
> {mean(PT[j:(i-1)])}}})))

Strange that you get no error. When I used your code I got

> for(i in 1:150)
+ for(j in 1:150)
+ (average <-c(
+ (if(NO[i]==1)
+ {i*0}
+ else
+ {if(HA[i]==HA[j])
+ {while(G[j]==1)
+ {mean(PT[j:(i-1)])}}})))
Error: object 'NO' not found
^^^^^^^^^^^^^^^^^^^^^^^^^^^^

> 
> Also, if what I'm trying to do makes any sense and someone sees an 
> easier way of doing it, that would be great.

And what really you are trying to do? Use R like C+? No way, forget it. R 
is R C+ is C+.

Regards
Petr

> 
> Thanks!
> 
> Milo
> Undergraduate -- Reed College
> Portland, OR
> 
> ______________________________________________
> 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.



More information about the R-help mailing list