Here is just small example (not exactly, but similar issue) I am trying to do:
test1 <- data.frame (matrix(sample( c(1,2,3,NA),15, replace = TRUE), 5,3))
X1 X2 X3
1 NA NA 2
2 1 3 3
3 NA 1 NA
4 NA 2 NA
5 2 NA 3
I want loop the process with 5 different seeds with 1:chr. I want to then combine the resulting dataframe in column wise:
X1 X2 X3 X1.1 X2.1 X3.1 ... so on (r will accept two variables with same name)
X1 X2 X3 X1 X2 X3 X1 X2 X3 X1 X2 X3 X1 X2 X3
1 NA NA 2 1 NA NA 2 1 NA NA 2 1 NA NA 2
2 1 3 3 2 1 3 3 2 1 3 3 2 1 3 3
3 NA 1 NA 3 NA 1 NA 3 NA 1 NA 3 NA 1 NA
4 NA 2 NA 3 NA 1 NA 3 NA 1 NA 3 NA 1 NA
5 2 NA 33 NA 1 NA 3 NA 1 NA 3 NA 1 NA
Here is my trial:
nchr = 1:5
seed <- round(runif(nchr)*1000000)
funct <- function (x){
set.seed <- seed[x]
test1 <- data.frame (matrix(sample( c(1,2,3,NA),15, replace = TRUE), 5,3))
return (test1)
}
sapply(nchr, funct)
How can I achieve my goal?
1 Answer