I have this values (simplify example):
a #class numeric
[1] 1 5 7 6 9
and this array:
res.tot <- array(NA,dim=c(2,1,5))
I need to fill the array res.tot with a values, in this way:
[[1]]
[1]
[1] 1
[2] 1
[[2]]
[1]
[1] 5
[2] 5
...
[[5]]
[1]
[1] 9
[2] 9
in the array res.tot each value of a is repeated 2 times, and each repeated a value occupay a different z dimension.
I tried with for loop in this way:
for (i in 1:length(a)){
res.1 <- data.frame(rep(a[i],2))
res.tot[,,i] <- res.1
}
R tell me:
Error in res.tot.1[, , i] <- res.1 : incorrect number of subscripts
How can do it with for loop or lapply function?