Hi Arun,

This is excellent and elegant.  I thought there had to be a relatively simple way to do this.  Thank you very much.
Jeremy

From: arun kirshna [via R] [mailto:ml-node+s789695n4664328h81@n4.nabble.com]
Sent: Monday, April 15, 2013 10:34 PM
To: Crowley, Jeremy
Subject: Re: matching multiple fields from a matrix

HI,
May be this helps:
dat1<- read.table(text="
site1 depth1 year1 site2 depth2 year2
10 30 1860 NA NA NA
NA NA NA 50 30 1860
10 20 1850  11 20 1850
11 25 1950  12 25 1960
10 NA 1870  12 30 1960
11 25 1880  15 22  1890
14 22 1890  14 25 1880
",sep="",header=TRUE,stringsAsFactors=FALSE)
 res<-merge(dat1[,1:3],dat1[,4:6],by.x=c("depth1","year1"),by.y=c("depth2","year2"))
 names(res)[1:2]<- gsub("\\d+<file:///\\d+>","",names(res))[1:2]
 na.omit(res)
#  depth year site1 site2
#1    20 1850    10    11
#2    22 1890    14    15
#3    25 1880    11    14
#4    30 1860    10    50
A.K.




----- Original Message -----
From: jercrowley <[hidden email]</user/SendEmail.jtp?type=node&node=4664328&i=0>>
To: [hidden email]</user/SendEmail.jtp?type=node&node=4664328&i=1>
Cc:
Sent: Monday, April 15, 2013 5:07 PM
Subject: [R] matching multiple fields from a matrix

I have been trying many ways to match 2 separate fields in a matrix.  Here is
a simplified version of the matrix:

site1    depth1    year1    site2    depth2    year2
10    30    1860    NA    NA    NA
NA    NA    NA    50    30    1860

Basically I am trying to identify the sites which have a common year and
depth from 2 datasets.  What I would like to do is match all of the year1
field to year2 field and the depth1 field and to depth2 field.  Then I would
like to output site1, site2, depth, and year.

I have been trying if loops, which(), isTRUE(), etc. but I have not come up
with anything that works.

Any help would be greatly appreciated.

Jeremy



--
View this message in context: http://r.789695.n4.nabble.com/matching-multiple-fields-from-a-matrix-tp4664309.html
Sent from the R help mailing list archive at Nabble.com.

______________________________________________
[hidden email]</user/SendEmail.jtp?type=node&node=4664328&i=2> 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.


______________________________________________
[hidden email]</user/SendEmail.jtp?type=node&node=4664328&i=3> 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.

________________________________
If you reply to this email, your message will be added to the discussion below:
http://r.789695.n4.nabble.com/matching-multiple-fields-from-a-matrix-tp4664309p4664328.html
To unsubscribe from matching multiple fields from a matrix, click here<http://r.789695.n4.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=4664309&code=amNyb3dsZXkyQG10ZWNoLmVkdXw0NjY0MzA5fDEwMzU2Mjk5ODI=>.
NAML<http://r.789695.n4.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>




--
View this message in context: http://r.789695.n4.nabble.com/matching-multiple-fields-from-a-matrix-tp4664309p4664376.html
Sent from the R help mailing list archive at Nabble.com.
	[[alternative HTML version deleted]]

