Skip to content
Prev 290729 / 398500 Next

random sample from list

Hello,
You are sampling from the length of z_nonna, with no guarantee that they are
indices to unique list elements.

Try this.

# First, create some fake data.
n <- 1000
z <- list()
set.seed(1234)
for(i in 1:n) z[[i]] <- sample(letters, 2)

# Now sample some unique elements from it.
iz <- which(!duplicated(z))
iz <- sample(iz, 100) # sample from the non-duplicate indices.
z[iz]

Hope this helps,

Rui Barradas


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