Re: [R] vector output loop or function

2011-09-01 Thread Dennis Murphy
Hi: Here's one approach: X1 <- sample(1:4, 10, replace = TRUE, prob = c(0.4, 0.2, 0.2, 0.2)) foo <- function(x) { m <- matrix(NA, nrow = length(x), ncol = length(x)) m[, 1] <- x idx <- seq_len(length(x)) for(j in idx[-1]) { k <- sample(idx, 2) x <- replace(x, k, 5)

[R] vector output loop or function

2011-08-31 Thread Nilaya Sharma
Dear all Sorry for simple question: I want to put the following option into look as number of X is large 1000 variables X1 <- sample(c(1,2, 3, 4),10, replace = T, prob = c(0.4, 0.2, 0.2, 0.2)) cv1 <- round(runif(2, 1, 10)) # X2 is copy of X1 X2 <- X1 # now X2 is different in cv1 random posi