# [R] Determining frequancy of events

Francisco J. Zagmutt gerifalte28 at hotmail.com
Mon Apr 3 03:47:58 CEST 2006

```This is not a very generic option, but for your example you can use unique
and cbind to create a new dataframe with the results i.e

a<-c(1,2,3,1,5)
b<-c(2,2,2,2,2)
c<-c(2,3,4,2,6)

f=as.integer(table(paste(a,b,c)))#Stores only frequency

data.frame(unique(cbind(a,b,c)),freq=f)
a b c freq
1 1 2 2    2
2 2 2 3    1
3 3 2 4    1
4 5 2 6    1

I hope this helps

Francisco

>From: "Philip Bermingham" <pberming at arts.ryerson.ca>
>To: "Philip Bermingham" <pberming at arts.ryerson.ca>
>CC: r-help <r-help at stat.math.ethz.ch>
>Subject: [R] Determining frequancy of events
>Date: Sun, 2 Apr 2006 18:10:37 -0400
>
>I have a smiple set of values:
>
>a<-c(1,2,3,1,5)
>b<-c(2,2,2,2,2)
>c<-c(2,3,4,2,6)
>
>Then I use data.frame(table(paste(a,b,c)))to determine the frequancy of
>each set of values occures and get the result:
>
>    Var1 Freq
>1 1 2 2    2
>2 2 2 3    1
>3 3 2 4    1
>4 5 2 6    1
>
>This is exactly what I need although the paste function puts the values
>into a string.  I want to split the var1 into three variables while hanging
>onto the frequancy count so the result would be like:
>
>   v1 v2 v3 Freq
>1  1  2  2  2
>2  2  2  3  1
>3  3  2  4  1
>4  5  2  6  1
>
>What is the best way to do this?
>