[R] align

Achim Zeileis Achim.Zeileis at wu-wien.ac.at
Wed May 18 19:32:29 CEST 2005


On Wed, 18 May 2005 13:29:00 -0400 Omar Lakkis wrote:

> >From the definition of locf
>  
> > locf
> function (x)
> {
>     if (!inherits(x, "its"))
>         stop("function is only valid for objects of class 'its'")
>     y <- x
>     jna <- which(apply(is.na(x), 2, any))
>     for (j in jna) { y[, j] <- y[most.recent(!is.na(y[, j])), j] }
>     return(y)
> }
> 
> Where is the function most.recent? It si not in its.

Yes, it is, but it is not exported. See

R> its::most.recent
Error: 'most.recent' is not an exported object from 'namespace:its'
R> its:::most.recent
function (x) 
{
    if (!is.logical(x)) 
        stop("x must be logical")
    x.pos <- which(x)
    if (length(x.pos) == 0 || x.pos[1] != 1) 
        x.pos <- c(1, x.pos)
    rep(x.pos, c(diff(x.pos), length(x) - x.pos[length(x.pos)] + 
        1))
}
<environment: namespace:its>

Z

> On 5/18/05, Gabor Grothendieck <ggrothendieck at gmail.com> wrote:
> > Check out the 'locf' function in the 'its' package and the 'na.locf'
> > function in the 'zoo' package.
> > 
> > On 5/18/05, Omar Lakkis <uofiowa at gmail.com> wrote:
> > > Is there a function in R that is similar to Splus's align?
> > >
> > > The idea is, if I have a data.frame, or an its object that is like
> > > this:
> > >
> > > 2002-01-03   5
> > > 2002-01-04   NA
> > > 2002-01-05   7
> > > 2002-01-06   NA
> > >
> > > I want to align it by the last value to this:
> > >
> > > 2002-01-03   5
> > > 2002-01-04   5
> > > 2002-01-05   7
> > > 2002-01-06   7
> > >
> > > TITLE:
> > >        Function align
> > >
> > > USAGE:
> > >        align(x, pos, how, error.how, localzone, matchtol, by,
> > >        k.by, week.align, holidays)
> > >
> > > ARGUMENTS:
> > >  x:  argument, no default.
> > >  pos:  argument, no default.
> > >  how:  argument, `default = "NA".'
> > >  error.how:  argument, `default = "NA".'
> > >  localzone:  argument, `default = F.'
> > >  matchtol:  argument, `default = 0.'
> > >  by:  argument, no default.
> > >  k.by:  argument, `default = 1.'
> > >  week.align:  argument, `default = NULL.'
> > >  holidays:  argument, `default = timeDate().'
> > >
> > > DESCRIPTION:
> > >
> > >        Align series object x to new positions
> > >
> > > ______________________________________________
> > > 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
> > >
> >
> 
> ______________________________________________
> 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
>




More information about the R-help mailing list