Skip to content
Back to formatted view

Raw Message

Message-ID: <x24qyw8xo6.fsf@biostat.ku.dk>
Date: 2003-09-28T20:28:03Z
From: Peter Dalgaard
Subject: frustration with ave()
In-Reply-To: <Pine.SOL.4.58.0309281545440.26147@millipede.gpcc.itd.umich.edu>

Thomas W Blackwell <tblackw at umich.edu> writes:

> Ed  -
> 
> You seem to have encountered a bug.  I can reproduce Ed's difficulty
> in a completely artificial example in which there are unused levels :
> 
> tmp <- factor(rep(seq(10), seq(10)))     #  length(tmp) # [1] 55
> ave(seq(50), tmp[-seq(5)])               #  gives NA in rows 32-50
> 
> I would consider this to be incorrect behavior for the function
> ave().  For the base package maintainers, I would suggest modifying
> the definition of  ave()  so that the line involving  as.factor()
> reads :
> 
>          l[[i]] <- li <- as.factor(l[[i]][,drop=T]) .

A minimal version of the same effect would be

> ave(1:2,factor(2:3,levels=1:3))
[1]  2 NA

Your fix looks sensible to me, but it might be better with simply

>          l[[i]] <- li <- factor(l[[i]]) 


-- 
   O__  ---- Peter Dalgaard             Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics     2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)             FAX: (+45) 35327907