Create a Frequency Table in R

Your goal

You have a column of categorical data, and you want to create a frequency table showing the counts per category.

Step-by-step tutorial

R's base package includes a table function that we can use to build frequency tables.

Suppose that we're working with a dataset called Police_Department_Incidents_Previous_Year_2016_ that includes a Category column:

Crime in San Francisco, 2016
Crime in San Francisco, 2016

To create a frequency table, simply use the following command:

> table(Police_Department_Incidents_Previous_Year_2016_['Category'])

The result is a frequency table:

                      ARSON                     ASSAULT
                        286                       13577
                 BAD CHECKS                     BRIBERY
                         34                          66
                   BURGLARY          DISORDERLY CONDUCT
                       5802                         658
DRIVING UNDER THE INFLUENCE               DRUG/NARCOTIC
                        378                        4243
                DRUNKENNESS                EMBEZZLEMENT
                        465                         168
                  EXTORTION             FAMILY OFFENSES
                         60                          53
     FORGERY/COUNTERFEITING                       FRAUD
                        619                        2635
                   GAMBLING                  KIDNAPPING
                         20                         257
              LARCENY/THEFT                 LIQUOR LAWS
                      40409                         156
                  LOITERING              MISSING PERSON
                         42                        4338
               NON-CRIMINAL              OTHER OFFENSES
                      17866                       19599
    PORNOGRAPHY/OBSCENE MAT                PROSTITUTION
                          4                         641
          RECOVERED VEHICLE                     ROBBERY
                        736                        3299
                    RUNAWAY             SECONDARY CODES
                        140                        1841
     SEX OFFENSES, FORCIBLE  SEX OFFENSES, NON FORCIBLE
                        940                          40
            STOLEN PROPERTY                     SUICIDE
                        882                          69
             SUSPICIOUS OCC                        TREA
                       5782                           3
                   TRESPASS                   VANDALISM
                       1812                        8589
              VEHICLE THEFT                    WARRANTS
                       6419                        5914
                WEAPON LAWS
                       1658