1

I have this data frame (train) where I have 2314 variables and I want to drop the columns where the unique length of the column is < 2 and keep the columns where the length is > 1. Maybe I can apply to scale to my function and then run it!

Example:

length(unique(train$makeAcura))
[1] 2

And delete columns with length < 2

length(unique(train$makeAm.General))
[1] 1
Talha Asif
  • 349
  • 1
  • 9

1 Answers1

2

You can use Filter to keep the columns where the unique length is > 1.

Filter(\(x) length(unique(x)) > 1, train)
#  a c
#1 1 1
#2 2 2
#3 3 1

Data:

train <- data.frame(a=1:3, b=1, c=c(1,2,1))
GKi
  • 37,245
  • 2
  • 26
  • 48