-2

I have a first table "results" of size 5313 rows and a second table "Lpp_sans_rss" size 3889 rows. I would like to create a merge between the tables by adding only the second column "lpp_libelle" from the second table in the last column of the first table. My problem is : when i make merge between these two tables, i get "124556" rows. I want to keep the same size of the first table by adding the "libell" of each "lpp_code"

Example of table 1 :

code_acte;lpp_code;count;expected_count;p-value;ROR;drug_margin;event_margin;FDR
 NGQK001 ;985675;3;0.00894810101411811;9.99200722162641e-16;689.196078431372;105;6;2.11945533050936e-16
 DASA006 ;985536;3;0.0159787518109252;9.99200722162641e-16;288.012295081967;9;125;2.11778383576921e-16

Example of table 2 :

lpp_code;lpp_libelle
953082;IMP RES SEPRAFILM 13X15CM 430103 (A56D)
3115092;ENDOPROT CORONAIRE, STENT LIB. ZOTAROLIMUS, MEDTRONIC,RESOLUTE INTEGRITY,3MM.
Brian Tompsett - 汤莱恩
  • 5,438
  • 68
  • 55
  • 126
user41096
  • 1
  • 2

2 Answers2

1

First, look for every lppcode in table1

see what the lpp_libelle is in table2 for that lppcode

put that value in table1 in column 10 in table1

for (i in length(table1[,2])){
 table1[i,10]=as.character(table2[which(table2[,1]==table1[i,2]),2])
}

edit: Ferdi's answer is more elegant.

Xizam
  • 669
  • 6
  • 21
1

The left outer join (or simply left join) described in the following question should solve your problem.

merge(x = results, y = Lpp_sans_rss, by = "ENTERHEREYOURCRITERIA", all.x = TRUE)

How to join (merge) data frames (inner, outer, left, right)?

Community
  • 1
  • 1
Ferdi
  • 530
  • 3
  • 12
  • 23