Re: [R] vlookup in R

From: Sachin J <sachinj.2006_at_yahoo.com>
Date: Mon, 24 Mar 2008 10:30:07 -0700 (PDT)


Thank you all for your help. I will definately go through the suggested document. Thanks again.

Sachin

# Setup the translation map
transMap <- c(A="R", B="R", C="R", D="B", F="B");

# The input data
v3 <- c("A", "C", "D", "F", "A", "C", "B", "B", "B", "B", "A", "D");

# The translated data
v4 <- transMap[v3];

df2 <- data.frame(V3=v3, V4=v4);

I recommend you to read 'An Introduction to R' that comes with any R installation. There is a lot of useful stuff in there; it takes many reads to grasp parts of it but it is worth it if you're going to use R for more than, say, two weeks. You can find it via help.start().

/Henrik

On Mon, Mar 24, 2008 at 8:25 AM, Sachin J <sachinj.2006_at_yahoo.com> wrote:
> Hi Henrique,
>
> This is what I am trying to accomplish:
> I want to read values in V1 and V2 and populate the column V4 with R or B based on the
> values in V3 i.e. if its A,B,C then its R else if D,F then B. You can assume V1, V2 are dataframe1
> and V3, V4 are in dataframe2 (note V4 is empty initially i.e. its a new column).
>
> > df1
> V1V2
> A R
> BR
> CR
> DB
> FB
>
> > df2
>
> V3V4
> AR
> CR
> DB
> FB
> AR
> CR
> BR
> BR
> BR
> BR
> AR
> DB
>
>
>
> Thanks in advance for your help.
>
>
>
>
> ----- Original Message ----
> From: Henrique Dallazuanna <wwwhsd_at_gmail.com>
> To: Sachin J <sachinj.2006_at_yahoo.com>
> Cc: r-help_at_r-project.org
> Sent: Monday, March 24, 2008 10:41:52 AM
> Subject: Re: [R] vlookup in R
>
> I think that merge is what you want:
>
> set.seed(24032008)
> x <- data.frame(ID=sample(10), Value=rnorm(10))
> idx <- sample(5)
> merge(idx, x, by.x=1, by.y=1)
>
> On 24/03/2008, Sachin J <sachinj.2006_at_yahoo.com> wrote:
> > Hi,
>
> >
> > Is there are function similar to excel vlookup in R. Please let me know.
> >
>
> > Thanks,
> > Sachin
> >
> >
> > ____________________________________________________________________________________
> >
> >
> > [[alternative HTML version deleted]]
> >
> > ______________________________________________
>
> > 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.
> >
>
>
>
> --
> Henrique Dallazuanna
> Curitiba-Paraná-Brasil
> 25° 25' 40" S 49° 16' 22" O
>
>
> ____________________________________________________________________________________
>
>
> [[alternative HTML version deleted]]
>
>
> ______________________________________________
> 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.
>
>


        [[alternative HTML version deleted]]



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. Received on Mon 24 Mar 2008 - 17:40:45 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 24 Mar 2008 - 18:30:24 GMT.

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

list of date sections of archive