dplyr group_by column not found

Using dplyr, in syntax like

sample_check_edu <- demo_dat %>% 
  left_join(edu_sample_map, by = c("EDU_LEVEL" = "input")) %>%
  group_by(output) %>%
  summarise(total = n() )  %>% 
  mutate(prop = total/sum(total) )

I get an error like

Error in `group_by()`:
! Must group by variables found in `.data`.
✖ Column `ouput` is not found.
Backtrace:

Specifying the column index number seems to work. 'output' is definitely a column name if I examine what is produced before the group_by command.

The issue described HERE is the same as mine and the solution works. Does anyone know why this happens or why the solution works.

If output is not a column/variable name, you would get this error. The result of the left_join() operation into the next step is an implicit data frame that does not need naming, but the variable/column within it does.

Try ;

demo_dat %>% 
  left_join(edu_sample_map, by = c("EDU_LEVEL" = "input")) %>%  names()  %>% unique()  %>%  sort()

Either 'output' will be there or not; but thats useful information.

1 Like

I definitely trust that output is a populated column. Here is another example.

tmp %<>%  left_join(edu_sample_map, by = c("EDU_LEVEL" = "input")) # %>% rename(edu_bin = output) 

tmp %>% rename(edu_bin = output) 
Error in `rename()`:
! Can't rename columns that don't exist.
✖ Column `output` doesn't exist.
Backtrace:
 1. tmp %>% rename(edu_bin = output)
 3. dplyr:::rename.data.frame(., edu_bin = output)
> names(tmp)
 [1] "..."     "ouput"         
table(tmp$ouput)

Bachelors Degree      High School        Post Grad  Post High Schoo 
            2145             1255             1288             2323 

The same behavior occurs if I run this in a single line of code.

Output with two 't's, doesnt exist you had something called ouput with only one 't'

1 Like

I was 40 before I discovered that I was mildly dyslexic, consistently transposing letters and numbers and being unable to review my work and detect the error. Because to me, the transposed version looked right. Once I became aware, I developed the habit of assuming that errors such as we see here are my errors of perception and learned to methodically trace back to where my transposition originated.

There’s no way to tell based solely on your example here if you are experiencing something similar but it’s worthwhile to keep your eyes open for the possibility. @nirgrahamuk spotted ouput because he doesn’t share the problem.

Thanks nigrahamuk and technocrat. Thanks for finding the error and correctly identifying my issue. I am aware for this issue in my general writing, but but using autofill - in spite of looking at this dozens of times - I didn't recognize ouput wasn't output.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.