Search code examples
rsortingdplyrfrequency

Sort based on Frequency in R


Structure of input dataframe

ds= structure(list(MSISDN = c(800, 800, 783, 
975, 800)), .Names = "Number", row.names = c(NA, 
-5L), class = "data.frame")

Need a simple output which looks like below (not able to add single break)

Num Freq

800 3

975 1

783 1


Solution

  • Check out Tabyl function from janitor package. It does the task that you want plus a bit more

    library(janitor)
        ds <- structure(list(MSISDN = c(800, 800, 783,975, 800)), .Names = "Number", row.names = c(NA,-5L), class = "data.frame")
    
        tabyl(ds$Number)