Skip to content
Back to formatted view

Raw Message

Message-ID: <381E1F56-4863-4490-B714-7B7F6E3B9C2E@xs4all.nl>
Date: 2012-02-28T16:24:06Z
From: Berend Hasselman
Subject: vlookup type function
In-Reply-To: <CAAqiDBztCkrAGMF+rxBqA2EokYGFHVWAZ6A47ESy74+Vn-qdOA@mail.gmail.com>

On 28-02-2012, at 16:32, Priyan Fernando wrote:

> Hi
> 
> I''m looking for an Excel Vlookup type function in R.
> 
> Example:
> list <- c(1,2,3,4,5,6,7)
> base <- c(2.2,3,5.2)
> 
> What I want is, for each number in base, the highest value in list,
> which is equal to or less than the number in base
> 
> So the results would be:
> 
> base         list
> 2.2  ------> 2
> 3    ------> 3
> 5.2  ------>  5

Don't use "list" as an object name. It is a standard R function.

vlist <- c(1,2,3,4,5,6,7)
base <- c(2.2,3,5.2)

findInterval(base, vlist)

Berend