[R] Concatenation, was Re: Physical Units in Calculations

hadley wickham h.wickham at gmail.com
Mon Apr 13 14:40:32 CEST 2009


On Mon, Apr 13, 2009 at 4:15 AM, Peter Dalgaard
<p.dalgaard at biostat.ku.dk> wrote:
> Stavros Macrakis wrote:
>
>> It would of course be nice if the existing difftime class could be fit
>> into this, as it is currently pretty much a second-class citizen.  For
>> example, c of two time differences is currently a numeric vector,
>> losing its units (hours, days, etc.) completely.
>
> That's actually a generic feature/issue of c(). We also have
>
>> c(factor(1),factor(3))
> [1] 1 1
>> library(survival)
> Loading required package: splines
>> c(Surv(1,T),Surv(2,F))
> [1] 1 1 2 0
>
> and similar issues apply to rbind() of data frames,
>
>> rbind(data.frame(s=Surv(1,T)),data.frame(s=Surv(2,F)))
>  s.time s.status
> 1      1        1
> 2      2        0
>
> There is some potential for redesigning this, using a concat() generic which
> should do the Right Thing for all classed vector-like objects. (There is
> such a function in Splus, but I don't their data frame code is using it.)

It would also be nice to have a strip_attr function for those times
you want to be explicit about using c to remove attributes.

Hadley

-- 
http://had.co.nz/



More information about the R-help mailing list