How to determine a subset of a binary strings?

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

How to determine a subset of a binary strings?

jing tang
Hi,

I need some neat ways of determing a subset of binary strings. For example,
x=c(0,0,1), y=c(0,1,1), z=c(0,1,0). So x is a subset of y and z is also a
subset of y, but x is not a subset of z.

I tried to search R functions and packages but no hits. Any ideas?

 

Best,

Jing

 

--

Jing Tang, PhD

Senior Researcher

Finnish Institute of Molecular Medicine (FIMM)

FI-00014 University of Helsinki

Finland

 

 


        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: How to determine a subset of a binary strings?

Berend Hasselman

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

> Hi,
>
> I need some neat ways of determing a subset of binary strings. For example,
> x=c(0,0,1), y=c(0,1,1), z=c(0,1,0). So x is a subset of y and z is also a
> subset of y, but x is not a subset of z.
>
> I tried to search R functions and packages but no hits. Any ideas?

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

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: How to determine a subset of a binary strings?

Enrico Schumann
In reply to this post by jing tang

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:

> Hi,
>
> I need some neat ways of determing a subset of binary strings. For example,
> x=c(0,0,1), y=c(0,1,1), z=c(0,1,0). So x is a subset of y and z is also a
> subset of y, but x is not a subset of z.
>
> I tried to search R functions and packages but no hits. Any ideas?
>
>
>
> Best,
>
> Jing
>
>
>
> --
>
> Jing Tang, PhD
>
> Senior Researcher
>
> Finnish Institute of Molecular Medicine (FIMM)
>
> FI-00014 University of Helsinki
>
> Finland
>
>
>
>
>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

--
Enrico Schumann
Lucerne, Switzerland
http://nmof.net/

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: How to determine a subset of a binary strings?

Petr Savicky
In reply to this post by jing tang
On Mon, Feb 20, 2012 at 03:15:53PM +0200, jing tang wrote:
> Hi,
>
> I need some neat ways of determing a subset of binary strings. For example,
> x=c(0,0,1), y=c(0,1,1), z=c(0,1,0). So x is a subset of y and z is also a
> subset of y, but x is not a subset of z.
>
> I tried to search R functions and packages but no hits. Any ideas?

Hi.

Try this

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

Hope this helps.

Petr Savicky.

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.