Joseph Noirre
Joseph Noirre

Reputation: 387

dplyr Error in eval(expr, envir, enclos) : object '.' not found

I'm trying to manipulate this bit of data with dplyr using the code below, but I keep getting the error.

Error in eval(expr, envir, enclos) : object '.' not found

The code I'm using, I think it's something to do with referencing the columns by index rather than name.

closing <- filter(survey, .[[47]] != 0, .[[48]] >= 10) %>%
  mutate(percieved_jobs = .[[47]] * 12, percieved_actual_jobs = (.[[47]] * 12) * (.[[48]] / 100)) %>%
  group_by(listing) %>%
  summarise(n = n(), mean_closing = mean(.[[48]]), mean_pjobs = mean(percieved_jobs), mean_jobs = mean(percieved_actual_jobs))

Thanks, any help is greatly appreciated.

Upvotes: 2

Views: 2973

Answers (1)

agenis
agenis

Reputation: 8377

Actually the error simply comes from your way of using the piping in the first command. The . (dot) refers to the previous result in the pipeline but there is nothing before your filter so it gives the error!

To get it work you can take the data.frame out of the filter function:

closing <- survey %>% filter(.[[47]] != 0, .[[48]] >= 10) %>% ...

I tested it with another dataset.

Upvotes: 3

Related Questions