问题
I have a data frame like this :
1 NA 0.2 NA 1 2
2 NA 0.5 NA 1 6
3 NA 0.7 NA 1 4
4 NA 0.3 NA 1 4
I want to remove the columns that have same values across all the rows.i.e my data frame should look like this:
1 0.2 2
2 0.5 6
3 0.7 4
4 0.3 4
Is there an easiest way to do this?
回答1:
dataf[sapply(dataf, function(x) length(unique(x))>1)]
来源:https://stackoverflow.com/questions/8776092/removing-all-the-columns-of-the-data-frame-that-have-same-values-across-all-the