Hi,
I was trying to do a cluster sampling but came across this error: Error in
xj[i] : only 0's may be mixed with negative subscripts. What is the cause
and how to get around? Thank you for your help!
Here is the code:
#simulate some data
y <- rnorm(20)
x <- rnorm(20)
z <- rep(1:5, 4)
w <- rep(1:4, each=5)
dd <- data.frame(id=z, cluster=w, x=x, y=y)
clusters <- split(dd, dd$cluster) #split into clusters
k <- length(clusters) #length of clusters
# This function generates a cluster sample
clsamp <- function() dd[unlist(clusters[sample.int(k, k, replace = TRUE)],
use.names = TRUE), ]
clsamp()
I got this error: Error in xj[i] : only 0's may be mixed with negative
subscripts.
Best,
Chao
[[alternative HTML version deleted]]
______________________________________________
[email protected] mailing list -- To UNSUBSCRIBE and more, see
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.