Message-ID: <50EFF26D.60301@ymail.com>
Date: 2013-01-11T11:07:25Z
From: Pascal Oettli
Subject: count combined occurrences of categories
In-Reply-To: <1357901690.69530.YahooMailNeo@web172401.mail.ir2.yahoo.com>
Hello,
Maybe you can try something like that:
count.au1 <- tapply(tutu$au1, tutu$nam, table)
count.au2 <- tapply(tutu$au2, tutu$nam, table)
count.au3 <- tapply(tutu$au3, tutu$nam, table)
HTH,
Pascal
Le 11/01/2013 19:54, Biau David a ?crit :
> Dear all,
>
> i would like to count the number of times where I have combined occurrences of the categories of 2 variables.
>
> For instance, in the dataframe below, i would like to know how many times each author (au1, au2, au3 represent the first, second, third author) is associated with each of the category of the variable 'nam'. The position of the author does not matter.
>
> nam <- c('da', 'ya', 'da', 'da', 'fr', 'fr', 'fr', 'da', 'ya', 'fr')
> au1 <- c('deb', 'art', 'deb', 'seb', 'deb', 'deb', 'mar', 'mar', 'joy', 'joy')
> au2 <- c('art', 'deb', 'mar', 'deb', 'joy', 'mar', 'art', 'lio', 'nem', 'mar')
> au3 <- c('mar', 'lio', 'joy', 'mar', 'art', 'lio', 'nem', 'art', 'deb', 'tat')
> tutu <- data.frame(cbind(nam, au1, au2, au3))
>
> thanks,
>
> David
> [[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.
>