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)])}}}))) Also, if what I'm trying to do makes any sense and someone sees an easier way of doing it, that would be great. Thanks! Milo Undergraduate -- Reed College Portland, OR
On 03/03/2010 2:27 AM, Milo Phillips-Brown wrote:> 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)])}}})))That's very strange formatting, mixing () and {} and not doing any indenting, so I don't know what you're trying to do. But the problem appears to be your while loop: you never change the condition G[j] == 1, so that loop will continue indefinitely. Duncan Murdoch> > Also, if what I'm trying to do makes any sense and someone sees an > easier way of doing it, that would be great. > > 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.
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 guidehttp://www.R-project.org/posting-guide.html> and provide commented, minimal, self-contained, reproducible code.