Is there a function like table that outputs the result in a ragged array?
I have a dataframe and I’d like to tabulate the occurrences of different items in a ragged array. I know that I can use table to output the data in an array. However the data is sparse. The xtab function can output in a sparse matrix, but it is limited to two dimensions.
I want a function to take a data frame like this:
Purchases WeeksSinceFirstPurcahse 1 10.1 1 4.2 1 4.2 2 2.4 3 1 2 2.4
And output counts like this:
Purchases DaysSinceFirstPurcahse Count 1 10.1 1 1 4.2 2 2 2.5 2 3 1 1
You can use the plyr package and specialy the count function.
Using your data, we can do something like this :
Edit to add Count Function Example: