# [R] indexing??

Petr PIKAL petr.pikal at precheza.cz
Tue Feb 28 16:24:25 CET 2012

```Hi

>
> My algorithm as follows;
> y <- c(1,1,1,0,0,1,0,1,0,0)
> x <- c(1,0,0,1,1,0,0,1,1,0)
>
> n <- length(x)
>
> t <- matrix(cbind(y,x), ncol=2)

Do not use t, it is a function for transposing matrix and after you
redefine it you can get nasty surprise in future.

tt <- cbind(y,x)

is enough

>
> z = x+y
>
> for(j in 1:length(x)) {
> out <- vector("list", )
>
> for(i in 1:10) {
>
> t.s <- t[sample(n,n,replace=T),]

t.s <- tt[sample(n,n,replace=T),]

>
> y.s <- t.s[,1]
> x.s <- t.s[,2]
>
> z.s <- y.s+x.s
>
> out[[i]] <- list(ff <- (z.s), finding=any (y.s==y[j]))

Here you compare vector y.s with one element of y as y.s is set of (0,1)
values y is either 0 or 1, any tests if there is any match so only in rare
case where all values in y.s are 0 and y[something] is 1 you get FALSE

> kk <- sapply(out, function(x) {x\$finding})

finding is (almost) always TRUE therefore kk is TRUE

> ff <- out[! kk]
> }
>

> I tried to find the total of the two vectors as statistic by using
> bootstrap. Finally, I want to get the values which do not contain the
y's
> each elemet. In the algorithm ti is referred to "ff". But i get always
the
> same result ;

I do not understand your intention so it is difficult to help. What is
total of two vectors? sum?

What does it mean "to get values which do not contain y's each element"?

Maybe you shall rethink your code and first try to evaluate each line
separately to see what it does and if the result is same as you intended.

Regards
Petr

> > ff
> list()
> > kk
>  [1] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
> Because, my "y" vector contains only 2 elements, and probably all of the
> bootstrap resamples  include "1", or all of resamples include "0". So I
can
> not find the true matches. Can anyone help me about how to be?
> Thanks.
>
> --
> View this message in context: http://r.789695.n4.nabble.com/indexing-
> tp4428210p4428210.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help