3

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?

PeeHaa
  • 71,436
  • 58
  • 190
  • 262
user1021713
  • 2,133
  • 8
  • 27
  • 40

1 Answers1

9
dataf[sapply(dataf, function(x) length(unique(x))>1)]
Wojciech Sobala
  • 7,431
  • 2
  • 21
  • 27