[R] conditional loop

jim holtman jholtman at gmail.com
Wed Oct 1 02:23:34 CEST 2008


It looks like you are test against TAZDetermine before it is defined.
Try something like this:

while(TRUE){
    ...generate random number
    if (value > Dev_size) break
}

On Tue, Sep 30, 2008 at 6:56 PM, PDXRugger <J_R_36 at hotmail.com> wrote:
>
> I am looking up a number based upon a randomly selected number and then
> proceed to the rest of my code if the corresponding value is greater than or
> equal to yet another value.
>
> so if
>
> Dev_Size = 14
>
> and my randomly selected number is 102
>
> and i am looking up 102 in the following table
>
> 100  21
> 101  4
> 102  9
> 103  52
> 104  29
>
> So i select the the corresponding value of 102, which is 9 and determine if
> it is greater than or equal to Dev_Size and if it is i would proceed, if not
> i would like my random number generator to select another number until
> complies with the requirement.  I have tried below but my while loop doesnt
> do what i would like.  I cant seem to find a good resource for my problem,
> any help would be much appreciated.
>
> Cheers,
> JR
>
>
>
>
> #Loads TAZ and corresponding vacant acres data
> TAZ_VAC_ACRES=
> read.csv(file="C:/LUSDR/Workspace/BizLandPrice/data/TAZ_VAC_ACRES.csv",header=TRUE);
>
>
> #Test Location Choice Model selected TAZ
>
> while(TAZDetermine <= Dev_Size){
>
> #Randomly generates test TAZ from 100 to 844
> RndTAZ=sample(100:844,1,replace=T)
>
> #Renames randomly generated TAZ's object
> Loc_Mod_TAZ = RndTAZ
>
> #Create test Development
> Dev_Size=50
>
> #Determines vacant acres by TAZ
> TAZDetermine=TAZ_VAC_ACRES[TAZ_VAC_ACRES$TAZ==Loc_Mod_TAZ,2]
>
> #Displays number of vacant acres in Location Choice Model selected TAZ
> TAZDetermine
>
> }
>
> --
> View this message in context: http://www.nabble.com/conditional--loop-tp19751172p19751172.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> 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.
>



-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem that you are trying to solve?



More information about the R-help mailing list