[R] indexing??

helin_susam helin.susam at gmail.com
Tue Feb 28 20:42:32 CET 2012

```Dear Petr Savicky,

Actually, this is based on jackknife after bootstrap algorithm. In summary,

I have a data set, and I want to compute some values by using this
algorithm.

Firstly, using bootstrap, I create some bootstrap re-samples. This step O.K.
Then, for each data point within these re-samples, I want to get a subset
which do not contain that data point ( this point would be any point of the
original data set), in general, if B is the number of bootstrap-resamples,
there are B/e resamples obtained for each data point.  And finally, I want
to calculate some values for each of this re samples.

Explanation of my algorithm;

#My data set: (x and y)
y <- c(1,2,3,4,5,6,7,8,9,10)
x <- c(1,0,0,1,1,0,0,1,1,0)

n <- length(x)

t <- matrix(cbind(y,x), ncol=2)

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),] # Here is the bootstrap step

y.s <- t.s[,1]
x.s <- t.s[,2]

z.s <- y.s+x.s
nn <- sum (z.s)  # For example, I want to calculate this value

out[[i]] <- list(ff <- (nn), finding=any (y.s==y[j])) # I get the mentioned
subset in here
kk <- sapply(out, function(x) {x\$finding})
ff <- out[! kk]
}
}

I obtained the following results of an experiment;

> kk
[1] FALSE  TRUE  TRUE FALSE  TRUE  TRUE FALSE  TRUE  TRUE  TRUE
> ff
[[1]]
[[1]][[1]]
[1] 47

[[1]]\$finding
[1] FALSE

[[2]]
[[2]][[1]]
[1] 46

[[2]]\$finding
[1] FALSE

[[3]]
[[3]][[1]]
[1] 52

[[3]]\$finding
[1] FALSE

It is easy to do when "y" contains different elements.  "out[[i]] <- list(ff
<- (nn), finding=any (y.s==y[j]))"

But, when y contains the same element, doing this process can be confusing
confusing..
Because, (y <- c(1,1,1,0,0,1,0,1,0,0)) for y[j] when j= 1 there are some
other 1 in the y.  Is there something special about the y to an j ?
Thanks

--
View this message in context: http://r.789695.n4.nabble.com/indexing-tp4428210p4429280.html
Sent from the R help mailing list archive at Nabble.com.

```