Issue with the group_by verb

Hello,

I'm currently haunted by the group_by verb not working to restructure my data.

Elispot_data_2 <- Elispot_data_2 %>% 
  mutate(Year = factor(Year, levels = c(2019,2020)),
        Organ = factor(Organ, levels = c("Spleen","Lung")),
        Group_name = factor(Group_name, levels=c("Phuket 2013","Colorado 2017","Kansas 2017","Brisbane 2018","Last combination","pVAX")),
        Type = factor(Type, levels=c("H1","H3","B")),
        Pool = factor(Pool, levels = c("1","2","3"))) %>%
  group_by(Year, Organ, Group_name, Type, Pool)

#> Error in Elispot_data_2 %>% mutate(Year = factor(Year, levels = c(2019, : could not find function "%>%"

Created on 2020-09-10 by the reprex package (v0.3.0)
'''

Despite trying to narrow the grouping down to by Pool, my data below show that the data refuse to group this way. It is still being grouped by "Animal" which is only still numeric. I've played with the code endlessly. Interestingly, the error message appearing in my reprex does not appear in my console, so I'm not sure if it's running fine or not. Can anyone identify an issue?

The group_by() function does not do anything to the appearance or arrangement of the data. Maybe you want to use the arrange() function to sort the data?

The error 'could not find function "%>%" ' appears when I forget to load the dplyr package. Have you run

library(dplyr)

Thanks for the clarification!! Arrange worked, I must be misunderstanding the utility of group_by (I'm new to R). Is group_by strictly for data summaries? I often see it preceding "summarize" in examples

Yes, group_by() is typically used with summarize(). It changes some information stored internally in the data frame so that other functions, such as summarize(), will combine the rows according to the desired columns.

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.