jeudi 5 juin 2014

merge extra rows being added R


Vote count:

0




I have two very large dfs (x= 379638 rows and y[routes] = 4103141 rows). I want to merge y into x, and I do this using every common variable between the two dfs. However, despite me using all the variables I can, my merge code is still adding on an extra 5000 rows (merged df = 384586 rows). My code is the default all.x=FALSE.... so unsure of whats happening here, given that I'm using every variable in each df to merge on. Does anyone know what I'm doing incorrectly?


Below are two mini-samples from my two dfs, (just copy and paste into your console to see) plus my code.



df<-merge(x,routes, by=c('hai_dispense_number', 'hai_age', 'sex', 'date_of_claim', 'quantity', 'hai_ddd', 'hai_strength', 'eligibility_end_date', 'hai_atc'))


First df (x)



x<- read.table(header=T, text=" hai_dispense_number sex hai_age eligibility_end_date quantity date_of_claim hai_atc hai_strength hai_ddd
13 PatientHAI0000092 F 42 2011-02-28 9 2010-06-16 N05BA01 2.00 10.0
14 PatientHAI0000092 F 42 2011-02-28 3 2010-06-16 N05CF02 5.00 10.0
41 PatientHAI0000110 F 31 2011-07-31 10 2010-09-09 N05BA12 250.00 1.0
72 PatientHAI0000360 F 58 2014-10-31 30 2010-04-21 N05CF02 10.00 10.0
82 PatientHAI0000360 F 58 2014-10-31 30 2010-07-19 N05CF02 10.00 10.0
111 PatientHAI0000522 M 38 2012-08-31 10 2010-07-06 N05CF01 7.50 7.5
134 PatientHAI0000731 F 28 2010-12-29 7 2010-06-15 N05CF01 7.50 7.5
137 PatientHAI0000731 F 28 2010-12-29 15 2010-08-18 N05BA12 500.00 1.0
139 PatientHAI0000731 F 29 2012-02-12 42 2010-09-10 N05BA12 0.25 1.0
159 PatientHAI0000798 F 41 2011-08-31 14 2010-06-30 N05CF01 7.50 7.5
")


second df (routes)



routes<- read.table(header=T, text="hai_dispense_number sex hai_age quantity date_of_claim hai_atc hai_roa hai_strength hai_ddd eligibility_end_date
1 PatientHAI0217603 F 75 14 2010-04-16 N05BA12 O 0.25 1.00 2016-04-30
2 PatientHAI1614296 F 74 30 2010-04-28 N05CD06 O 1.00 1.00 2015-11-30
3 PatientHAI0408690 F 91 28 2010-04-15 N05BA12 O 0.25 1.00 2013-06-30
4 PatientHAI0050917 M 67 56 2010-04-15 N05BE01 O 10.00 30.00 2020-12-31
5 PatientHAI0143945 M 64 30 2010-04-14 N05BA01 O 5.00 10.00 2010-07-31
8 PatientHAI2149890 M 72 84 2010-04-27 N05BA08 O 1.50 10.00 2011-06-30
10 PatientHAI1903034 F 80 45 2010-04-01 N05CD07 O 20.00 20.00 2020-12-31
11 PatientHAI0205229 F 80 56 2010-04-22 N05CD07 O 20.00 20.00 2020-12-31
13 PatientHAI0317751 F 71 30 2010-04-26 N05CD05 O 0.25 0.25 2016-11-30
14 PatientHAI1986979 M 22 15 2010-04-19 N05BA01 O 10.00 10.00 2012-11-30
")


asked 46 secs ago






Aucun commentaire:

Enregistrer un commentaire