[R] variable pattern
Prof Brian D Ripley
ripley at stats.ox.ac.uk
Mon Feb 5 19:38:45 CET 2001
On Mon, 5 Feb 2001, Jan Seidel wrote:
> Suppose I've got p vectors x1, ..., xp each of length n merged in a (n x
> p)-matrix X.
> Now I want to calculate the number of distinct values of row-vectors
> (x_i1, ..., x_ip).
> Is there a way to do this in R? Thanks in advance,
Completely distinct row vectors? Take a look at the code of
merge.data.frame. Something like
bx <- matrix(as.character(a), nrow(a))
bx <- drop(apply(bx, 1, function(x) paste(x, collapse = "\r")))
length(unique(bx))
This turns each row into a single character string, and counts the unique
ones.
--
Brian D. Ripley, ripley at stats.ox.ac.uk
Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel: +44 1865 272861 (self)
1 South Parks Road, +44 1865 272860 (secr)
Oxford OX1 3TG, UK Fax: +44 1865 272595
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list