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 positions
X2[cv1] <- 5
cv2 <- round(runif(2, 1, 10))
# X3 is copy of X2
X3 <- X2
X3[cv2] <- 5
.
So on till X10
mydf <- data.frame ( X1, X2, X3, X4, X5, X6, X7, X8, X9, X10)
The basic idea is the X2 is like X1 but is different at two positions where
the normal value is replaced with 5, the position is defined by cv1 . The
process is repeated till the last variable.
I tried several way. One of unsuccessful function:
v = 2:10
mufun3 <- function(v, x){
x[,v] <- x[,v-1]
cv1 <- round(runif(3, 1, 10))
}
mufun3 (v, X1)
Thank you for the help
NIL
[[alternative HTML version deleted]]
______________________________________________
[email protected] 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.