r - Sampled the original values and convert it to no. of time it occured in sample -
t has 20 values, c has 20 values 0, 1. interested in t matrix. here have loop, repeating 5 times. every time sel give 20 values. want store there frequency in t.mat. how can required results, resulting table may below table
t <- 1:20
# c <- seq(0:1, 10) t.mat <- array(dim = c(20, 5))
rep <- 5
for(mm in 1:rep){ sel <- sample(1:20, replace = true) tt <- t[sel] # cc <- c[sel] t.mat[, mm] = tt[1:20] # here problem lies, have no clue how
}
the output above may below. t of 20 values, give 6 lines:
t v1 v2 v3 v4 v5 1 1 0 1 0 1 2 0 0 2 0 1 3 0 1 1 1 0 4 1 1 0 0 1 5 2 0 2 1 0 6 0 0 0 1 2
i'm guessing little bit want, it's this:
do.call(cbind, lapply(1:5, function(i) tabulate(sample(t, replace = t), nbins = 20)))
sample
generates samples want, tabulate
counts frequencies (with max specified manually not occur in sample), lapply
iterates procedure 5 times, , do.call(cbind,
binds column.
Comments
Post a Comment