[R] merging two dataframes

dividend stapnes at gmail.com
Mon Oct 24 15:28:55 CEST 2011


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.



More information about the R-help mailing list