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
|