First, I want to simulate let 20 data sets using for loop. Once these data sets are generated, I want to add a new variable (column) to these data sets on each iteration. The new variable is the sum of all columns of each data set.

```
library(bindata)
set.seed(485)
cor.mat = diag(1, nrow = 3)
for (i in 1:nrow(cor.mat)) {
for (j in 1:ncol(cor.mat)) {
if (i > j) cor.mat[i, j] = runif(1, 0.2, 0.7)
cor.mat[j, i] = cor.mat[i, j]
}
}
N=20
mydata = list()
var = list()
mydata.new = list()
for(i in 1:N){
mydata[[i]] = rmvbin(n=10,margprob=rep(0.4,3),bincorr = cor.mat)
var[[i]] = mydata[,1][i]+mydata[,2][i]+mydata[,3][i] # I need your help here
mydata.new[[i]] = cbind(mydata,var) # Again I need your help here
}
```

I expect 20 mydata.new data sets to be like the following.

```
v1 v2 v3 var
0 1 0 1
1 0 0 1
1 1 1 3
0 0 0 0
1 0 1 2
```

Thank you in advance!

If I understand correctly, you want this: