[R] Confusion in 'quantile' and getting rolling estimation of sample quantiles

Gabor Grothendieck ggrothendieck at gmail.com
Sun Jan 17 07:04:42 CET 2010


There is no quantile method defined for zoo objects so it falls
through to the default method but that method does not work for zoo
objects.  Try this:

set.seed(123)
rn <- rnorm(500)
quantile(rn, 0.8)
quantile(coredata(zoo(rn)), 0.8)

In the second question the error message tells you what the problem
is.  FUN is supposed to be a function but a vector of numbers has been
supplied rather than a function.  Try:

uprange=rollapply(x,width=10,FUN=function(x)quantile(x,0.8),align='right')

On Sat, Jan 16, 2010 at 10:08 PM, Saji Ren <saji.ren at gmail.com> wrote:
>
> Guys:
>
> 1).When I using the 'quantile' function, I get really confused. Here is what
> I met:
>
>> x<-zoo(rnorm(500,0,1))
>> quantile(x,0.8)
>     400
> 1.060258
>
>> c=rnorm(500,0,1)
>> quantile(c,0.8)
>      80%
> 0.9986075
>
> why do the results display different? Is that because of the different type
> of the class?
>
> 2).And I want to use the 'rollapply' function to compute a rolling
> estimation of the sample quantile.
> the command i used is below:
>
>> uprange=rollapply(x,width=10,FUN=quantile(x,0.8),align='right')
> Here the 'x' is the one generated above in 1).
> And the R told me:
>
> "mistakes in match.fun(FUN) :
>  'quantile(x, 0.8)' is not a function, character or symbol"
>
> Can anyone help? Thank you in advanced.
>
>
> -----
> ------------------------------------------------------------------
> Saji Ren
> from Shanghai China
> GoldenHeart Investment Group
> ------------------------------------------------------------------
> --
> View this message in context: http://n4.nabble.com/Confusion-in-quantile-and-getting-rolling-estimation-of-sample-quantiles-tp1015893p1015893.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at r-project.org 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