Winsorize data by column

Hi @LAH_17,

I was able to reproduce the error with the following code:

iris %>% select(Sepal.Length) %>% DescTools::Winsorize(.)

Error in [.data.frame(x, order(x, na.last = na.last, decreasing = decreasing)) :
undefined columns selected

The issue is that Winsorize() only accepts a single numeric vector as its first argument. A data frame with only one variable is still a data frame, not a vector. So based on the error you are getting, it seems like your single variable is still a variable in a data frame. You will need to extract the vector from the data frame like so:

DescTools::Winsorize(rev_vector$rev) # where rev is the name of the variable

Or use an approach that ensures the function is ran inside the context of the data frame. Here are two such examples:

# Base R approach
with(rev_vector, DescTools::Winsorize(rev))
# Tidy approach
rev_vector %>%
  mutate(rev2 = DescTools::Winsorize(rev))