hi netters
Suppose I have a factor X, with 10 elements and 3 levels: A B B C A C B A C
C .
It is easy to count the number of elements for each level:
tapply(X,X,length).
Now I have another factor Y, which formed a matrix with X:
X| A B B C A C B A C C
Y| B B C C C A A A B B
I wanna count
table() is your friend:
X - factor(scan(what=))
1: A B B C A C B A C C
11:
Read 10 items
Y - factor(scan(what=))
1: B B C C C A A A B B
11:
Read 10 items
table(X)
X
A B C
3 3 4
table(X, Y)
Y
X A B C
A 1 1 1
B 1 1 1
C 1 2 1
Andy
From: zhihua li
hi netters
Suppose I
Sent: Tuesday, June 21, 2005 2:46 PM
Subject: [R] how to count associated factors?
hi netters
Suppose I have a factor X, with 10 elements and 3 levels: A B B C A
C B A C
C .
It is easy to count the number of elements for each level:
tapply(X,X,length).
Now I have another factor Y, which