[R] a little probleme

Torsten Hothorn Torsten.Hothorn at rzmail.uni-erlangen.de
Wed Jul 4 14:39:10 CEST 2001


> 
> 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.

R> x <- c(1,2,3,3,4,4,5,6)
R> sapply(unique(x), fun <- function(a) x ==  a)
      [,1]  [,2]  [,3]  [,4]  [,5]  [,6]
[1,]  TRUE FALSE FALSE FALSE FALSE FALSE
[2,] FALSE  TRUE FALSE FALSE FALSE FALSE
[3,] FALSE FALSE  TRUE FALSE FALSE FALSE
[4,] FALSE FALSE  TRUE FALSE FALSE FALSE
[5,] FALSE FALSE FALSE  TRUE FALSE FALSE
[6,] FALSE FALSE FALSE  TRUE FALSE FALSE
[7,] FALSE FALSE FALSE FALSE  TRUE FALSE
[8,] FALSE FALSE FALSE FALSE FALSE  TRUE

which is as good as 0, 1 ;-)

Torsten

> Thanks for your help.
> Olivier
> 
> 
> --
> -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
> Olivier MARTIN               phone: (33) 04 76 61 53 55
> Projet IS2                               06 08 67 93 42
> INRIA Rhone-Alpes            fax  : (33) 04 76 61 54 77
> 655, Av. de l'Europe
> Montbonnot                  e-mail:olivier.martin at inrialpes.fr
> 38334 Saint Ismier cedex
> -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
> 
> 
> 

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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