0

I have the following data in the form of code like "J87A" I need to create a table to show the frequency of each code.

My data:

df <- structure(list(value = c("I2510", "I2510", "R9431", "M1A9XX0", 
"I272", "E869", "I2510", "Z87891", "E1140", "Z955", "R7989", 
"I2510", "I340")), class = c("tbl_df", "tbl", "data.frame"), row.names = c(NA, 
-13L))
TarJae
  • 72,363
  • 6
  • 19
  • 66

1 Answers1

0

One way could be: count is quite handy in this situation as it also summarises the data.

count does the same as df %>% group_by(value) %>% summarise(n = n()) in contrast to add_count which is the same as df %>% group_by(value) %>% mutate(n = n()):

library(dplyr)

df %>% 
  count(value)
  value       n
   <chr>   <int>
 1 E1140       1
 2 E869        1
 3 I2510       4
 4 I272        1
 5 I340        1
 6 M1A9XX0     1
 7 R7989       1
 8 R9431       1
 9 Z87891      1
10 Z955        1

data:

structure(list(value = c("I2510", "I2510", "R9431", "M1A9XX0", 
"I272", "E869", "I2510", "Z87891", "E1140", "Z955", "R7989", 
"I2510", "I340")), class = c("tbl_df", "tbl", "data.frame"), row.names = c(NA, 
-13L))
TarJae
  • 72,363
  • 6
  • 19
  • 66