1

I have a dataset (mhomes) with around 6000 observations and 80 variables. Of these variables, around 40 contain different types of policies and how often they are sold to each customer. These all start with the word "num", after which the specific type of policy is specified (e.g., num_life).

I now want to add a variable (total_policies) that calculates how many policies each customer has purchased.

I tried the following R code, but it gives me the following error: No tidyselect variables were registered

mhomes %>% mutate(total_policies = rowSums(select(starts_with("num"))))

What does this error mean and how can I fix it to calculate total_policies?

Ronak Shah
  • 377,200
  • 20
  • 156
  • 213
Florence V
  • 21
  • 2
  • 1
    `Select` needs a dataframe to select variables from. Try `mhomes %>% mutate(total_policies = rowSums(select(., starts_with("num"))))` to pass the df via the "." to `select`. – stefan Apr 18 '20 at 17:08

0 Answers0