[Rd] quantile() names
Avi Gross
@v|gro@@ @end|ng |rom ver|zon@net
Tue Dec 15 00:00:48 CET 2020
Question: is the part that Ed Merkle is asking about the change in the
expected NAME associated with the output?
He changed a sort of global parameter affecting how many digits he wants any
compliant function to display. So when he asked for a named vector, the
chosen name was based on his request and limited when possible to two
digits.
x <- 1:1000
temp <- quantile(x, .975)
If you examine temp, you will see it is a vector containing (as it happens)
a single numeric item (as it happens a double) with the value of 975. But
the name associated is a character string with a "%" appended as shown
below:
str(temp)
Named num 975
- attr(*, "names")= chr "98%"
If you do not want a name attached to the vector, add an option:
quantile(x, .975, names=FALSE)
If you want the name to be longer or different, you can do that after.
names(temp)
[1] "98%"
So change it yourself:
temp
98%
975
names(temp) <- paste(round(temp, 3), "%", sep="")
temp
975.025%
975
The above is for illustration with tabs inserted to show what is in the
output. You probably do not need a name for your purposes and if you ask for
multiple quantiles you might need to adjust the above.
Of course if you wanted another non-default "type" of calculation, what Abby
offered may also apply.
-----Original Message-----
From: R-devel <r-devel-bounces using r-project.org> On Behalf Of Abby Spurdle
Sent: Monday, December 14, 2020 4:48 PM
To: Merkle, Edgar C. <merklee using missouri.edu>
Cc: r-devel using r-project.org
Subject: Re: [Rd] quantile() names
The "value" is *not* 975.
It's 975.025.
The results that you're observing, are merely the byproduct of formatting.
Maybe, you should try:
quantile (x, .975, type=4)
Which perhaps, using default options, produces the result you're expecting?
On Tue, Dec 15, 2020 at 8:55 AM Merkle, Edgar C. <merklee using missouri.edu>
wrote:
>
> All,
>
> Consider the code below
>
> options(digits=2)
> x <- 1:1000
> quantile(x, .975)
>
> The value returned is 975 (the 97.5th percentile), but the name has been
shortened to "98%" due to the digits option. Is this intended? I would have
expected the name to also be "97.5%" here. Alternatively, the returned value
might be 980 in order to match the name of "98%".
>
> Best,
> Ed
>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-devel using r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
______________________________________________
R-devel using r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Scanned by McAfee and confirmed virus-free.
Find out more here: https://bit.ly/2zCJMrO
More information about the R-devel
mailing list