[R] a little probleme

Thomas Lumley tlumley at u.washington.edu
Wed Jul 4 18:20:14 CEST 2001

On Wed, 4 Jul 2001, Olivier Martin wrote:

> Hi all,
> i would like to find the best way to resolve the following problem.
> Suppoose i have a vector x of length N with k different elements.
> length(x)=N
> u<-unique(x)
> length(u)=k
> I would like to get a matrix M with k rows and N columns such that:
> in each line i (i=1,...,k), which(x%in%u[i]) is equal to 1 and 0 else.

Another solution


(the +0 just converts it to numeric rather than TRUE/FALSE)


Thomas Lumley			Asst. Professor, Biostatistics
tlumley at u.washington.edu	University of Washington, Seattle

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