0

I extracted data from sql in R. The data is in a list. I want to find the number of occurrences each value appears in a column of the list. How would I go about doing this? I'm very new to R.

    group_by(demo) %>%
         summarise(unique_value = n_distinct(column_name))

I tried doing this above and the output was:

    unique_value
            <int>
             5

So there are 5 unique values. How do I determine how many times each unique value appears in the column?

irene123
  • 11
  • 2

1 Answers1

0

Would be helpful to include what your dataset looks like using dput. To start, depending on your object I would convert demo to a data.table. Then you can use the following to get the frequency of each unique value for a specific col.

library(data.table)
demo = as.data.table(demo)
demo_n = demo[,.N, by = column_name]

Additionally, I'd recommend checking out this question: Count number of occurences for each unique value

Jamie
  • 1,793
  • 6
  • 16