Count function for character class in R

Viewed 2759

My code was working and then RStudio crashed. When I opened it back up, a line of my code is not working now...

CodeTable<-count(unique(Data$Code))

Previously, this created a simple database of 3 columns: 1) Numeric order, 2)the unique Code, and 3) the count of each Code (which was always 1, since they were counted as unique). Now, I am receiving an error message:

Error in UseMethod("summarise_") : 
no applicable method for 'summarise_' applied to an object of class "character"

I don't believe anything was changed from R crashing and I don't know how to now create my little 'count' table I had before.

1 Answers

count from dplyr requires input as a data.frame

library(dplyr)
Data %>%
      count(Code)

In base R, we can do

table(Data$Code)
Related