[R] Adding two files into one and vlookup

Peter Alspach Peter.Alspach at plantandfood.co.nz
Wed Jul 7 01:10:05 CEST 2010


Tena koe 

Why is merge() not helpful?  From your description I would imagine

merge(file1, file2, by='Date')

would do what you require.

HTH ....

Peter Alspach

> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
> project.org] On Behalf Of raghu
> Sent: Wednesday, 7 July 2010 10:18 a.m.
> To: r-help at r-project.org
> Subject: [R] Adding two files into one and vlookup
> 
> 
> I have two files with dates and prices in each. The number of rows in
> each of
> them will differ. How do I create a new file which contains data from
> both
> these files? Cbind and merge are not helpful. For cbind because the
> rows are
> not the same replication occurs. Also if I have similar data how do I
> write
> a vlookup kind of function? I am giving an example below:
> Say Price1 file contains the following:
> Date             Price
> 2/3/2010       134.00
> 3/3/2010       133.90
> 4/3/2010       135.55
> 
> And say price2 contains the following:
> Date              Price
> 2/3/2010        2300
> 3/3/2010        3200
> 4/3/2010        1800
> 5/3/2010        1900
> 
> I want to take both these data together in a single file, and take the
> smaller vector (or matrix or dataframe??..i am new to R and still
> confused
> with the various objects) which is file1 (because it contains fewer
> rows )
> and vlookup prices in the second file basedon the dates on file1 and
> write
> three columns (date, price from 1 and price from2) in a new file. How
> do i
> do this please?
> 
> Many thanks...
> R
> --
> View this message in context: http://r.789695.n4.nabble.com/Adding-two-
> files-into-one-and-vlookup-tp2280277p2280277.html
> Sent from the R help mailing list archive at Nabble.com.
> 
> ______________________________________________
> 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.



More information about the R-help mailing list