R group_by error

I have the following code:

supply_agg = vector(length = 64, mode = 'list')
for (i in 1:64) {
  supply_agg[[i]] <- PST[rownames(pct_kritiek),]*pct_kritiek[,i] *1000000
  supply_agg[[i]] <- cbind("gg_omschrijving" = rownames(supply_agg[[i]]), supply_agg[[i]])
  supply_agg[[i]] <- inner_join(koppelGG, supply_agg[[i]], by= "gg_omschrijving")
  supply_agg[[i]] <- supply_agg[[i]][,-1]
  supply_agg[[i]] <- supply_agg[[i]] %>% 
    group_by(gg_mm) %>% 
    summarise_each(funs(sum))
  colnames(supply_agg[[i]]) <- koppelRK[1,]
  supply_agg[[i]]<- pivot_longer(supply_agg[[i]], col= "Landbouw, bosbouw en visserij":"Milieu",names_to = "Regkol", values_to = "value")
  supply_agg[[i]]<- supply_agg[[i]][,-3]
  supply_agg[[i]] <- supply_agg %>% 
    group_by(gg_mm, Regkol) %>%
    summarise_each(funs(sum()))

All goes well untill the last group_by(gg_mm, Regkol) I het this error:
"no applicable method for 'group_by_' applied to an object of class "list".

In the image you can see how the data looks just before the group_by function. I need to group when "gg_mm" and "Regkol" are the same.

My guess is that you also intended to [[i]] subset supply_agg in the problematic line, as you did in previous lines.

This topic was automatically closed 21 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.