Skip to content
Prev 248592 / 398503 Next

applying a set of rules to each row

On Jan 27, 2011, at 8:45 AM, KATSCHKE, ADRIAN CIV DFAS wrote:

            
It's nice of Dennis to reorganize your logic, although if I sent you  
something privately I would expect it to remain private. An alternate  
approach to selecting a value based on a number falling into a range  
(bypassing the creation of a factor)  is available using findInterval:

multiplier <- c(55,30,60,20,65,5)[
                           findinterval(ageFedStart, c(0, 25, 30, 40,  
45, 60, 100) ) ]

You are implicitly creating an index lookup into the initial vector of  
values. This is a very familiar operation to Excel users who often  
resort to VLOOKUP or HLOOKUP. Unlike cut, the default for findInterval  
is for the right side of the interval to be open which is the case here.