Reputation: 862
I have a database df_final
with many rows (3000) and 4 columns.
To get a count the number of times that each number occurs in a specific column , I'm using this:
counts <- ddply(df_final, .(round(df_final$`Nº HB (1-8)`)), nrow)
names(counts) <- c("HB", "% ")
Output looks like:
1 4 1
2 5 34
3 6 470
4 7 1886
5 8 609
However, what I really need is the frequency of numbers between a range, for example (0-8).
Output should look like:
1 1 0
2 2 0
3 3 0
4 4 0
5 5 34
6 6 470
7 7 1886
8 8 609
Upvotes: 1
Views: 143
Reputation: 886948
We can use table
after specifying the levels
table(factor(round(df_final$"Nº HB (1-8)"), levels = 1:8)
Upvotes: 1