Browse Source

length and subset

master
boB Rudis 5 years ago
parent
commit
2bbe5b2c92
No known key found for this signature in database GPG Key ID: 1D7529BE14E2BBA9
  1. 2
      NAMESPACE
  2. 24
      R/create.R
  3. 6
      man/td_total_count.Rd
  4. 12
      man/td_value_at.Rd

2
NAMESPACE

@ -1,5 +1,7 @@
# Generated by roxygen2: do not edit by hand
S3method("[",tdigest)
S3method(length,tdigest)
S3method(print,tdigest)
S3method(quantile,tdigest)
export("%>%")

24
R/create.R

@ -109,6 +109,7 @@ td_create <- function(compression=100) {
#' td <- td_create(10)
#' td_add(td, 0, 1)
#' td_total_count(td)
#' length(td)
td_total_count <- function(td) {
stopifnot(inherits(td, "tdigest"))
stopifnot(!is_null_xptr(td))
@ -144,6 +145,9 @@ td_add <- function(td, val, count) {
#' td_add(10, 1)
#'
#' td_value_at(td, 0.1)
#' td_value_at(td, 0.5)
#' td[0.1]
#' td[0.5]
td_value_at <- function(td, q) {
stopifnot(inherits(td, "tdigest"))
stopifnot(!is_null_xptr(td))
@ -176,3 +180,23 @@ td_merge <- function(from, into) {
stopifnot(!is_null_xptr(into))
.Call("Rtd_merge", from=from, into=into, PACKAGE="tdigest")
}
#' @rdname td_total_count
#' @param x a tdigest object
#' @export
length.tdigest <- function(x) {
td_total_count(x)
}
#' @rdname td_value_at
#' @param x a tdigest object
#' @param i quantile (range 0:1)
#' @param ... unused
#' @export
`[.tdigest` <- function(x, i, ...) {
if (length(x) == 0) return(NULL)
i <- as.double(i[1])
if ((i<=0) || (i>1)) return(NULL)
td_value_at(x, i)
}

6
man/td_total_count.Rd

@ -2,12 +2,17 @@
% Please edit documentation in R/create.R
\name{td_total_count}
\alias{td_total_count}
\alias{length.tdigest}
\title{Total items contained in the t-digest}
\usage{
td_total_count(td)
\method{length}{tdigest}(x)
}
\arguments{
\item{td}{t-digest object}
\item{x}{a tdigest object}
}
\description{
Total items contained in the t-digest
@ -16,4 +21,5 @@ Total items contained in the t-digest
td <- td_create(10)
td_add(td, 0, 1)
td_total_count(td)
length(td)
}

12
man/td_value_at.Rd

@ -2,14 +2,23 @@
% Please edit documentation in R/create.R
\name{td_value_at}
\alias{td_value_at}
\alias{[.tdigest}
\title{Return the value at the specified quantile}
\usage{
td_value_at(td, q)
\method{[}{tdigest}(x, i, ...)
}
\arguments{
\item{td}{t-digest object}
\item{q}{quantile (range 0:1)}
\item{x}{a tdigest object}
\item{i}{quantile (range 0:1)}
\item{...}{unused}
}
\description{
Return the value at the specified quantile
@ -21,4 +30,7 @@ td_add(td, 0, 1) \%>\%
td_add(10, 1)
td_value_at(td, 0.1)
td_value_at(td, 0.5)
td[0.1]
td[0.5]
}

Loading…
Cancel
Save