Re: [R] Usage of repeat,while or loop. Documetation?

From: Petr Pikal <petr.pikal_at_precheza.cz>
Date: Thu 13 Jul 2006 - 16:30:52 EST


Hi

nobody has answered your question yet, so I try. There is no reproducible code in your mail. Besides you use names of bult-in functions for your data which gives it really messy lookup.

Such tasks can be solved by do.call or maybe *apply but without more information, especially a structure of your data it is difficult to help you more.

Petr   

On 6 Jul 2006 at 12:04, Torleif Markussen Lunde wrote:

Date sent:      	Thu, 06 Jul 2006 12:04:54 +0200
From:           	Torleif Markussen Lunde <tlu004@student.uib.no>
Organization:   	UiB
To:             	r-help@stat.math.ethz.ch
Subject:        	[R] Usage of repeat,while or loop. Documetation?

> 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)
>
> ______________________________________________
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html

Petr Pikal
petr.pikal@precheza.cz



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Thu Jul 13 17:44:59 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Thu 13 Jul 2006 - 18:14:27 EST.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.