Reputation: 9687
I have a data.frame containing many duplicated columns, for example:
df = data.frame(a=1:10, b=1:10, c=2:11)
Is there a function (base R or dplyr) that removes duplicated columns ? unique()
removes duplicate rows.
Unlike How to remove duplicated column names in R? my columns already have different names, but the values are identical.
Upvotes: 2
Views: 2489
Reputation: 887028
An option is
df[!duplicated(as.list(df))]
Or
df[!duplicated(unclass(df))]
Upvotes: 5