33  numeric

Function base::numeric() creates a numeric scalar or vector, i.e., an R object of S3 class 'numeric'.


The examples in Chapter 33 require

library(groupedHyperframe)
search path & loadedNamespaces on author’s computer
search()
#  [1] ".GlobalEnv"                "package:groupedHyperframe" "package:stats"             "package:graphics"          "package:grDevices"         "package:utils"             "package:datasets"         
#  [8] "package:methods"           "Autoloads"                 "package:base"
loadedNamespaces() |> sort.int()
#  [1] "abind"             "base"              "cli"               "cluster"           "codetools"         "compiler"          "datasets"          "deldir"            "digest"           
# [10] "doParallel"        "dplyr"             "evaluate"          "farver"            "fastmap"           "fastmatrix"        "foreach"           "generics"          "geomtextpath"     
# [19] "GET"               "ggplot2"           "glue"              "goftest"           "graphics"          "grDevices"         "grid"              "gridExtra"         "groupedHyperframe"
# [28] "gtable"            "htmltools"         "htmlwidgets"       "iterators"         "jsonlite"          "knitr"             "lattice"           "lifecycle"         "magrittr"         
# [37] "Matrix"            "matrixStats"       "methods"           "nlme"              "otel"              "parallel"          "patchwork"         "pillar"            "pkgconfig"        
# [46] "polyclip"          "pracma"            "R6"                "RColorBrewer"      "rlang"             "rmarkdown"         "rstudioapi"        "S7"                "scales"           
# [55] "SpatialPack"       "spatstat.data"     "spatstat.explore"  "spatstat.geom"     "spatstat.random"   "spatstat.sparse"   "spatstat.univar"   "spatstat.utils"    "stats"            
# [64] "systemfonts"       "tensor"            "textshaping"       "tibble"            "tidyselect"        "tools"             "utils"             "vctrs"             "viridisLite"      
# [73] "xfun"              "yaml"

Package groupedHyperframe (v0.3.2.20251225) implements the following S3 methods to the class 'numeric' (Table 33.1),

Table 33.1: S3 methods groupedHyperframe::*.numeric (v0.3.2.20251225)
visible generic isS4
cumvtrapz.numeric TRUE groupedHyperframe::cumvtrapz FALSE
kerndens.numeric TRUE groupedHyperframe::kerndens FALSE
visualize_vtrapz.numeric TRUE groupedHyperframe::visualize_vtrapz FALSE

33.1 Kernel Density Estimates

The S3 generic function kerndens() extracts the $y element of a density object. Package groupedHyperframe (v0.3.2.20251225) implements the following S3 methods (Table 33.2),

Table 33.2: S3 methods of groupedHyperframe::kerndens (v0.3.2.20251225)
visible isS4
kerndens.anylist TRUE FALSE
kerndens.hyperframe TRUE FALSE
kerndens.numeric TRUE FALSE
kerndens.ppp TRUE FALSE
kerndens.ppplist TRUE FALSE

The S3 method kerndens.numeric() is simply a wrapper of stats::density.default()$y.

Listing 33.1 finds the kernel density estimates of the eruption time in minutes of the Old Faithful geyser in Yellowstone National Park, Wyoming, USA, in the data frame faithful from the package datasets shipped with R version 4.5.2 (2025-10-31).

Listing 33.1: Example: function kerndens.numeric()
datasets::faithful$eruptions |> 
  kerndens(bw = 'sj') |>
  identical(
    y = datasets::faithful$eruptions |> 
      density(bw = 'sj') |>
      getElement(name = 'y')
  ) |>
  stopifnot()

33.2 Cumulative Average Vertical Height of Trapzoidal Integration

The S3 method cumvtrapz.numeric() (Section 11.1, Table 11.1) has been explained in Section 11.1.

The S3 method visualize_vtrapz.numeric() (Section 11.2, Table 11.2) calculate the cumulative average vertical height of the trapezoidal integration (Section 11.1) under the numeric vectors \(x\) and \(y\) (Listing 11.8, Figure 11.1).