0

I want to create a loop in which i take de colum names to obtain this columns. Next inside of the loop i want to introduce in a variable with the name of the colum and other things, the result of an operation.

Hear is an example of what i did:

for (i in colnames(data)){
  paste("estim",i,"global",sep=".")<-svyby(~i,by=~Global,dis,svymean,level=0.95, vartype=c("se","ci"),deff=TRUE)
  
}

And i pretend to obtain something like this: estim.1_tv.global which is the name of a variable which contain a data.frame Note: colnames are like: 1_tv, 3_global ....

Mike
  • 3,797
  • 1
  • 11
  • 30
  • 2
    can you provide the packages you used for the code above? – Mike Jan 18 '23 at 14:16
  • Creating variable with indexes in their name is really an anti-pattern when using R. The better way to do something like this is to use a list and apply functions over that list in R. You cannot create variables with `paste()`; that's for building string values. You can turn strings into variable reference with `get/assign` but again that's generally discouraged. The lists are easier to work with. It's unclear where `svyby` comes from but it likely will also not understand using a string value in a formula. – MrFlick Jan 18 '23 at 14:31
  • 1
    It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. – MrFlick Jan 18 '23 at 14:31
  • head(iris,10) dis<-svydesign(ids=~1 ,data=iris) svyby(~`Sepal.Length`,dis,svymean,level=0.95, vartype=c("se","ci"),deff=TRUE) this may be an example of my dataset. I want to create a vairable which is an estimation with the name estimation.name_of_the_colum in it i will introduce the estimation that correspond to each column, so what i expected to obtain is a amount of data.frame which names are estimation.name_of_the_colum and which contain the estimation produce by the svyby. – user21036439 Jan 18 '23 at 15:21

0 Answers0