我有一个包含2列的数据集
text created
1 cant do it with cards either 1/2/2014
2 cant do it with cards either 2/2/2014
3 Coming back home AK 2/2/2014
4 Coming back home AK 5/2/2014
5 gotta try PNNL 1/2/2014
6 Me and my Tart would love to flyLoveisintheAir 5/2/2014
7 Me and my Tart would love to flyLoveisintheAir 6/2/2014
如何根据第一列的唯一字符串获取数据集的子集?
text created
1 cant do it with cards either 1/2/2014
3 Coming back home AK 2/2/2014
5 gotta try PNNL 1/2/2014
6 Me and my Tart would love to flyLoveisintheAir 5/2/2014
structure(list(text = structure(c(1L, 1L, 2L, 2L, 3L, 4L, 4L), .Label = c("cant do it with cards either",
"Coming back home AK", "gotta try PNNL", "Me and my Tart would love to flyLoveisintheAir"
), class = "factor"), created = structure(c(1L, 2L, 2L, 3L, 1L,
3L, 4L), .Label = c("1/2/2014", "2/2/2014", "5/2/2014", "6/2/2014"
), class = "factor")), .Names = c("text", "created"), class = "data.frame", row.names = c(NA,
-7L))
答案 0 :(得分:1)
尝试使用duplicated
和!
。考虑df
是您的data.frame。
> df[!duplicated(df$text), ]
text created
1 cant do it with cards either 1/2/2014
3 Coming back home AK 2/2/2014
5 gotta try PNNL 1/2/2014
6 Me and my Tart would love to flyLoveisintheAir 5/2/2014
答案 1 :(得分:0)
有很多可能性:
tab[!duplicated(tab$text),]
# with dplyr
filter(tab, !duplicated(text))
HTH