Hello, > > #Here is how I have tried to sample but it is not sampling from the right > part of the list > > bg<- z_nonna[sample(1:length(z_nonna), 5000, replace=FALSE)] >
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. ______________________________________________ R-help@r-project.org 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.