Skip to content
Prev 319487 / 398506 Next

Bootstrap encounter histories data

Hello,

One more thing, if you have the data as strings of states/space/group, 
you can split it in vectors state/group with

# This is your data example
x <- c(
"1100222101 1",
"0000020010 3",
"0010101022 2"
)

mat <- do.call(rbind, strsplit(x, " "))


But this creates a matrix, so you'll need to revise the function as

fun <- function(x){
	f <- function(y){
		idx <- sample(NROW(y), NROW(y), replace = TRUE)
		y[idx, ]
	}
	sp <- split(as.data.frame(x), x[, 2])
	res <- do.call(rbind, lapply(sp, f))
	rownames(res) <- seq_len(nrow(res))
	res
}

fun(mat)


Hope this helps,

Rui Barradas

Em 14-03-2013 11:34, Rui Barradas escreveu: