[R] merging two dataframes

Petr PIKAL petr.pikal at precheza.cz
Mon Oct 24 15:05:26 CEST 2011


Hi

 
> Hello
> 
> I am a new user of R and I need help to merge two large datasets about
> stocks with different number of rows and columns.
> Both have 2 variable(column) that are have same values ("name" and 
"date1),
> but they are not in same order and "data3" contains much more 
observations.
> In the "data" have dividend information about each stock, and in the 
second
> there are information about the stock prices.
> 
> I tried to use this function:
> data4<-merge(data,data3, by="name","date1")

Does

data4<-merge(data,data3, by=c("name","date1"), all=T)

do what you want?

I think merge help page is quite explanatory and you shall look at it.

Regards
Petr


> 
> But it does not work. 
> 
> "data 3" has more than 800.000 observations of daily stock prices for 
each
> stock, and "data" has only 14.000, so i want to make a function that 
merge
> the two datasets to a new dataset with the same length as "data", and 
also
> include all the variables in "data3" where "name" (example: Statoil) and
> "date1"(example:31.12.2000)  is the same in both sets.
> 
> Can someone please help me?
> 
> Regards
> 
> 
> 
> --
> View this message in context: http://r.789695.n4.nabble.com/merging-two-
> dataframes-tp3932869p3932869.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