raghu wrote:
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?

I think all this can be accomplished with merge. Can you give reproducible examples as the posting guide suggests?

Use read.table to read in your data into R objects, then use ?dput to give us the exact copies of the objects (probably data.frames by your example), and what output you want to have. Being precise with the classes of objects you're working with is key, and ?dput is a great way to make sure we have the same objects as you.

Another tip is common terminology. For instance, `vlookup` is not a term used in R, and many people will not know what it means.

This way, everything is reproducible for us, and we can offer suggestions and show you what the exact output will be. In short, making sure everyone is on the same page goes a long way when getting help from a mailing list.

______________________________________________
R-help@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.

Reply via email to