[R] how do I "relate" tables in R?

From: Jeffrey Moore <jemoore_at_duke.edu>
Date: Sat 11 Feb 2006 - 13:23:26 EST


Hi all,  

I'm new to the list...pretty new at learning to code in R...  

Is there a way to relate 2 different arrays in R?  

Hypothetical example:  

data1
ID z
1 100
2 250
3 75
4 12
5 89  

data2
ID z
1
1
1
1
2
3
4
3
4
5
5
5
etc.  

Goal is to fill column z in data2 with appropriate z-values from data1 that correspond to a given ID.  

I'm looking for something akin to a relational database, or a lookup table in Excel.  

I can construct a simple for-loop (with if else statement) to fill the z-column in data2, but in my case data2 is 150,000 records long, so this approach is not efficient.  

Thanks for any help
Jeff  



Jeffrey Moore, Ph.D.
Postdoctoral Research Scientist
Duke Center for Marine Conservation
Duke University Marine Laboratory
135 Duke Marine Lab Road
Beaufort, NC 28516
Phone: (252) 504-7653
Fax: (252) 504-7689
Email: jemoore@duke.edu
 

        [[alternative HTML version deleted]]



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Sat Feb 11 13:28:48 2006

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:42:27 EST