14  data.frame

Function base::data.frame() creates a data frame, i.e., an R object of S3 class 'data.frame'.

Listing 14.1, Listing 14.2 summarize the S3 methods for the class '.data.frame' in the spatstat.* family of packages,

Listing 14.1: Existing S3 methods spatstat.geom::*.data.frame
Code
suppressPackageStartupMessages(library(spatstat.geom))
.S3methods(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 14.2: Existing S3 methods spatstat.univar::*.data.frame
Code
suppressPackageStartupMessages(library(spatstat.univar))
.S3methods(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

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

library(groupedHyperframe)

Package groupedHyperframe (v0.3.2) implements the following S3 methods to the class 'data.frame' (Table 14.1),

Table 14.1: S3 methods groupedHyperframe::*.data.frame (v0.3.2)
visible from generic isS4
as.groupedHyperframe.data.frame TRUE groupedHyperframe groupedHyperframe::as.groupedHyperframe FALSE

14.1 Create groupedHyperframe

The S3 generic function as.groupedHyperframe() converts objects of various classes into a grouped hyper data frame (groupedHyperframe, Chapter 19). Package groupedHyperframe (v0.3.2) implements the following S3 methods (Table 14.2),

Table 14.2: S3 methods groupedHyperframe::as.groupedHyperframe.* (v0.3.2)
visible isS4
as.groupedHyperframe.data.frame TRUE FALSE
as.groupedHyperframe.groupedData TRUE FALSE
as.groupedHyperframe.hyperframe TRUE FALSE

The S3 method as.groupedHyperframe.data.frame() converts a data frame with substantial amount of duplicated information into a grouped hyper data frame. 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.