Skip to content
Prev 198733 / 398506 Next

counting frequencies across two columns

On Nov 1, 2009, at 1:59 AM, Patrick Connolly wrote:

            
You've had two guesses so far and my guess increments the count.

Were you attempting to specify this?

df1 <- read.table(textConnection("commentID  author articleID
1         1   smith         2
2         2   jones         3
3         3 andrews         2
4         4   jones         1
5         5 johnson         3
6         6   smith         2"), header=T)

 > lapply( lapply(tapply(df1$author, df1$articleID, I), unique) ,  
length)
$`1`
[1] 1

$`2`
[1] 2

$`3`
[1] 2

Or delivered in matrix form (and using Connolly's approach as  
intermediate:

 > apply( with(df1, table(articleID, author)), 1, function(x) sum(x>0) )
1 2 3
1 2 2
--

David Winsemius, MD
Heritage Laboratories
West Hartford, CT