[R] Modifying dim attribute of elements of a list

Giovanni Petris GPetris at uark.edu
Fri Oct 17 20:39:28 CEST 2003


I've found the solution to my problem (see below), although it looks
somewhat ugly: 

sim <- c('simMeans','simVars','simWeights')
indexTable <- table(modelIndex)
for (i in sim) {
    assign(tmp <- paste(i,'By',sep=''),split(get(i), modelIndex))
    lapply(seq(along=indexTable), function(j)
           eval(parse(text=paste('dim(',tmp,'[[',j,']])','<<-','c(indexTable[',j,'],K)'))))
}

> Date: Fri, 17 Oct 2003 11:50:29 -0500 (CDT)
> From: Giovanni Petris <GPetris at uark.edu>
> Sender: r-help-bounces at stat.math.ethz.ch
> Precedence: list
> 
> 
> I am creating lists of vectors withing a loop. I also would like to
> change the dim attribute to the vectors in order to make them
> matrices. 
> 
> I have tried the following, but it doesn't work...
> 
> > sim <- c('simMeans','simVars','simWeights')
> > indexTable <- table(modelIndex)
> > for (i in sim) {
> +     assign(tmp <- paste(i,'By',sep=''),split(get(i), modelIndex))
> +     lapply(seq(along=indexTable),function(j) attr(get(tmp)[[j]],'dim') <<- c(indexTable[j],K))
> + }
> Error in FUN(X[[1]], ...) : couldn't find function "get<-"
> In addition: Warning message: 
> argument lengths differ in: split(x, f) 
> 
> Any suggestions will be appreciated. 
> Thanks
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help
> 
> 
>




More information about the R-help mailing list