我使用R中的重复功能删除数据框中的重复行。
df:
Name Rank
A 1
a 1
B 2
df[!duplicated(df),]
Name Rank
A 1
a 1
B 2
第二行与第一行相同,但不会因为考虑“A”和“a”的情况而被删除。这有什么转折?感谢。
答案 0 :(得分:3)
# If it's okay to change the case
df.lower <- df
df.lower$Name <- tolower(df$Name)
df.lower[!duplicated(df.lower$Name),]
# If you don't want to change the case
df[!duplicated(df.lower$Name),]
或只是
df[!duplicated(tolower(df$Name)),]
Name Rank 1 A 1 3 B 2
基于Name
进行重复数据删除的内容。对于你可以做的整行:
df.lower[!duplicated(df.lower),] # changes the case
或
df[!duplicated(cbind(tolower(df$Name),df$Rank)),] # does not change case