这里有一个 dplyr
的选项,可以基于两个(或更多)列标记重复项。在本例中,是根据 ric
和 date
列进行标记:
df <- data_frame(ric = c('S1A.PA', 'ABC.PA', 'EFG.PA', 'S1A.PA', 'ABC.PA', 'EFG.PA'),
date = c('2011-06-30 20:00:00', '2011-07-03 20:00:00', '2011-07-04 20:00:00', '2011-07-05 20:00:00', '2011-07-03 20:00:00', '2011-07-04 20:00:00'),
open = c(23.7, 24.31, 24.495, 24.23, 24.31, 24.495))
df %>%
group_by(ric, date) %>%
mutate(dupe = n()>1)
# A tibble: 6 x 4
# Groups: ric, date [4]
ric date open dupe
<chr> <chr> <dbl> <lgl>
1 S1A.PA 2011-06-30 20:00:00 23.7 FALSE
2 ABC.PA 2011-07-03 20:00:00 24.3 TRUE
3 EFG.PA 2011-07-04 20:00:00 24.5 TRUE
4 S1A.PA 2011-07-05 20:00:00 24.2 FALSE
5 ABC.PA 2011-07-03 20:00:00 24.3 TRUE
6 EFG.PA 2011-07-04 20:00:00 24.5 TRUE
RIC 日期
107515 7541.T 2011-06-30 20:00:00 107516 7541.T 2011-07-03 20:00:00 107517 7541.T 2011-07-04 20:00:00 107518 7541.T 2011-07-05 20:00:00 107519 7541.T 2011-07-06 20:00:00 107520 7541.T 2011-07-07 20:00:00 107521 7541.T 2011-07-10 20:00:00 107522 7541.T 2011-07-11 20:00:00 107523 7541.T 2011-07-12 20:00:00 107524 7541.T 2011-07-13 20:00:00 107525 7541.T 2011-07-14 20:00:00 107526 7541.T 2011-07-18 20:00:00 - user802231TRUE
,而不是如果数字被倒置。换句话说:如果列1和列2的值分别为A,B
,则只有当存在另一个A,B
时才会将其标记为重复项,但如果存在B,A
则不会。 - rvrvrv