0

I want to use a loop to run an amount of function svyby which all of then have the same argument except the first one (which you pass to ~), which are de different columns of a data.frame.

Using the iris table installed on r This is what i try: head(iris,10) dis<-svydesign(ids=~1 ,data=iris) names<-colnames(iris) a<-c() for(i in 1:length(names)){ a[i]<-svyby(~names[i],dis,svymean,level=0.95, vartype=c("se","ci"),deff=TRUE) } This produce me this error: Error in contrasts<-(*tmp*, value = contr.funs[1 + isOF[nn]]) : contrasts can be applied only to factors with 2 or more levels

Moreover, svyby will produce a data.frame and i want to create a list or a group of elements which names are save in "a", and when i use the loop y obtain it and introduce the result of svyby. Thanks in avance for the help an the effort.

The problema is similar to this: R Looping through in survey package

The only difference with this problem is that the object that i pass to ~ has to be the name of a colum. I try to obtain this name such as in this page but svyby not admit it cause the names of teh columns appear like "setosa" and it is needed to appear like setosa.

0 Answers0