[R] for/if loop
SnowManPaddington
wiwiana at gmail.com
Wed Jan 28 09:21:37 CET 2009
Hi, it's my first time to write a loop with R for my homework. This loop is
part of the function. I wanna assign values for hll according to panel
[ii,1]=pp. I didn't get any error message in this part. but then when I
further calculate another stuff with hll, the function can't return. I think
it must be some problem in my loop. Probably something stupid or easy. But I
tried to look for previous posts in forum and read R language help. But none
can help.. Thanks!
for (ii in 1:100){
for (pp in 1:pp+1){
for (rr in 1:rr+1){
if (panel[ii,1]!=pp)
{
hll(pp,1)=ColSums(lselb1(rr:ii-1,1))
hll(pp,2)=ColSums(lselb2(rr:ii-1,1))
rr=ii
pp=pp+1
}
else
{
hll(pp,1)=ColSums(lselb1(rr:ii,1))
hll(pp,2)=ColSums(lselb2(rr:ii,1))
rr=ii
pp=pp+1}
}
}}}
in fact I have the corresponding Gauss code here. But I really don't know
how to write such loop in R.
rr=1;
ii=1;
pp=1;
do until ii==n+1;
if pan[ii,1] ne pp;
hll[pp,1]=sumc(lselb1[rr:ii-1,1]);
hll[pp,2]=sumc(lselb2[rr:ii-1,1]);
rr=ii;
pp=pp+1;
endif;
if ii==n;
hll[pp,1]=sumc(lselb1[rr:ii,1]);
hll[pp,2]=sumc(lselb2[rr:ii,1]);
rr=ii;
pp=pp+1;
endif;
ii=ii+1;
endo;
--
View this message in context: http://www.nabble.com/for-if-loop-tp21701496p21701496.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list