-4

I have a single row of numbers. I'm wondering how I can separate it out so that it outputs columns that total the tally of each set of numbers. I've tried playing around with "separate" but I can't figure out how to make it work.

Here's my data frame:


2
2
2
2
2
4
4
4   

I'd like it to be

2  4
5  3
Claire
  • 135
  • 1
  • 11

2 Answers2

1

You can use the table() function.

> df
  V1
1  2
2  2
3  2
4  2
5  2
6  4
7  4
8  4
> table(df$V1)

2 4 
5 3 
Psidom
  • 195,464
  • 25
  • 298
  • 322
0

We can use tabulate which would be faster

tabulate(factor(df1$V1))
#[1] 5 3
akrun
  • 789,025
  • 32
  • 460
  • 575