assigning a string to an object without double quotes

前端 未结 2 885
醉话见心
醉话见心 2021-01-23 16:45

I have a string that is built programmatically

 tot=~item1+item2+item3+item4+item5+item6+item7+item8+item9+item10

that I need to wrap in two si

2条回答
  •  南方客
    南方客 (楼主)
    2021-01-23 17:22

    Generate data:

    set.seed(101)
    dat.test <- do.call(data.frame,replicate(6,sample(1:10, 50, replace=TRUE),
                                        simplify=FALSE))
    names(dat.test) <- paste0("s1.item",1:6)
    
    myList1 <- list(scale1.tot=paste0("s1.item",1:6),
                    scale1.sub1=paste0("s1.item",1:3),
                    scale1.sub2=paste0("s1.item",4:6))
    

    I only made one item here, but you could apply across a set of these too, with another *apply call or a for loop ...

    This works (although it gives warnings because the data are trivial)

    fitList <- mapply(function(lhs,rhs) {
               mod <- paste(lhs,"=~",paste(rhs,collapse="+"))
               cfa(mod,data=dat.test)
           },
           names(myList),myList)
    

提交回复
热议问题