Skip to content

How to determine a subset of a binary strings?

4 messages · jing tang, Berend Hasselman, Enrico Schumann +1 more

#
On 20-02-2012, at 14:15, jing tang wrote:

            
x <- c(0,0,1)
y <- c(0,1,1)
z <- c(0,1,0)

any(x & y)
any(z & y)
any(x & z)

Berend
#
Hi Jing,

I am not sure I got your definition of a "subset" right, but maybe this 
helps.

Regards,
Enrico

x <- c(0,0,1)
y <- c(0,1,1)
z <- c(0,1,0)

## is x a 'subset' of y?
isSubset <- function(x, y) {
     x <- as.logical(x)
     y <- as.logical(y)
     all(y[x] == TRUE)
}

isSubset(x, y)
isSubset(z, y)
isSubset(x, z)

## create all subsets
exampleVec <- c(0,1,1,0,1)
fun <- function(t)
     if (t) 0:1 else 0
expand.grid(lapply(as.list(exampleVec), fun))



Am 20.02.2012 14:15, schrieb jing tang:

  
    
#
On Mon, Feb 20, 2012 at 03:15:53PM +0200, jing tang wrote:
Hi.

Try this

  all(x <= y) # [1] TRUE
  all(z <= y) # [1] TRUE
  all(x <= z) # [1] FALSE

Hope this helps.

Petr Savicky.