-1

I have a data frame with two columns, year and grade. I am trying to get a table or matrix (any visual) to show the count of each grade per year. data sample

I have done data%>%count(Grade) and have the grades as factors. Not sure how to get it into respective years though.

lbevs
  • 11
  • 1
  • 3
  • It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. Do not share data as images. We cannot copy/paste that into R for testing. – MrFlick Mar 27 '21 at 20:26
  • 1
    Google „group_by tidyverse“. – deschen Mar 27 '21 at 21:03

1 Answers1

0

As other people have commented, a reproducible example with a clear expected output (where possible) will always get you fast, friendly help on Stackoverflow. In the absence of this, I hope the below will help you.

library(tidyverse)

data<-tibble(grade=c("a", "b", "a", "a", "c"),
             cohort=c("2020", "2019", "2019", "2020", "2020"))

data %>% 
  group_by(cohort) %>% 
  count(grade)

Creates as output:

# A tibble: 4 x 3
# Groups:   cohort [2]
  cohort grade     n
  <chr>  <chr> <int>
1 2019   a         1
2 2019   b         1
3 2020   a         2
4 2020   c         1
Simon
  • 991
  • 8
  • 30