我有两个数据框
df1
Gate Set
1 1 PIP D04 LMI1 975
2 6 PIP D06 LMI1 363
3 Time PIP d08 LMI1 wk7 539
和
df2
ID Weeks
1 d01 6
2 d04 8
3 d06 9
4 d08 19
我要合并的。如您所见,df2 $ ID中的字符串作为df1 $ Set中字符串的一部分返回。 我想以匹配字符串并将df2 $ Weeks中的相应值附加在新列中的方式来连接两个数据框。像这样:
Gate Set Weeks
1 1 PIP D04 LMI1 975 8
2 6 PIP D06 LMI1 363 9
3 Time PIP d08 LMI1 wk7 539 19
我尝试了一种方法,在该方法中,我使用了一个循环功能,该功能将无法使用的字符串分割开。
test_day <- unlist(strsplit(df[,2][1], ""))
test_day <- paste(test_day[c(5:7)], collapse = "")
编辑:此处两个数据帧的dput输出:
df1:
structure(list(Gate = structure(c(1L, 24L, 1L, 23L, 1L, 13L,
1L, 21L, 1L, 20L, 1L, 3L, 4L, 5L, 1L, 19L, 1L, 9L, 1L, 2L, 1L,
10L, 14L, 15L, 22L, 1L, 12L, 16L, 17L, 18L, 1L, 6L, 7L, 8L, 1L,
11L, 1L, 24L, 1L, 23L, 1L, 13L, 1L, 21L, 1L, 20L, 1L, 3L, 4L,
5L, 1L, 19L, 1L, 9L, 1L, 2L, 1L, 10L, 14L, 15L, 22L, 1L, 12L,
16L, 17L, 18L, 1L, 6L, 7L, 8L, 1L, 11L, 1L, 24L, 1L, 23L, 1L,
13L, 1L, 21L, 1L, 20L, 1L, 3L, 4L, 5L, 1L, 19L, 1L, 9L, 1L, 2L,
1L, 10L, 14L, 15L, 22L, 1L, 12L, 16L, 17L, 18L, 1L, 6L, 7L, 8L,
1L, 11L, 1L, 24L, 1L, 23L, 1L, 13L, 1L, 21L, 1L, 20L, 1L, 3L,
4L, 5L, 1L, 19L, 1L, 9L, 1L, 2L, 1L, 10L, 14L, 15L, 22L, 1L,
12L, 16L, 17L, 18L, 1L, 6L, 7L, 8L, 1L, 11L, 1L, 24L, 1L, 23L,
1L, 13L, 1L, 21L, 1L, 20L, 1L, 3L, 4L, 5L, 1L, 19L, 1L, 9L, 1L,
2L, 1L, 10L, 14L, 15L, 22L, 1L, 12L, 16L, 17L, 18L, 1L, 6L, 7L,
8L, 1L, 11L, 1L, 24L, 1L, 23L, 1L, 13L, 1L, 21L, 1L, 20L, 1L,
3L, 4L, 5L, 1L, 19L, 1L, 9L, 1L, 2L, 1L, 10L, 14L, 15L, 22L,
1L, 12L, 16L, 17L, 18L, 1L, 6L, 7L, 8L, 1L, 11L, 1L, 24L, 1L,
23L, 1L, 13L, 1L, 21L, 1L, 20L, 1L, 3L, 4L, 5L, 1L, 19L, 1L,
9L, 1L, 2L, 1L, 10L, 14L, 15L, 22L, 1L, 12L, 16L, 17L, 18L, 1L,
6L, 7L, 8L, 1L, 11L, 1L, 24L, 1L, 23L, 1L, 13L, 1L, 21L, 1L,
20L, 1L, 3L, 4L, 5L, 1L, 19L, 1L, 9L, 1L, 2L, 1L, 10L, 14L, 15L,
22L, 1L, 12L, 16L, 17L, 18L, 1L, 6L, 7L, 8L, 1L, 11L, 1L, 24L,
1L, 23L, 1L, 13L, 1L, 21L, 1L, 20L, 1L, 3L, 4L, 5L, 1L, 19L,
1L, 9L, 1L, 2L, 1L, 10L, 14L, 15L, 22L, 1L, 12L, 16L, 17L, 18L,
1L, 6L, 7L, 8L, 1L, 11L, 1L, 24L, 1L, 23L, 1L, 13L, 1L, 21L,
1L, 20L, 1L, 3L, 4L, 5L, 1L, 19L, 1L, 9L, 1L, 2L, 1L, 10L, 14L,
15L, 22L, 1L, 12L, 16L, 17L, 18L, 1L, 6L, 7L, 8L, 1L, 11L, 1L,
24L, 1L, 23L, 1L, 13L, 1L, 21L, 1L, 20L, 1L, 3L, 4L, 5L, 1L,
19L, 1L, 9L, 1L, 2L, 1L, 10L, 14L, 15L, 22L, 1L, 12L, 16L, 17L,
18L, 1L, 6L, 7L, 8L, 1L, 11L, 1L, 24L, 1L, 23L, 1L, 13L, 1L,
21L, 1L, 20L, 1L, 3L, 4L, 5L, 1L, 19L, 1L, 9L, 1L, 2L, 1L, 10L,
14L, 15L, 22L, 1L, 12L, 16L, 17L, 18L, 1L, 6L, 7L, 8L, 1L, 11L,
1L, 24L, 1L, 23L, 1L, 13L, 1L, 21L, 1L, 20L, 1L, 3L, 4L, 5L,
1L, 19L, 1L, 9L, 1L, 2L, 1L, 10L, 14L, 15L, 22L, 1L, 12L, 16L,
17L, 18L, 1L, 6L, 7L, 8L, 1L, 11L, 1L, 24L, 1L, 23L, 1L, 13L,
1L, 21L, 1L, 20L, 1L, 3L, 4L, 5L, 1L, 19L, 1L, 9L, 1L, 2L, 1L,
10L, 14L, 15L, 22L, 1L, 12L, 16L, 17L, 18L, 1L, 6L, 7L, 8L, 1L,
11L, 1L, 24L, 1L, 23L, 1L, 13L, 1L, 21L, 1L, 20L, 1L, 3L, 4L,
5L, 1L, 19L, 1L, 9L, 1L, 2L, 1L, 10L, 14L, 15L, 22L, 1L, 12L,
16L, 17L, 18L, 1L, 6L, 7L, 8L, 1L, 11L, 1L, 24L, 1L, 23L, 1L,
13L, 1L, 21L, 1L, 20L, 1L, 3L, 4L, 5L, 1L, 19L, 1L, 9L, 1L, 2L,
1L, 10L, 14L, 15L, 22L, 1L, 12L, 16L, 17L, 18L, 1L, 6L, 7L, 8L,
1L, 11L, 1L, 24L, 1L, 23L, 1L, 13L, 1L, 21L, 1L, 20L, 1L, 3L,
4L, 5L, 1L, 19L, 1L, 9L, 1L, 2L, 1L, 10L, 14L, 15L, 22L, 1L,
12L, 16L, 17L, 18L, 1L, 6L, 7L, 8L, 1L, 11L, 1L, 24L, 1L, 23L,
1L, 13L, 1L, 21L, 1L, 20L, 1L, 3L, 4L, 5L, 1L, 19L, 1L, 9L, 1L,
2L, 1L, 10L, 14L, 15L, 22L, 1L, 12L, 16L, 17L, 18L, 1L, 6L, 7L,
8L, 1L, 11L, 1L, 24L, 1L, 23L, 1L, 13L, 1L, 21L, 1L, 20L, 1L,
3L, 4L, 5L, 1L, 19L, 1L, 9L, 1L, 2L, 1L, 10L, 14L, 15L, 22L,
1L, 12L, 16L, 17L, 18L, 1L, 6L, 7L, 8L, 1L, 11L, 1L, 24L, 1L,
23L, 1L, 13L, 1L, 21L, 1L, 20L, 1L, 3L, 4L, 5L, 1L, 19L, 1L,
9L, 1L, 2L, 1L, 10L, 14L, 15L, 22L, 1L, 12L, 16L, 17L, 18L, 1L,
6L, 7L, 8L, 1L, 11L, 1L, 24L, 1L, 23L, 1L, 13L, 1L, 21L, 1L,
20L, 1L, 3L, 4L, 5L, 1L, 19L, 1L, 9L, 1L, 2L, 1L, 10L, 14L, 15L,
22L, 1L, 12L, 16L, 17L, 18L, 1L, 6L, 7L, 8L, 1L, 11L, 1L, 24L,
1L, 23L, 1L, 13L, 1L, 21L, 1L, 20L, 1L, 3L, 4L, 5L, 1L, 19L,
1L, 9L, 1L, 2L, 1L, 10L, 14L, 15L, 22L, 1L, 12L, 16L, 17L, 18L,
1L, 6L, 7L, 8L, 1L, 11L, 1L, 24L, 1L, 23L, 1L, 13L, 1L, 21L,
1L, 20L, 1L, 3L, 4L, 5L, 1L, 19L, 1L, 9L, 1L, 2L, 1L, 10L, 14L,
15L, 22L, 1L, 12L, 16L, 17L, 18L, 1L, 6L, 7L, 8L, 1L, 11L, 1L,
24L, 1L, 23L, 1L, 13L, 1L, 21L, 1L, 20L, 1L, 3L, 4L, 5L, 1L,
19L, 1L, 9L, 1L, 2L, 1L, 10L, 14L, 15L, 22L, 1L, 12L, 16L, 17L,
18L, 1L, 6L, 7L, 8L, 1L, 11L, 1L, 24L, 1L, 23L, 1L, 13L, 1L,
21L, 1L, 20L, 1L, 3L, 4L, 5L, 1L, 19L, 1L, 9L, 1L, 2L, 1L, 10L,
14L, 15L, 22L, 1L, 12L, 16L, 17L, 18L, 1L, 6L, 7L, 8L, 1L, 11L,
1L, 24L, 1L, 23L, 1L, 13L, 1L, 21L, 1L, 20L, 1L, 3L, 4L, 5L,
1L, 19L, 1L, 9L, 1L, 2L, 1L, 10L, 14L, 15L, 22L, 1L, 12L, 16L,
17L, 18L, 1L, 6L, 7L, 8L, 1L, 11L, 1L, 24L, 1L, 23L, 1L, 13L,
1L, 21L, 1L, 20L, 1L, 3L, 4L, 5L, 1L, 19L, 1L, 9L, 1L, 2L, 1L,
10L, 14L, 15L, 22L, 1L, 12L, 16L, 17L, 18L, 1L, 6L, 7L, 8L, 1L,
11L), .Label = c("All", "B cell", "CD14+ CD16+", "CD14++ CD16-",
"CD14++ CD16+", "CD16-CD56+ NK", "CD16-CD56+ NK bright", "CD16+CD56+ NKdim",
"CD3-", "CD3+CD56- Tcells", "CD4+CD25++", "CD4+CD8- Tc", "CD45+",
"CD56+CD3- NK cells", "CD56+CD3+ NKT cells", "CD8-CD4- Tc", "CD8+CD4- Tc",
"CD8+CD4+ Tc", "Lymphocytes", "Monocytes", "Neutrophils", "non NK(T) cells",
"Singlets", "Time"), class = "factor"), Set = structure(c(2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 5L, 5L, 5L, 5L, 5L,
5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L,
5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 6L,
6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L,
6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L,
6L, 6L, 6L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L,
7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L,
7L, 7L, 7L, 7L, 7L, 7L, 7L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L,
8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L,
8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 9L, 9L, 9L, 9L, 9L,
9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L,
9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 10L,
10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L,
10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L,
10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L,
10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L,
10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L,
10L, 10L, 10L, 10L, 10L, 10L, 11L, 11L, 11L, 11L, 11L, 11L, 11L,
11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L,
11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L,
11L, 11L, 11L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L,
12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L,
12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L,
13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L,
13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L,
13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L,
14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L,
14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 15L, 15L,
15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L,
15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L,
15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 17L, 17L, 17L, 17L, 17L,
17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L,
17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L,
17L, 17L, 17L, 17L, 17L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L,
18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L,
18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L,
18L, 18L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L,
19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L,
19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 20L,
20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L,
20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L,
20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 21L, 21L, 21L, 21L,
21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L,
21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L,
21L, 21L, 21L, 21L, 21L, 21L, 22L, 22L, 22L, 22L, 22L, 22L, 22L,
22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L,
22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L,
22L, 22L, 22L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L,
23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L,
23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L,
24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L,
24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L,
24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L, 25L, 25L, 25L,
25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L,
25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L,
25L, 25L, 25L, 25L, 25L, 25L, 25L, 26L, 26L, 26L, 26L, 26L, 26L,
26L, 26L, 26L, 26L, 26L, 26L, 26L, 26L, 26L, 26L, 26L, 26L, 26L,
26L, 26L, 26L, 26L, 26L, 26L, 26L, 26L, 26L, 26L, 26L, 26L, 26L,
26L, 26L, 26L, 26L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L,
16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L,
16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L,
16L), .Label = c("d31 wk 9.5 LMI1 168", "PIP D04 LMI1 975", "PIP D06 LMI1 363",
"PIP d08 LMI1 wk7 539", "PIP d10 LMI1 wk10.4 540", "PIP D12 DPMC LMI1 789",
"PIP d13 6.2wk LMI1", "PIP D15 LMI1 316", "PIP D19 LMI1 319",
"PIP D21 LMI1 518", "PIP D22 LMI1 519", "PIP D23 LMI1 520", "PIP D26 LMI1 912",
"PIP d39 wk 9.2 LMI1 094", "PIP d46 wk 8 LMI1 550", "d56 LMI1 14.3wk 2018-06-19 771",
"PIP D05P LMI1 981", "PIP D07 LMI1 367", "PIP d11 LMI1 wk14 541",
"PIP d14 LMI1 14wk 136", "PIP D18 LMI1 318", "PIP D20 LMI1 321",
"PIP D24 LMI1 521", "PIP D25 LMI1 527", "PIP D27 LMI1 911", "PIP d47 wk 15.3 LMI1 554"
), class = "factor")), .Names = c("Gate", "Set"), class = "data.frame", row.names = c(NA,
-972L))
和df2:
structure(list(ID = structure(c(1L, 2L, 3L, 4L, 6L, 5L, 7L, 8L,
9L, 10L, 11L, 19L, 20L, 21L, 22L, 23L, 24L, 25L, 26L, 27L, 28L,
29L, 30L, 31L, 32L, 33L, 34L, 35L, 36L, 37L, 38L, 39L, 40L, 41L,
42L, 43L, 44L, 45L, 46L, 47L, 48L, 49L, 50L, 51L, 52L, 53L, 54L,
55L, 56L, 57L, 58L, 59L, 60L, 61L, 62L, 63L, 64L, 65L, 66L, 67L,
68L, 69L, 70L, 71L, 72L, 73L, 74L, 75L, 76L, 77L, 78L, 79L, 80L,
81L, 82L, 83L, 84L, 85L, 86L, 87L, 88L, 89L, 90L, 91L, 92L, 93L,
94L, 95L, 96L, 97L, 98L, 99L, 100L, 101L, 102L, 103L, 104L, 105L,
106L, 107L, 12L, 13L, 14L, 15L, 16L, 17L, 18L), .Label = c("d01",
"d02", "d03", "d04", "d05B", "d05P", "d06", "d07", "d08", "d09",
"d10", "d100", "d101", "d102", "d103", "d104", "d105", "d106",
"d11", "d12", "d13", "d14", "d15", "d16", "d17", "d18", "d19",
"d20", "d21", "d22", "d23", "d24", "d25", "d26", "d27", "d28",
"d29", "d30", "d31", "d32", "d33", "d34", "d35", "d36", "d37",
"d38", "d39", "d40", "d41", "d42", "d43", "d44", "d45", "d46",
"d47", "d48", "d49", "d50", "d51", "d52", "d53", "d54", "d55",
"d56", "d57", "d58", "d59", "d60", "d61", "d62", "d63", "d64",
"d65", "d66", "d67", "d68", "d69", "d70", "d71", "d72", "d73",
"d74", "d75", "d76", "d77", "d78", "d79", "d80", "d81", "d82",
"d83", "d84", "d85", "d86", "d87", "d88", "d89", "d90", "d91",
"d92", "d93", "d94", "d95", "d96", "d97", "d98", "d99"), class = "factor"),
Weeks = c(6.7, 8.4, 6.3, 8, 15.9, 15.9, 8.9, 16.3, 7, 8,
10.6, 14, 10, 6.3, 14, 6.9, NA, 16, 16, 7.3, 13, 5, 6, 7,
14.4, 14.4, 7, 13.4, 6, 6, 14.3, 9.7, 14.3, 5.7, 7.3, 8.1,
6, 15.4, 7.4, 9.3, 13.6, 5.9, 5.4, 7.7, 13, 13.3, 8, 15.4,
16, 7, 14.1, 6.7, 13.1, 6, 6, 10.6, 14.4, 5, 6.7, 7.9, 12.4,
7.6, 14, 6, 13.6, 13.6, 7.3, 9, 16, 16.3, 4.7, 5, 5.9, 6,
8, 11.6, 6, 6.4, 8.1, 8.1, 7, 7.3, 9.6, 13.3, 6, 5, 11, 11,
17, 6.3, 8.3, 11.3, 14.3, 4.9, 5.9, 8.4, 5.4, 7, 15.6, 6.1,
4.7, 10.9, 10.4, 6, 7.3, 8.9, 11)), .Names = c("ID", "Weeks"
), class = "data.frame", row.names = c(NA, -107L))
答案 0 :(得分:0)
使用IMAGE_FILE_LARGE_ADDRESS_AWARE
data.table
数据
df1[, ID := tolower(gsub(".+([dD]\\d{2}).+", "\\1", Set))]
df1
# Gate Set ID
#1: 1 PIP D04 LMI1 975 d04
#2: 6 PIP D06 LMI1 363 d06
#3: Time PIP d08 LMI1 wk7 539 d08
df2[df1, on = .(ID)]
# ID Weeks Gate Set
#1: d04 8 1 PIP D04 LMI1 975
#2: d06 9 6 PIP D06 LMI1 363
#3: d08 19 Time PIP d08 LMI1 wk7 539
# with merge()
merge(df1, df2, by = "ID")
答案 1 :(得分:0)
一个选择是使用库regex_left_join
中的fuzzyjoin
,该库允许合并列条目的正则表达式匹配项上的数据集:
library(fuzzyjoin)
library(dplyr)
regex_left_join(df1, df2, by = c("Set" = "ID"), ignore_case = T) %>%
select(-ID)
# Gate Set Weeks
#1 1 PIP D04 LMI1 975 8
#2 6 PIP D06 LMI1 363 9
#3 Time PIP d08 LMI1 wk7 539 19
df1 <- read.table(text =
" Gate Set
1 1 'PIP D04 LMI1 975'
2 6 'PIP D06 LMI1 363'
3 Time 'PIP d08 LMI1 wk7 539'", header = T)
df2 <- read.table(text =
" ID Weeks
1 d01 6
2 d04 8
3 d06 9
4 d08 19", header = T)
使用更新的样本数据
regex_left_join(df1, df2, by = c("Set" = "ID"), ignore_case = T) %>%
select(-ID)
Gate Set Weeks
1 All PIP D04 LMI1 975 8.0
2 Time PIP D04 LMI1 975 8.0
3 All PIP D04 LMI1 975 8.0
4 Singlets PIP D04 LMI1 975 8.0
5 All PIP D04 LMI1 975 8.0
6 CD45+ PIP D04 LMI1 975 8.0
7 All PIP D04 LMI1 975 8.0
8 Neutrophils PIP D04 LMI1 975 8.0
9 All PIP D04 LMI1 975 8.0
10 Monocytes PIP D04 LMI1 975 8.0
....