I'm having some trouble using R's group_by and summarize functions and was wondering if you all could lend me some help. I have a table similar to this:
Category Frequency
First 1
First 4
Second 6
First 1
Third 1
Third 2
Second 6
First 2
Second 1
I'm attempting to use dplyr's group_by and summarize to find the mean of the frequency column. Here's my sample code:
table %>%
group_by(table$Category) %>%
summarize(meanfrequency = mean(table$frequency))
What I would expect would be for a table to be spit out that breaks down the mean frequency grouped by individual category, like so:
Category Frequency
First 2
Second 4.33
Third 1.5
However, what I'm receiving is a table grouped by category, with each category receiving the value of the mean of the ENTIRE table, like so:
Category Frequency
First 2.66
Second 2.66
Third 2.66
Any clue to what's going on here? I should say I'm a beginner so perhaps I'm missing something obvious. I should note that in my actual table there's several variables in the table other than the 2 I'm attempting to analyze, but not sure if that's relevant or might be messing with something. I also loaded this data into R using Rstudio's built in readxcl package.
Thanks in advance!