去除重复的行
data <- data.frame(id1 = c(1, 1, 1, 2, 2),
id2 = c(2, 2, 3, 2, 2))
library(dplyr)
data %>%
group_by(id1, id2) %>%
filter(row_number() == 1) %>%
ungroup()
累计出现次数
library(data.table)
DT = data.table(x=c(20,10,10,30,30,20), y=c("a", "a", "a", "b", "b", "b"), z=1:6)
rowid(DT$x)#1 1 2 1 2 2