concatenate - Loop with variables

#1
Hello,
I have a data frame. I generated some dummies using a simple loop.
However, I can't concatenate the dummies to the original data frame.

Code:
yyy=max(region)

for (i in 1:yyy) {

   nam=paste("region",i,sep="")

   assign(nam,as.numeric(cise>0 & region==i))

  data=cbind(data,paste("region",i,sep="" ))

}
The last line in this code is obviously wrong, but I haven't found a similar task on my web searches.
Thanks for your time and interest
 

Dason

Ambassador to the humans
#2
I think your entire approach is probably done better in some other way but it's hard to give explicit advice on what exactly you should be doing instead without a reproducible example.
 
#3
Hi,
I need to obtain a set of dummies. Then I need to concatenate every one of them I generated in my simple loop. And that's what I can't figure it out.

Code:
c=seq(from=1, to=200)
region=round(runif(200,min=1,max=10),0)
cise=round(runif(200,min=0,max=6),0)
data=cbind(c,region,cise)
attach(data)
data


for (i in 1:15) {
  nam=paste("region",i,sep="")
  assign(nam,as.numeric(cise>0 & region==i))
  data=cbind(data,glue::glue('region'i))
}
The big mistake I make is when I try to concatenate all the the vectors (region dummies) to the data frame (data).
The reason why I need the cbind or similar inside the loop is because in the near future I will need to use a loop using the same approach to the survey package. I mean using a differents dummies to compute confidence intervals.

If you think that I can perform a repetitive task for different vector not using a loop style code, please, recommend me the package for reading info about it.
Thanks again.
 
#4
The reason why I need the cbind or similar inside the loop is because in the near future I will need to use a loop using the same approach to the survey package. I mean using a differents dummies to compute confidence intervals.
Forget this. With "lapply" I did it.

By the way, I still need to concatenate the dummies to the original data frame...