I am trying to get involved in two grounds. There are many setkeys in the R base and those repeated entries as an example
& gt; DT1 ID Month of the year 1 IL January 3 2013 1 IL January 3 2014 1 IL January 3 2014 1 IL January 10 2014 1 IL January 11 2013 1 IL January 30 2013 1 IL January 30 2013 1 IL Feb 2 2013 1 IL February 2 2014 1 IL Feb 3 2013 1 IL Feb 3 2014 & gt; DT 2 State Month Day Year TAh IL Jan 1 2013 13 IL Jan 2 2013 1 9 IL Jan 3rd 2013 22 IL January 4 2013 23 IL January 5 2013 26 IL January 6 2013 24 IL January 7 2013 27 IL January 8 2013 32 IL January 9 2013 36 ... ... ... ... .... ... ... IL 31 December 2013 33
I would like to add the "TAV" values of DT2 to the respective dates in DT2. For example, all entries in DT1 will be held on January 3 2013 will require a further 13 in an additional column.
I created the following setkey (DT1, state, month, day, year)
and the same DT2 for an integrated operation DT1 [DT2, nomatch = 0, Permission cartesian = TRUE
but it does not work
Just a friend's help with this (That could not get a good stack overflow answer), so I thought this question requires a more "toy" answer.
Here are some simple data tables with a mismatch key:
dt1 < - data.table (a = letter [1: 5], b = letters [1: 5], c = 1: 5) dt2 & lt; - data.table (c = LETTERS [c] (1: 4,6)], B = letter [1: 5], A = 6: 10)
And many more here The merge options are:
merge (dt1, dt2, by.x = c ("a", "b"), by.y = c ("c", "b")) #inter mergence merge (dt1, dt2, by x = c ("a", "b"), by.y = c ("c", "b"), all = t) # external joint setkey (dt1, A, B) DT 2 [DT1] # Left (DT1 is the "left" table) DT1 [DT2] #Wright Join (if DT1 "left" table) (DT 2, C, B) DT2 [DT1] Is)
No comments:
Post a Comment