[英]How do I remove duplicated columns from a data frame in R?
I have a data.frame containing many duplicated columns, for example:我有一个包含许多重复列的 data.frame,例如:
df = data.frame(a=1:10, b=1:10, c=2:11)
Is there a function (base R or dplyr) that removes duplicated columns ?是否有删除重复列的 function(基础 R 或 dplyr)?
unique()
removes duplicate rows. unique()
删除重复的行。
Unlike How to remove duplicated column names in R?与如何删除 R 中的重复列名不同? my columns already have different names, but the values are identical.
我的列已经有不同的名称,但值是相同的。
An option is一个选项是
df[!duplicated(as.list(df))]
Or或者
df[!duplicated(unclass(df))]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.