1

我有几个数据框,例如

>data1
     pearson     fisher      yates  mec
1 0.01141204 0.02857143 0.05777957 2.50
2 0.02609829 0.04761905 0.11203684 2.25
3 0.05280751 0.07619048 0.19670560 2.00
4 0.09742169 0.16666667 0.31998422 1.75
5 0.16754628 0.42857143 0.49015296 1.50
6 0.27332168 0.44444444 0.71500065 1.25
7 0.42919530 1.00000000 1.00000000 1.00
8 0.65790502 1.00000000 0.65790502 0.75
9 1.00000000 1.00000000 0.29184055 0.50

> data2
     pearson     fisher     yates  mec
1 0.02609829 0.04761905 0.1120368 2.25
2 0.05777957 0.20634921 0.2059032 2.50
3 0.11203684 0.24242424 0.3403557 2.25
4 0.19670560 0.52380952 0.5186050 2.00
5 0.31998422 0.52380952 0.7402693 1.75
6 0.49015296 1.00000000 1.0000000 1.50
7 0.71500065 1.00000000 0.7150007 1.25
8 1.00000000 1.00000000 0.4291953 1.00
9 0.65790502 1.00000000 0.6579050 0.75

当我尝试合并这两个数据框时,这是我得到的:

> merge(data1, data2, all=TRUE)
      pearson     fisher      yates  mec
1  0.01141204 0.02857143 0.05777957 2.50
2  0.02609829 0.04761905 0.11203684 2.25
3  0.05280751 0.07619048 0.19670560 2.00
4  0.05777957 0.20634921 0.20590321 2.50
5  0.09742169 0.16666667 0.31998422 1.75
6  0.11203684 0.24242424 0.34035574 2.25
7  0.16754628 0.42857143 0.49015296 1.50
8  0.19670560 0.52380952 0.51860502 2.00
9  0.27332168 0.44444444 0.71500065 1.25
10 0.31998422 0.52380952 0.74026928 1.75
11 0.42919530 1.00000000 1.00000000 1.00
12 0.49015296 1.00000000 1.00000000 1.50
13 0.65790502 1.00000000 0.65790502 0.75
14 0.71500065 1.00000000 0.71500065 1.25
15 1.00000000 1.00000000 0.29184055 0.50
16 1.00000000 1.00000000 0.42919530 1.00

我需要得到 18 行,但我得到了 16 行,我有重复的行,我想将它们保留在数据集中。我怎样才能做到这一点?

4

1 回答 1

2

编辑忽略这个答案。merge给出所需的输出。

rbind()将两个数据框放在一起,将两者的所有行都保留在新数据框中。此外,如果您使用 重新标记您的问题,您可能会得到更多的回复和及时的回复r

首先,将您的两个数据集放入r

data1 = read.table(text = "
 pearson    fisher     yates      mec
 0.01141204 0.02857143 0.05777957 2.50
 0.02609829 0.04761905 0.11203684 2.25
 0.05280751 0.07619048 0.19670560 2.00
 0.09742169 0.16666667 0.31998422 1.75
 0.16754628 0.42857143 0.49015296 1.50
 0.27332168 0.44444444 0.71500065 1.25
 0.42919530 1.00000000 1.00000000 1.00
 0.65790502 1.00000000 0.65790502 0.75
 1.00000000 1.00000000 0.29184055 0.50", sep = "", header = TRUE)

data2 = read.table(text = "
 pearson     fisher     yates  mec
 0.02609829 0.04761905 0.1120368 2.25
 0.05777957 0.20634921 0.2059032 2.50
 0.11203684 0.24242424 0.3403557 2.25
 0.19670560 0.52380952 0.5186050 2.00
 0.31998422 0.52380952 0.7402693 1.75
 0.49015296 1.00000000 1.0000000 1.50
 0.71500065 1.00000000 0.7150007 1.25
 1.00000000 1.00000000 0.4291953 1.00
 0.65790502 1.00000000 0.6579050 0.75", sep = "", header = TRUE)

data.merge = rbind(data1, data2)
于 2012-04-28T09:23:44.057 回答