Entering edit mode
3.2 years ago
Vincent Manzanilla
▴
40
Hi,
I would like to keep the line where the ID are the same. I know how to to it in bash nut I would like to succeed with R. I have two files with 500,000 lines and 300,000 lines.
df1 <- data.frame(ID=c(sample(LETTERS,20,replace=FALSE)),A=sample(1:100,20,replace=FALSE),B=sample(100:1000,20,replace=FALSE))
ID A B
1 F 81 337
2 J 14 400
3 B 1 620
4 L 40 326
5 T 86 315
6 D 94 797
7 U 96 309
8 Y 42 939
9 Z 18 397
10 W 8 168
11 R 71 308
12 I 83 591
13 O 67 462
14 C 63 353
15 S 88 362
16 Q 13 917
17 G 58 289
18 P 55 640
19 E 9 218
20 X 59 920
and
df2 <- data.frame(D=sample(1:100,10,replace=FALSE),E=sample(100:1000,10,replace=FALSE), ID=c(sample(LETTERS,10,replace=FALSE)))
D E ID
1 29 551 U
2 33 191 C
3 85 814 Q
4 55 897 D
5 46 527 V
6 57 603 T
7 45 287 K
8 79 409 Z
9 65 243 W
10 90 701 M
I would like to join the two data frames where the column ID are similar.
ID A B D E
T 86 315 57 603
D 94 797 55 897
U 96 309 29 551
Z 18 397 79 409
W 8 168 65 243
C 63 353 33 191
Q 13 917 85 814