R:如何按列分组并删除每个组在另一列中重复的行
有一个如下所示的数据框,我需要按“ID”按数据框分组,然后删除列“course”中具有重复值的行 我需要这个:R:如何按列分组并删除每个组在另一列中重复的行,r,unique,R,Unique,有一个如下所示的数据框,我需要按“ID”按数据框分组,然后删除列“course”中具有重复值的行 我需要这个: 1 ID01 01.10.2012 Math 4 ID01 01.01.2013 History 5 ID02 10.01.2013 Math 7 ID02 15.01.2013 History dput(test) structure(list(ID = structure(c(1L, 1L, 1L, 1L, 2L, 2L, 2L), .Label = c("I
1 ID01 01.10.2012 Math
4 ID01 01.01.2013 History
5 ID02 10.01.2013 Math
7 ID02 15.01.2013 History
dput(test)
structure(list(ID = structure(c(1L, 1L, 1L, 1L, 2L, 2L, 2L), .Label = c("ID01",
"ID02"), class = "factor"), time = structure(c(1L, 2L, 3L, 3L,
4L, 5L, 6L), .Label = c("01.10.2012", "10.11.2012", "01.01.2013",
"10.01.2013", "02.05.2013", "15.01.2013"), class = "factor"),
course = structure(c(1L, 1L, 1L, 2L, 1L, 1L, 2L), .Label = c("Math",
"History"), class = "factor")), .Names = c("ID", "time",
"course"), row.names = c(NA, 7L), class = "data.frame")
1 ID01 01.10.2012 Math
4 ID01 01.01.2013 History
5 ID02 10.01.2013 Math
7 ID02 15.01.2013 History
dput(test)
structure(list(ID = structure(c(1L, 1L, 1L, 1L, 2L, 2L, 2L), .Label = c("ID01",
"ID02"), class = "factor"), time = structure(c(1L, 2L, 3L, 3L,
4L, 5L, 6L), .Label = c("01.10.2012", "10.11.2012", "01.01.2013",
"10.01.2013", "02.05.2013", "15.01.2013"), class = "factor"),
course = structure(c(1L, 1L, 1L, 2L, 1L, 1L, 2L), .Label = c("Math",
"History"), class = "factor")), .Names = c("ID", "time",
"course"), row.names = c(NA, 7L), class = "data.frame")
ff=your.table
ff[!duplicated(ff[c("ID","course")]),]