# [R] Frequencies for a list of vectors

Peter Alspach Peter.Alspach at plantandfood.co.nz
Tue Aug 5 22:53:48 CEST 2014

```Alternatively, use sapply instead of lapply ....

marieData <- list('30008'=c(1,0,1,0), '60008'=c(0,0,1,0), '90008'=c(0,0,1,0), '100007'=1, '130001'=c(0,1))
marieData
\$`30008`
[1] 1 0 1 0

\$`60008`
[1] 0 0 1 0

\$`90008`
[1] 0 0 1 0

\$`100007`
[1] 1

\$`130001`
[1] 0 1

table(sapply(marieData, paste, collapse=''))

-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of Rui Barradas
Sent: Wednesday, 6 August 2014 8:49 a.m.
To: Marie-Pierre Sylvestre; r-help at r-project.org
Subject: Re: [R] Frequencies for a list of vectors

Hello,

Maybe something like

table(unlist(lapply(HTNlist, paste, collapse = '')))

(Untested, it's a bad idea not to use ?dput to give a data example.) Use

dput(head(HTNlist))  # paste the output of this in a mail

Hope this helps,

Em 05-08-2014 18:39, Marie-Pierre Sylvestre escreveu:
> Dear R users,
>
> I have a list of vectors (list is called HTNlist). Each vector is of
> length
> 1 to 4 and takes only 0 and 1 as values. E.g.
>
> \$`30008`
> [1] 1 0 1 0
>
> \$`60008`
> [1] 0 0 1 0
>
> \$`90008`
> [1] 0 0 1 0
>
> \$`100007`
> [1] 1
>
> \$`130001`
> [1] 0 1
>
> \$`130007`
> [1] 1 0 1 0
>
> I would like to obtain a frequency table for the elements of the list.
> I want to know how many of
> '1 0 0' I have in the list, how many '1 0 1 0' etc.
>
>
> Thank you in advance,
> MP
>
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org 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.
>

______________________________________________
R-help at r-project.org 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.
The contents of this e-mail are confidential and may be ...{{dropped:14}}

```