s-news
[Top] [All Lists]

Re: Beginner's question: Merging dataset

To: Jindan Zhou <jindan@jindan.homedns.org>
Subject: Re: Beginner's question: Merging dataset
From: Sundar Dorai-Raj <sundar.dorai-raj@pdf.com>
Date: Mon, 13 Dec 2004 13:12:11 -0600
Cc: s-news@lists.biostat.wustl.edu
In-reply-to: <Pine.CYG.4.58.0412131238480.3408@shenzhen>
Organization: PDF Solutions, Inc.
References: <OFFB8EDC80.90B2CF07-ON87256F66.00529C96-87256F66.00531701@npsp.com> <41B9D3A8.80801@uvm.edu> <6.1.0.6.2.20041213104431.0617db90@mailhost.blackmesacapital.com> <Pine.CYG.4.58.0412131238480.3408@shenzhen>
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.4) Gecko/20030624 Netscape/7.1 (ax)

Jindan Zhou wrote:

Hello members!

I need to merge two datasets in the following manner:

The first dataset, mydata, has 6 columns

  SiteID Summ.Per. Year  NO3      Dates          X
1   AL02    Summer 2001 0.86   6/5/2001  8/28/2001
2   AL02      Fall 2001 0.47  8/28/2001 11/27/2001
3   AL02    Winter 2002 0.62 11/27/2001  2/26/2002
....
21   AL10    Winter 1986 0.62 12/3/1985 3/4/1986
22   AL10    Spring 1986 0.73  3/4/1986 6/3/1986
23   AL10    Summer 1986 1.36  6/3/1986 9/2/1986

Notice each SiteID may appear multiple times.

The second dataset, latlong, has 3 columns

  Site.ID Latitude Longitude
1    AL02  30.7905  -87.8497
2    AL10  32.4583  -87.2422
3    AL24  30.4741  -88.1411
...

Each Site.ID will appear exactly one time.

What I need to do is to generate two additional columns in mydata, using
information from latlong, for *each* occurrence of SiteID in mydata.
What is the syntax in S for this job? Will the syntax be different from
R? I have been struggling for the solution since last night without a
clue, so sad!

Thanks for any hint!


Did you look at ?merge?

merge(mydata, latlong, by.x = "SiteID", by.y = "Site.ID")

Should be the same in R.

--sundar



<Prev in Thread] Current Thread [Next in Thread>