Unable to do a group_by

   Name           y2_costate y2_FIPSCO
1   Joe Arlington County, VA     51013
2   Joe Arlington County, VA     51013
3   Joe Arlington County, VA     51013
4   Joe Arlington County, VA     51013
5   Joe Arlington County, VA     51013
6   Joe Arlington County, VA     51013
7   Joe Arlington County, VA     51013
8  Mary   Baltimore city, MD     24005
9  Mary   Baltimore city, MD     24005
10 Mary   Baltimore city, MD     24005
11 Mary   Baltimore city, MD     24005
12 Mary   Baltimore city, MD     24005
13 Mary   Baltimore city, MD     24005
14 Mary   Baltimore city, MD     24005

I am trying to do a group_by on the three variable dataset test4.
The package does not do the grouping. The results are below. What am I missing?
Thanks, Anton

check4 <- group_by(test4, Name)
head(check4)
head(check4, 14)
# A tibble: 14 x 3
# Groups:   Name [2]
   Name  y2_costate           y2_FIPSCO
   <fct> <fct>                    <int>
 1 Joe   Arlington County, VA     51013
 2 Joe   Arlington County, VA     51013
 3 Joe   Arlington County, VA     51013
 4 Joe   Arlington County, VA     51013
 5 Joe   Arlington County, VA     51013
 6 Joe   Arlington County, VA     51013
 7 Joe   Arlington County, VA     51013
 8 Mary  Baltimore city, MD       24005
 9 Mary  Baltimore city, MD       24005
10 Mary  Baltimore city, MD       24005
11 Mary  Baltimore city, MD       24005
12 Mary  Baltimore city, MD       24005
13 Mary  Baltimore city, MD       24005
14 Mary  Baltimore city, MD       24005
>

Could you please turn this into a self-contained reprex (short for reproducible example)? It will help us help you if we can be sure we're all working with/looking at the same stuff. For example, based on what you've pasted, it's not clear whether or not you've loaded the necessary packages before running the code.

install.reprex("reprex")

If you've never heard of a reprex before, you might want to start by reading the tidyverse.org help page. The reprex dos and don'ts are also useful.

What to do if you run into clipboard problems

If you run into problems with access to your clipboard, you can specify an outfile for the reprex, and then copy and paste the contents into the forum.

reprex::reprex(input = "fruits_stringdist.R", outfile = "fruits_stringdist.md")

For pointers specific to the community site, check out the reprex FAQ, linked to below.

What are you expecting the output to be? I suspect what you are missing is you expect group_by to change your data in some way beyond putting a grouping variable in the meta data. It doesn't work that way. group_by just sets up the grouping. To change the data you need to do something like summarize. Try this:

test4 %>%
  group_by( Name) %>%
  summarize(rec_count = n() ) %>%
  head(14)
1 Like

Thank you so much. I will try this.

Anton