Your IF statement (if (x >= 3:6)) does not work as you probably expect it since it does not test for the range. You probably want to use "cut" to convert a value to a bucket in a range:
> x <- 3.5 > cut(x, breaks=seq(-3,5,.2), labels=FALSE) [1] 33 > seq(-3,5,.2) [1] -3.0 -2.8 -2.6 -2.4 -2.2 -2.0 -1.8 -1.6 -1.4 -1.2 -1.0 -0.8 -0.6 -0.4 -0.2 0.0 0.2 [18] 0.4 0.6 0.8 1.0 1.2 1.4 1.6 1.8 2.0 2.2 2.4 2.6 2.8 3.0 3.2 3.4 3.6 [35] 3.8 4.0 4.2 4.4 4.6 4.8 5.0 > # it is in the 33rd group > On Thu, Sep 4, 2008 at 1:52 PM, PDXRugger <[EMAIL PROTECTED]> wrote: > > I am trying to lookup a value in 1 of 10 loaded two column-data sets (Bins) > by displaying the value of the second column based on the value of the > first. For instance in > > Bin1_Acres Bin1_parprob Bin1_TAZ > [1,] 0.000442 0.9999978 356 > [2,] 0.000453 0.9999954 356 > [3,] 0.000583 0.9999925 366 > [4,] 0.000635 0.9999893 403 > [5,] 0.000756 0.9999854 358 > [6,] 0.000774 0.9999815 530 > [7,] 0.000813 0.9999773 405 > [8,] 0.000970 0.9999724 576 > [9,] 0.001022 0.9999672 569 > [10,] 0.001066 0.9999618 620 > > I would like to display the column value on Bin1_parprob based on the > closest match to Bin1_acres. So if the value i am referenceing in column 1 > (Bin1_Acres) is .009999 the value outputted would be .9999672. I keep > getting a numeric(0) error with the code i am using(see below). I think the > issue is i usually dont have an exact match and i am using a >= sign which > may be causing the problem. I need the closest match and it needs to be > larger, not smaller if not exact match is found( which is very common). > > #Test value for Vacant acres in TAZ > TAZDetermine = 24 > > #Test value for and development size > Dev_Size= 3.5 > > #Determines Bin number based on vacant acres in TAZ > BinSize=function(Dev_Size,BinNumer){ > if (TAZDetermine<=3.999) > BinNumber=1 > if (TAZDetermine>=4:6.999) > (BinNumber=2) > if (TAZDetermine >=10:16.999) > (BinNumber=3) > if (TAZDetermine>=17:27.999) > (BinNumber=4) > if (TAZDetermine>=28:49.999) > (BinNumber=5) > if (TAZDetermine>=50:90.999) > (BinNumber=6) > if (TAZDetermine>=91:150.999) > (BinNumber=7) > if (TAZDetermine>=151:340.999) > (BinNumber=8) > if (TAZDetermine>=341:650.999) > (BinNumber=9) > if (TAZDetermine>=651:3000) > (BinNumber=10) > BinNumber > } > > #so in this case Bin 4 is selected > > #Based on previously selected bin, display second column > value(Bin1_parprob). Selected value in column 1 may be slightly larger but > closest match is desirable. > > if (BinNumber==1) > (Loc_Prop=Bin1Main.data[Bin1Main.data$Bin1_Acres >=Dev_Size,1]) > if (BinNumber==2) > (Loc_Prop=Bin2Main.data[Bin2Main.data$Bin2_Acres>=Dev_Size,1]) > if (BinNumber==3) > (Loc_Prop=Bin3Main.data[Bin3Main.data$Bin3_Acres>=Dev_Size,1]) > if (BinNumber==4) > (Loc_Prop=Bin4Main.data[Bin4Main.data$Bin4_Acres>=Dev_Size,1]) > if (BinNumber==5) > (Loc_Prop=Bin5Main.data[Bin5Main.data$Bin5_Acres>=Dev_Size,1]) > if (BinNumber==6) > (Loc_Prop=Bin6Main.data[Bin6Main.data$Bin6_Acres>=Dev_Size,1]) > if (BinNumber==7) > (Loc_Prop=Bin7Main.data[Bin7Main.data$Bin7_Acres>=Dev_Size,1]) > if (BinNumber==8) > (Loc_Prop=Bin8Main.data[Bin8Main.data$Bin8_Acres>=Dev_Size,1]) > if (BinNumber==9) > (Loc_Prop=Bin9Main.data[Bin9Main.data$Bin9_Acres>=Dev_Size,1]) > if (BinNumber==10) > (Loc_Prop=Bin10Main.data[Bin10Main.data$Bin10_Acres>=Dev_Size,1]) > > I hope this question is clear. I have tried a number of different lines of > code but get the same error (Numeric (0)) > Cheers, > JR > -- > View this message in context: > http://www.nabble.com/Error-in-table-lookup-tp19316307p19316307.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help@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? ______________________________________________ R-help@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.