"Adding missing grouping variables" message in dplyr in R -


i have portion of script running fine before, has been producing odd statement after many of other functions not work properly. trying select 8th , 23rd positions in ranked list of values each site find 25th , 75th percentile values each day in year each site 30 years. approach follows (adapted 4 line dataset - slice(3) slice(23) full 30 year dataset usually):

library(“dplyr”)  mydata  structure(list(station_number = structure(c(1l, 1l, 1l, 1l), .label = "01ad002", class = "factor"),  year = 1981:1984, month = c(1l, 1l, 1l, 1l), day = c(1l,  1l, 1l, 1l), value = c(113, 8.329999924, 15.60000038, 149 )), .names = c("station_number", "year", "month", "day", "value"), class = "data.frame", row.names = c(na, -4l))        value <- mydata$value   qu25 <- mydata %>%            group_by(month, day, station_number) %>%            arrange(desc(value)) %>%            slice(3) %>%            select(value) 

before, left table had 1 value per site describe 25th percentile (since arrange function seems order them highest lowest). however, when run these lines, message:

adding missing grouping variables: `month`, `day`, `station_number` 

this message doesn’t make sense me, grouping variables present in table. also, again, working fine until recently. have tried:

  • detatch(“plyr”) – since have loaded before dplyr
  • dplyr:: group_by – placing directly in group_by line
  • uninstalling , re-intstalling dplyr, although issue having

any idea why might receiving message , why may have stopped working?

thanks help.

update: added dput example 1 site, values january 1st multiple years. hope positional value returned once grouped, instance slice(3) return 15.6 value smaller subset.

for consistency sake grouping variables should present when defined earlier , added when select(value) executed. ungroup should resolve it:

qu25 <- mydata %>%    group_by(month, day, station_number) %>%   arrange(desc(value)) %>%    slice(2) %>%    ungroup() %>%   select(value) 

the requested result without warnings:

> mydata %>%  +   group_by(month, day, station_number) %>% +   arrange(desc(value)) %>%  +   slice(2) %>%  +   ungroup() %>% +   select(value) # tibble: 1 x 1   value   <dbl> 1   113 

Comments