[R] frequence of patterns in a vector
David Winsemius
dwinsemius at comcast.net
Fri May 29 21:10:41 CEST 2009
> x <- c("ABC", "ABC", "ABC", "A02", "ABC", "RCA", "ABC", "ABC")
> table(x)
x
A02 ABC RCA
1 6 1
> table(x)[c("ABC", "A02", "RCA")]
x
ABC A02 RCA
6 1 1
On May 29, 2009, at 2:15 PM, liujb wrote:
>
> Dear R users,
>
> Suppose I have a vector that consists of characters like ABC, A02,
> RCA,
> etc., and there are about 700 of possible characters. For example,
> x <- c("ABC", "ABC", "ABC", "A02", "ABC", "RCA", "ABC", "ABC")
>
> I'd like to get a frequency matrix that looks something like this:
> ABC 6
> A02 1
> RCA 1
>
> I have like 1M numbers of vectors like x (that can have different
> length
> too). How do I do this?
>
> Thank you very much in advance,
>
> Julia
>
David Winsemius, MD
Heritage Laboratories
West Hartford, CT
More information about the R-help
mailing list