The merge function seems perfect for your problem. If you can't get it to work, 
the problem may be in the data you are working with, which you have not 
supplied (read the posting guide, and use the head and dput functions to make 
your example small and reproducible).
One common mistake by beginners occurs in the data import stage, when it is 
easy to end up with factors instead of character strings or Date values. You 
can use the str function to see what data types are in your named objects. If 
this has already occurred, use something like as.character to fix it, e.g.

data$date <- as.character( data$date )

Factors are useful, but not for merging between different data frames.
---------------------------------------------------------------------------
Jeff Newmiller The ..... ..... Go Live...
DCN:<jdnew...@dcn.davis.ca.us> Basics: ##.#. ##.#. Live Go...
Live: OO#.. Dead: OO#.. Playing
Research Engineer (Solar/Batteries O.O#. #.O#. with
/Software/Embedded Controllers) .OO#. .OO#. rocks...1k
--------------------------------------------------------------------------- 
Sent from my phone. Please excuse my brevity.

dividend <stap...@gmail.com> wrote:

Thank you Petr!

I have read on the merge help page, but I cant figure out how to write this
function.
When I use your function it includes all data from "data3", but all columns
in "data" has "NA"(without "name" and "date". I hoped to keep these values
to.

I try to explain it more precise:
In "data" with 14000 observations about company name, date, size of dividend
etc.
In "data3" there are 800000 daily observations of the stockprices for each
company listed:

name date div
statoil 17.05.2000 5
statoil 18.05.2001 6
........ .............. ...
Yara 17.05.2000 10
etc

I want to get the stockprice for statoil, yara etc from "data3", and merge
it into a new data like this:

name date div price
statoil 17.05.2000 5 120
statoil 18.05.2001 6 130
........ .............. ...
Yara 17.05.2000 10 200
etc

And also keep the rest of the columns from both datasets. 

name date div price industry secid 
etc
statoil 17.05.2000 5 120 ....... ..... 
...
statoil 18.05.2001 6 130 ....... 
...... .... 
........ .............. ...
Yara 17.05.2000 10 200 ..... ...... 
...
etc

Using the first function i get this result:

name date div price industry secid 
etc
statoil 17.05.2000 NA 120 ....... ..... 
...
statoil 18.05.2001 NA 130 ....... 
...... .... 
........ .............. ...
Yara 17.05.2000 NA 200 ..... ...... 
...

Hope you understand what i want to do.

Thanks again, I really appreciate it!
etc

--
View this message in context: 
http://r.789695.n4.nabble.com/merging-two-dataframes-tp3932869p3933101.html
Sent from the R help mailing list archive at Nabble.com.

_____________________________________________

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.


        [[alternative HTML version deleted]]

______________________________________________
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