# count frequency

 Classic List Threaded
9 messages
Reply | Threaded
Open this post in threaded view
|
Report Content as Inappropriate

## count frequency

 Hello everyone, please consider the following lines of a matrix [574,]   59   32 [575,]   59   32 [576,]   59   32 [577,]   59   32 [578,]   59   32 [579,]   59   32 [580,]   59   32 [581,]   60   32 [582,]   60   33 [583,]   60   33 [584,]   60   33 [585,]   60   33 [586,]   60   33 [587,]   60   33 [588,]   60   33 [589,]   60   33 [590,]   60   33 [591,]   61   33 [592,]   61   33 [593,]   61   33 [594,]   61   33 [595,]   61   33 [596,]   61   33 [597,]   61   33 [598,]   61   33 [599,]   61   33 [600,]   61   33 [601,]   62   34 Is it possible somehow to count the similarities between the first and second column and put them on a third column like this? 59 32 3 60 33 5 62 34 1 where (3,5,1 are the frequencies for (59,32), (60,33) and (62,34) Best Regards Alex               [[alternative HTML version deleted]] ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|
Report Content as Inappropriate

## Re: count frequency

 -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On 17/09/10 14:19, Alaios wrote: > Hello everyone, > please consider the following lines of a matrix > > > [574,]   59   32 > [575,]   59   32 > [576,]   59   32 > [577,]   59   32 > [578,]   59   32 > [579,]   59   32 > [580,]   59   32 > [581,]   60   32 > [582,]   60   33 > [583,]   60   33 > [584,]   60   33 > [585,]   60   33 > [586,]   60   33 > [587,]   60   33 > [588,]   60   33 > [589,]   60   33 > [590,]   60   33 > [591,]   61   33 > [592,]   61   33 > [593,]   61   33 > [594,]   61   33 > [595,]   61   33 > [596,]   61   33 > [597,]   61   33 > [598,]   61   33 > [599,]   61   33 > [600,]   61   33 > [601,]   62   34 > > Is it possible somehow to count the similarities between the first and second > column and put them on a third column like this? > > 59 32 3 > 60 33 5 > 62 34 1 > > where (3,5,1 are the frequencies for (59,32), (60,33) and (62,34) One solution: > x <- data.frame(a=trunc(runif(10)*10), b=trunc(runif(10)*10)) > x    a b 1  6 5 2  7 5 3  1 5 4  0 4 5  3 9 6  6 8 7  4 3 8  0 4 9  2 7 10 7 2 > x\$comb <- paste(x\$a, x\$b) > x    a b comb 1  6 5  6 5 2  7 5  7 5 3  1 5  1 5 4  0 4  0 4 5  3 9  3 9 6  6 8  6 8 7  4 3  4 3 8  0 4  0 4 9  2 7  2 7 10 7 2  7 2 > table(x\$comb) 0 4 1 5 2 7 3 9 4 3 6 5 6 8 7 2 7 5   2   1   1   1   1   1   1   1   1 > I am sure, there are better ones Cheers, Rainer > > Best Regards > Alex > > > >       > [[alternative HTML version deleted]] > > ______________________________________________ > [hidden email] mailing list > https://stat.ethz.ch/mailman/listinfo/r-help> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html> and provide commented, minimal, self-contained, reproducible code. - -- Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation Biology, UCT), Dipl. Phys. (Germany) Centre of Excellence for Invasion Biology Natural Sciences Building Office Suite 2039 Stellenbosch University Main Campus, Merriman Avenue Stellenbosch South Africa Tel:        +33 - (0)9 53 10 27 44 Cell:       +27 - (0)8 39 47 90 42 Fax (SA):   +27 - (0)8 65 16 27 82 Fax (D) :   +49 - (0)3 21 21 25 22 44 Fax (FR):   +33 - (0)9 58 10 27 44 email:      [hidden email] Skype:      RMkrug -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.10 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/iEYEARECAAYFAkyTXoQACgkQoYgNqgF2egrgrgCfUOvMaUOwOC7HPSdbC2fFzdLo 4scAmwQ2M1E000PH4HoQmkpkLbANtjLy =B2y8 -----END PGP SIGNATURE----- ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|
Report Content as Inappropriate

## Re: count frequency

 In reply to this post by alaios Try this: aggregate(rep(1, nrow(x)), x, sum) On Fri, Sep 17, 2010 at 9:19 AM, Alaios <[hidden email]> wrote: > Hello everyone, > please consider the following lines of a matrix > > > [574,]   59   32 > [575,]   59   32 > [576,]   59   32 > [577,]   59   32 > [578,]   59   32 > [579,]   59   32 > [580,]   59   32 > [581,]   60   32 > [582,]   60   33 > [583,]   60   33 > [584,]   60   33 > [585,]   60   33 > [586,]   60   33 > [587,]   60   33 > [588,]   60   33 > [589,]   60   33 > [590,]   60   33 > [591,]   61   33 > [592,]   61   33 > [593,]   61   33 > [594,]   61   33 > [595,]   61   33 > [596,]   61   33 > [597,]   61   33 > [598,]   61   33 > [599,]   61   33 > [600,]   61   33 > [601,]   62   34 > > Is it possible somehow to count the similarities between the first and > second > column and put them on a third column like this? > > 59 32 3 > 60 33 5 > 62 34 1 > > where (3,5,1 are the frequencies for (59,32), (60,33) and (62,34) > > Best Regards > Alex > > > > >        [[alternative HTML version deleted]] > > ______________________________________________ > [hidden email] mailing list > https://stat.ethz.ch/mailman/listinfo/r-help> PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html> and provide commented, minimal, self-contained, reproducible code. > -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40" S 49° 16' 22" O         [[alternative HTML version deleted]] ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|
Report Content as Inappropriate

## Re: count frequency

 In reply to this post by alaios On 17-Sep-10 12:19:10, Alaios wrote: > Hello everyone, > please consider the following lines of a matrix > > [574,]   59   32 > [575,]   59   32 > [576,]   59   32 > [577,]   59   32 > [578,]   59   32 > [579,]   59   32 > [580,]   59   32 > [581,]   60   32 > [582,]   60   33 > [583,]   60   33 > [584,]   60   33 > [585,]   60   33 > [586,]   60   33 > [587,]   60   33 > [588,]   60   33 > [589,]   60   33 > [590,]   60   33 > [591,]   61   33 > [592,]   61   33 > [593,]   61   33 > [594,]   61   33 > [595,]   61   33 > [596,]   61   33 > [597,]   61   33 > [598,]   61   33 > [599,]   61   33 > [600,]   61   33 > [601,]   62   34 > > Is it possible somehow to count the similarities between the first and > second > column and put them on a third column like this? > > 59 32 3 > 60 33 5 > 62 34 1 > > where (3,5,1 are the frequencies for (59,32), (60,33) and (62,34) > > Best Regards > Alex Does the following do what you want?   a <- c(59,59,59,59,59,59,59,60,60,60,60,60,60,60,          60,60,60,61,61,61,61,61,61,61,61,61,61,62)   b <- c(32,32,32,32,32,32,32,32,33,33,33,33,33,33,          33,33,33,33,33,33,33,33,33,33,33,33,33,34)   table(data.frame(a=a,b=b))   #     b   # a    32 33 34   #   59  7  0  0   #   60  1  9  0   #   61  0 10  0   #   62  0  0  1   T <- t(as.matrix(table(data.frame(a=a,b=b))))   L <- c(table(data.frame(a=a,b=b)))   B <- as.integer(rep(rownames(T),each=ncol(T)))   A <- as.integer(rep(colnames(T),nrow(T)))   cbind(A,B,L)[L>0,]   #       A  B  L   # [1,] 59 32  7   # [2,] 60 32  1   # [3,] 60 33  9   # [4,] 61 33 10   # [5,] 62 34  1 Ted. -------------------------------------------------------------------- E-Mail: (Ted Harding) <[hidden email]> Fax-to-email: +44 (0)870 094 0861 Date: 17-Sep-10                                       Time: 14:15:03 ------------------------------ XFMail ------------------------------ ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|
Report Content as Inappropriate

## Re: count frequency

 In reply to this post by alaios Alaios, Try as.data.frame(table(x[,1], x[,2)) where x is your matrix. HTH, Jorge On Fri, Sep 17, 2010 at 8:19 AM, Alaios <> wrote: > Hello everyone, > please consider the following lines of a matrix > > > [574,]   59   32 > [575,]   59   32 > [576,]   59   32 > [577,]   59   32 > [578,]   59   32 > [579,]   59   32 > [580,]   59   32 > [581,]   60   32 > [582,]   60   33 > [583,]   60   33 > [584,]   60   33 > [585,]   60   33 > [586,]   60   33 > [587,]   60   33 > [588,]   60   33 > [589,]   60   33 > [590,]   60   33 > [591,]   61   33 > [592,]   61   33 > [593,]   61   33 > [594,]   61   33 > [595,]   61   33 > [596,]   61   33 > [597,]   61   33 > [598,]   61   33 > [599,]   61   33 > [600,]   61   33 > [601,]   62   34 > > Is it possible somehow to count the similarities between the first and > second > column and put them on a third column like this? > > 59 32 3 > 60 33 5 > 62 34 1 > > where (3,5,1 are the frequencies for (59,32), (60,33) and (62,34) > > Best Regards > Alex > > > > >        [[alternative HTML version deleted]] > > ______________________________________________ > [hidden email] mailing list > https://stat.ethz.ch/mailman/listinfo/r-help> PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html> and provide commented, minimal, self-contained, reproducible code. >         [[alternative HTML version deleted]] ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|
Report Content as Inappropriate

## Re: count frequency

 Just to confirm, this one worked for me  as.data.frame(table(temp[]))    Var1 Freq 1     1   11 2     2   29 3     3   29 4     4   29 5     5   29 6     6   29 7     7   29 8     8   29 9     9   29 10   10   29 11   11   29 12   12   29 13   13   29 14   14   29 15   15   29 16   16   29 17   17   29 18   18   30 19   19   29 20   20   29 Best Regards Alex ________________________________ From: Jorge Ivan Velez <[hidden email]> Cc: Rhelp <[hidden email]> Sent: Fri, September 17, 2010 4:24:59 PM Subject: Re: [R] count frequency Alaios, Try as.data.frame(table(x[,1], x[,2)) where x is your matrix. HTH, Jorge   On Fri, Sep 17, 2010 at 8:19 AM, Alaios <> wrote: Hello everyone, >please consider the following lines of a matrix > > >[574,]   59   32 >[575,]   59   32 >[576,]   59   32 >[577,]   59   32 >[578,]   59   32 >[579,]   59   32 >[580,]   59   32 >[581,]   60   32 >[582,]   60   33 >[583,]   60   33 >[584,]   60   33 >[585,]   60   33 >[586,]   60   33 >[587,]   60   33 >[588,]   60   33 >[589,]   60   33 >[590,]   60   33 >[591,]   61   33 >[592,]   61   33 >[593,]   61   33 >[594,]   61   33 >[595,]   61   33 >[596,]   61   33 >[597,]   61   33 >[598,]   61   33 >[599,]   61   33 >[600,]   61   33 >[601,]   62   34 > >Is it possible somehow to count the similarities between the first and second >column and put them on a third column like this? > >59 32 3 >60 33 5 >62 34 1 > >where (3,5,1 are the frequencies for (59,32), (60,33) and (62,34) > >Best Regards >Alex > > > > >       [[alternative HTML version deleted]] > >______________________________________________ >[hidden email] mailing list >https://stat.ethz.ch/mailman/listinfo/r-help>PLEASE do read the posting guide http://www.R-project.org/posting-guide.html>and provide commented, minimal, self-contained, reproducible code. >               [[alternative HTML version deleted]] ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|
Report Content as Inappropriate

## Re: count frequency

 In reply to this post by Henrique Dallazuanna My bad :( unfortunately does not work correct. This is some of the output of the table .............. [494,]   50   27 [495,]   50   27 [496,]   50   27 [497,]   50   28 [498,]   50   28 [499,]   50   28 [500,]   50   28 [501,]   51   28 [502,]   51   28 [503,]   51   28 [504,]   51   28 [505,]   51   28 [506,]   51   28 [507,]   51   28 [508,]   51   28 [509,]   51   28 [510,]   51   28 [511,]   52   28 [512,]   52   28 [513,]   52   28 [514,]   52   28 [515,]   52   28 [516,]   52   29 [517,]   52   29 [518,]   52   29 ............ I need the following results 50 27: 3 50 28: 4 51 28: 10 52 28: 5 52 29: 3 So far nothing worked. Best Regards Alex ________________________________ From: Henrique Dallazuanna <[hidden email]> Cc: Rhelp <[hidden email]> Sent: Fri, September 17, 2010 3:09:36 PM Subject: Re: [R] count frequency Try this: aggregate(rep(1, nrow(x)), x, sum) Hello everyone, >please consider the following lines of a matrix > > >[574,]   59   32 >[575,]   59   32 >[576,]   59   32 >[577,]   59   32 >[578,]   59   32 >[579,]   59   32 >[580,]   59   32 >[581,]   60   32 >[582,]   60   33 >[583,]   60   33 >[584,]   60   33 >[585,]   60   33 >[586,]   60   33 >[587,]   60   33 >[588,]   60   33 >[589,]   60   33 >[590,]   60   33 >[591,]   61   33 >[592,]   61   33 >[593,]   61   33 >[594,]   61   33 >[595,]   61   33 >[596,]   61   33 >[597,]   61   33 >[598,]   61   33 >[599,]   61   33 >[600,]   61   33 >[601,]   62   34 > >Is it possible somehow to count the similarities between the first and second >column and put them on a third column like this? > >59 32 3 >60 33 5 >62 34 1 > >where (3,5,1 are the frequencies for (59,32), (60,33) and (62,34) > >Best Regards >Alex > > > > >       [[alternative HTML version deleted]] > >______________________________________________ >[hidden email] mailing list >https://stat.ethz.ch/mailman/listinfo/r-help>PLEASE do read the posting guide http://www.R-project.org/posting-guide.html>and provide commented, minimal, self-contained, reproducible code. > -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40" S 49° 16' 22" O               [[alternative HTML version deleted]] ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|
Report Content as Inappropriate

## Re: count frequency

 So try this : aggregate(rep(1, nrow(x)), as.data.frame(x), sum) On Fri, Sep 17, 2010 at 11:54 AM, Alaios <[hidden email]> wrote: > My bad :( > unfortunately does not work correct. > > This is some of the output of the table > .............. > [494,]   50   27 > [495,]   50   27 > [496,]   50   27 > [497,]   50   28 > [498,]   50   28 > [499,]   50   28 > [500,]   50   28 > [501,]   51   28 > [502,]   51   28 > [503,]   51   28 > [504,]   51   28 > [505,]   51   28 > [506,]   51   28 > [507,]   51   28 > [508,]   51   28 > [509,]   51   28 > [510,]   51   28 > [511,]   52   28 > [512,]   52   28 > [513,]   52   28 > [514,]   52   28 > [515,]   52   28 > [516,]   52   29 > [517,]   52   29 > [518,]   52   29 > ............ > > > I need the following results > 50 27: 3 > 50 28: 4 > 51 28: 10 > 52 28: 5 > 52 29: 3 > > So far nothing worked. > Best Regards > Alex > > > > ------------------------------ > *From:* Henrique Dallazuanna <[hidden email]> > *To:* Alaios <[hidden email]> > > *Cc:* Rhelp <[hidden email]> > *Sent:* Fri, September 17, 2010 3:09:36 PM > > *Subject:* Re: [R] count frequency > > Try this: > > aggregate(rep(1, nrow(x)), x, sum) > > On Fri, Sep 17, 2010 at 9:19 AM, Alaios <[hidden email]> wrote: > >> Hello everyone, >> please consider the following lines of a matrix >> >> >> [574,]   59   32 >> [575,]   59   32 >> [576,]   59   32 >> [577,]   59   32 >> [578,]   59   32 >> [579,]   59   32 >> [580,]   59   32 >> [581,]   60   32 >> [582,]   60   33 >> [583,]   60   33 >> [584,]   60   33 >> [585,]   60   33 >> [586,]   60   33 >> [587,]   60   33 >> [588,]   60   33 >> [589,]   60   33 >> [590,]   60   33 >> [591,]   61   33 >> [592,]   61   33 >> [593,]   61   33 >> [594,]   61   33 >> [595,]   61   33 >> [596,]   61   33 >> [597,]   61   33 >> [598,]   61   33 >> [599,]   61   33 >> [600,]   61   33 >> [601,]   62   34 >> >> Is it possible somehow to count the similarities between the first and >> second >> column and put them on a third column like this? >> >> 59 32 3 >> 60 33 5 >> 62 34 1 >> >> where (3,5,1 are the frequencies for (59,32), (60,33) and (62,34) >> >> Best Regards >> Alex >> >> >> >> >>        [[alternative HTML version deleted]] >> >> ______________________________________________ >> [hidden email] mailing list >> https://stat.ethz.ch/mailman/listinfo/r-help>> PLEASE do read the posting guide >> http://www.R-project.org/posting-guide.html>> and provide commented, minimal, self-contained, reproducible code. >> > > > > -- > Henrique Dallazuanna > Curitiba-Paraná-Brasil > 25° 25' 40" S 49° 16' 22" O > > -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40" S 49° 16' 22" O         [[alternative HTML version deleted]] ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|
Report Content as Inappropriate

## Re: count frequency

 You are pretty good. Worked nicely :) Thanks! Alex ________________________________ From: Henrique Dallazuanna <[hidden email]> Cc: Rhelp <[hidden email]> Sent: Fri, September 17, 2010 4:58:50 PM Subject: Re: [R] count frequency So try this : aggregate(rep(1, nrow(x)), as.data.frame(x), sum) My bad :( >unfortunately does not work correct. > >This is some of the output of the table >.............. >[494,]   50   27 >[495,]   50   27 >[496,]   50   27 >[497,]   50   28 >[498,]   50   28 >[499,]   50   28 >[500,]   50   28 >[501,]   51   28 >[502,]   51   28 >[503,]   51   28 >[504,]   51   28 >[505,]   51   28 >[506,]   51   28 >[507,]   51   28 >[508,]   51   28 >[509,]   51   28 >[510,]   51    28 >[511,]   52   28 >[512,]   52   28 >[513,]   52   28 >[514,]   52   28 >[515,]   52   28 >[516,]   52   29 >[517,]   52   29 >[518,]   52   29 > >............ > > >I need the following results >50 27: 3 >50 28: 4 >51 28: 10 >52 28: 5 >52 29: 3 > > >So far nothing worked. >Best Regards >Alex > > > > > ________________________________ From: Henrique Dallazuanna <[hidden email]> > >Cc: Rhelp <[hidden email]> >Sent: Fri, September 17, 2010 3:09:36 PM > >Subject: Re: [R] count frequency > > >Try this: > >aggregate(rep(1, nrow(x)), x, sum) > > > >Hello everyone, >>please consider the following lines of a matrix >> >> >>[574,]   59   32 >>[575,]   59   32 >>[576,]   59   32 >>[577,]   59   32 >>[578,]   59   32 >>[579,]   59   32 >>[580,]   59   32 >>[581,]   60   32 >>[582,]   60   33 >>[583,]   60   33 >>[584,]   60   33 >>[585,]   60   33 >>[586,]   60   33 >>[587,]   60   33 >>[588,]   60   33 >>[589,]   60   33 >>[590,]   60   33 >>[591,]   61   33 >>[592,]   61   33 >>[593,]   61   33 >>[594,]   61   33 >>[595,]   61   33 >>[596,]   61   33 >>[597,]   61   33 >>[598,]   61   33 >>[599,]   61   33 >>[600,]   61   33 >>[601,]   62   34 >> >>Is it possible somehow to count the similarities between the first and second >>column and put them on a third column like this? >> >>59 32 3 >>60 33 5 >>62 34 1 >> >>where (3,5,1 are the frequencies for (59,32), (60,33) and (62,34) >> >>Best Regards >>Alex >> >> >> >> >>       [[alternative HTML version deleted]] >> >>______________________________________________ >>[hidden email] mailing list >>https://stat.ethz.ch/mailman/listinfo/r-help>>PLEASE do read the posting guide http://www.R-project.org/posting-guide.html>>and provide commented, minimal, self-contained, reproducible code. >> > > >-- >Henrique Dallazuanna >Curitiba-Paraná-Brasil >25° 25' 40" S 49° 16' 22" O > > -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40" S 49° 16' 22" O               [[alternative HTML version deleted]] ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
Loading...