[R] Counting occurrences of a set of values

Thierry Onkelinx thierry.onkelinx at inbo.be
Thu Sep 10 15:30:45 CEST 2015


Have a look at the dplyr package

library(dplyr)
n <- 1000
data_frame(
  V1 = sample(0:1, n, replace = TRUE),
  V2 = sample(0:1, n, replace = TRUE),
  V3 = sample(0:1, n, replace = TRUE)
) %>%
  group_by(V1, V2, V3) %>%
  mutate(
    Freq = n()
  )


ir. Thierry Onkelinx
Instituut voor natuur- en bosonderzoek / Research Institute for Nature and
Forest
team Biometrie & Kwaliteitszorg / team Biometrics & Quality Assurance
Kliniekstraat 25
1070 Anderlecht
Belgium

To call in the statistician after the experiment is done may be no more
than asking him to perform a post-mortem examination: he may be able to say
what the experiment died of. ~ Sir Ronald Aylmer Fisher
The plural of anecdote is not data. ~ Roger Brinner
The combination of some data and an aching desire for an answer does not
ensure that a reasonable answer can be extracted from a given body of data.
~ John Tukey

2015-09-10 15:11 GMT+02:00 Thomas Chesney <Thomas.Chesney op nottingham.ac.uk>:

> Can anyone suggest a way of counting how frequently sets of values occurs
> in a data frame? Like table() only with sets.
>
> So for a dataset:
>
> V1, V2, V3
> 1, 2, 1
> 1, 3, 2
> 1, 2, 1
> 1, 1, 1
>
> The output would be something like:
>
> 1,2,1: 2
> 1,3,2: 1
> 1,1,1: 1
>
> Thank you,
>
> Thomas Chesney
>
>
>
> This message and any attachment are intended solely for the addressee
> and may contain confidential information. If you have received this
> message in error, please send it back to me, and immediately delete it.
>
> Please do not use, copy or disclose the information contained in this
> message or in any attachment.  Any views or opinions expressed by the
> author of this email do not necessarily reflect the views of the
> University of Nottingham.
>
> This message has been checked for viruses but the contents of an
> attachment may still contain software viruses which could damage your
> computer system, you are advised to perform your own checks. Email
> communications with the University of Nottingham may be monitored as
> permitted by UK legislation.
>
> ______________________________________________
> R-help op r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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]]



More information about the R-help mailing list