12  data.frame

The examples in Chapter 12 require that the search path contains the following namespaces,

library(groupedHyperframe)

Function base::data.frame() creates a data frame, i.e., an R object of S3 class 'data.frame'. In addition to the existing S3 method dispatches spatstat.geom::*.data.frame (v3.6.0.3, Listing 12.1) and spatstat.univar::*.data.frame (v3.1.4.1, Listing 12.2),

Listing 12.1: Existing S3 method dispatches spatstat.geom::*.data.frame
Code
suppressPackageStartupMessages(library(spatstat.geom))
methods(class = 'data.frame', all.names = TRUE) |> 
  attr(which = 'info', exact = TRUE) |>
  subset.data.frame(subset = from == 'spatstat.geom')
#                          visible          from       generic  isS4
# as.hyperframe.data.frame    TRUE spatstat.geom as.hyperframe FALSE
# as.im.data.frame            TRUE spatstat.geom         as.im FALSE
# as.owin.data.frame          TRUE spatstat.geom       as.owin FALSE
# as.ppp.data.frame           TRUE spatstat.geom        as.ppp FALSE
# as.psp.data.frame           TRUE spatstat.geom        as.psp FALSE
# multiplicity.data.frame     TRUE spatstat.geom  multiplicity FALSE
Listing 12.2: Existing S3 method dispatches spatstat.univar::*.data.frame
Code
suppressPackageStartupMessages(library(spatstat.univar))
methods(class = 'data.frame', all.names = TRUE) |> 
  attr(which = 'info', exact = TRUE) |>
  subset.data.frame(subset = from == 'spatstat.univar')
#                      visible            from   generic  isS4
# uniquemap.data.frame    TRUE spatstat.univar uniquemap FALSE

Package groupedHyperframe implements the following S3 method dispatches to the class 'data.frame' (Listing 12.3, Table 12.1),

Listing 12.3: Table: S3 method dispatches groupedHyperframe::*.data.frame
Code
methods2kable(class = 'data.frame', package = 'groupedHyperframe', all.names = TRUE)
Table 12.1: S3 method dispatches groupedHyperframe::*.data.frame (v0.3.0.20251020)
visible from generic isS4
as.groupedHyperframe.data.frame TRUE groupedHyperframe groupedHyperframe::as.groupedHyperframe FALSE

12.1 Create groupedHyperframe

The S3 generic function as.groupedHyperframe() converts objects of various classes into a groupedHyperframe (Chapter 16).

The S3 method dispatch as.groupedHyperframe.data.frame() converts a data.frame with substantial amount of duplicated information into a groupedHyperframe. The example in Chapter 2, Listing 2.1, Listing 2.2,

  1. inspects the input data frame lung0 by the user-specified (nested) grouping structure, e.g., image_id nested in patient_id;
  2. identifies the input data.frame column(s) with non-identical elements within the lowest group, e.g., the numeric column lung0$hladr and the factor column lung0$phenotype;
  3. converts these column(s) into the hypercolumn(s) of the output groupedHyperframe, e.g., the numeric-hypercolumn lung_g$hladr and the factor-hypercolumn lung_g$phenotype. Each row of the output groupedHyperframe represents the lowest group of the nested grouping structure.