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]]
______________________________________________
[email protected] 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/
______________________________________________
[email protected] 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.