[R] Pairlist of pairlsit assembly howto

Duncan Murdoch murdoch at stats.uwo.ca
Sun Jul 15 16:08:12 CEST 2007


(This isn't important to your question, but those aren't pairlists. 
Pairlists are rarely used in R code, except implicitly in the way R 
stores parsed code.)

On 15/07/2007 10:00 AM, Johannes Graumann wrote:
> Hy guys,
> 
> I'm trying something like this
> 
> minbins <- list()
> for (minute in sequence(3)) {
>         minbins[minute] <- list(data="a",variable="b")
> }

You want to use

minbins[[minute]] <- list(data="a",variable="b")

The difference between [[ ]] and [ ] is that the former works on the 
element, the latter works on a subset.  So your version tried to change 
a subset of length 1 into a subset of length 2, which generates the 
warnings.  You want to assign a list of length 2 as an element of minbins.

Duncan Murdoch
> 
> And it doesn't work ...
> Warning messages:
> 1: number of items to replace is not a multiple of replacement length in:
> minbins[minute] <- list(data = "a", variable = "b") 
> 2: number of items to replace is not a multiple of replacement length in:
> minbins[minute] <- list(data = "a", variable = "b") 
> 3: number of items to replace is not a multiple of replacement length in:
> minbins[minute] <- list(data = "a", variable = "b")
> 
> What am I doing wrong and how to do this properly?
> 
> Thanks, Joh
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list