[R] Usage of repeat,while or loop. Documetation?
Torleif Markussen Lunde
tlu004 at student.uib.no
Thu Jul 6 12:04:54 CEST 2006
Hi
I want to run the loop described in the example below, but cannot find any
good documentation on how to do it. I wold be very happy if someone could
help me on this, as it would save me for a lot of work.
Kindest regards
Torleif
University of Bergen/Norway
#Sample 1
m<-0
#35-40
#want to repeat this untill m=300
m<-m+1
if (length(type[maling==m&type==1&length>=35&length<=39])>0)
a<-length(type[maling==m&type==1&length>=35&length<=39]) else a<-0
if (length(type[maling==m&type==2&length>=35&length<=39])>0)
b<-length(type[maling==m&type==2&length>=35&length<=39]) else b<-0
if (length(type[maling==m&type==3&length>=35&length<=39])>0)
c<-length(type[maling==m&type==3&length>=35&length<=39]) else c<-0
if (length(type[maling==m&type==4&length>=35&length<=39])>0)
d<-length(type[maling==m&type==4&length>=35&length<=39]) else d<-0
if (length(type[maling==m&type==5&length>=35&length<=39])>0)
e<-length(type[maling==m&type==5&length>=35&length<=39]) else e<-0
a35<-(a+b)/(a+b+c+d+e); a35<-format(a35,digits=4)
l35<-length(length[maling==m&type==1&length>=35&length<=39])
.
.
.
.
.
#65+
if (length(type[maling==m&type==1&length>=65])>0)
a<-length(type[maling==m&type==1&length>=65]) else a<-0
if (length(type[maling==m&type==2&length>=65])>0)
b<-length(type[maling==m&type==2&length>=65]) else b<-0
if (length(type[maling==m&type==3&length>=65])>0)
c<-length(type[maling==m&type==3&length>=65]) else c<-0
if (length(type[maling==m&type==4&length>=65])>0)
d<-length(type[maling==m&type==4&length>=65]) else d<-0
if (length(type[maling==m&type==5&length>=65])>0)
e<-length(type[maling==m&type==5&length>=65]) else e<-0
a65<-(a+b)/(a+b+c+d+e); a65<-format(a65,digits=4)
l65<-length(length[maling==m&type==1&length>=65])
la1<-latitude[maling==m]; la1<-format(la1[1],digits=9)
lo1<-longitude[maling==m]; lo1<-format(lo1[1],digits=9)
year1<-year[maling==m]; year1<-format(year1[1],digits=4)
mnd1<-mnd[maling==m]; mnd1<-format(mnd1[1],digits=2)
dag1<-dag[maling==m]; dag1<-format(dag1[1],digits=2)
omr1<-omr[maling==m]; omr1<-format(omr1[1],digits=2)
dist1<-dist[maling==m]; dist1<-format(dist1[1],digits=2)
start1<-start[maling==m]; start1<-format(start1[1],digits=4)
stopp1<-stopp[maling==m]; stopp1<-format(stopp1[1],digits=4)
homr1<-homr[maling==m]; homr1<-format(homr1[1],digits=2)
skip1<-skip[maling==m]; skip1<-skip1[1]
######################
#Then i want to update the kt1 name to change from kt1 to kt2 to kt3...
#kt300. The goal is to create a table with
#kt1
#kt2
.
.
#kt300
#by using rbind. Suggestions on how to update the table as the loop is
#running are welcome.
######################
kt1<-c(la1,lo1,year1,mnd1,dag1,omr1,dist1,start1,stopp1,homr1,a30,a35,a40,a45,a50,a55,a60,a65,l30,l35,l40,l45,l50,l55,l60,l65)
More information about the R-help
mailing list