Learn R Programming

spatstat.geom (version 3.6-1)

Extract.hyperframe: Extract or Replace Subset of Hyperframe

Description

Extract or replace a subset of a hyperframe.

Usage

# S3 method for hyperframe
[(x, i, j, drop, strip=drop, ...)
  # S3 method for hyperframe
[(x, i, j) <- value
  # S3 method for hyperframe
$(x, name)
  # S3 method for hyperframe
$(x, name) <- value
  # S3 method for hyperframe
[[(x, ...)
  # S3 method for hyperframe
[[(x, i, j) <- value

Arguments

Value

A hyperframe (of class "hyperframe").

Details

These functions extract a designated subset of a hyperframe, or replace the designated subset with another hyperframe.

The function [.hyperframe is a method for the subset operator [ for the class "hyperframe". It extracts the subset of x specified by the row index i and column index j.

The argument drop determines whether the array structure will be discarded if possible. The argument strip determines whether the list structure in a row or column or cell will be discarded if possible. If drop=FALSE (the default), the return value is always a hyperframe or data frame. If drop=TRUE, and if the selected subset has only one row, or only one column, or both, then

  • if strip=FALSE, the result is a list, with one entry for each array cell that was selected.

  • if strip=TRUE,

    • if the subset has one row containing several columns, the result is a list or (if possible) an atomic vector;

    • if the subset has one column containing several rows, the result is a list or (if possible) an atomic vector;

    • if the subset has exactly one row and exactly one column, the result is the object (or atomic value) contained in this row and column.

The function [<-.hyperframe is a method for the subset replacement operator [<- for the class "hyperframe". It replaces the designated subset with the hyperframe value. The subset of x to be replaced is designated by the arguments i and j as above. The replacement value should be a hyperframe with the appropriate dimensions, or (if the specified subset is a single column) a list of the appropriate length.

The function $.hyperframe is a method for $ for hyperframes. It extracts the relevant column of the hyperframe. The result is always a list (i.e. equivalent to using [.hyperframe with strip=FALSE).

The function $<-.hyperframe is a method for $<- for hyperframes. It replaces the relevant column of the hyperframe. The replacement value should be a list of the appropriate length.

The functions [[.hyperframe and [[<-.hyperframe are methods for [[ and [[<-.hyperframe for hyperframes. They are analogous to [[.data.frame and [[<-.data.frame in that they can be used in different ways:

  • when [[.hyperframe or [[<-.hyperframe are used with a single index, as in x[[n]] or x[[n]] <- value, they index the hyperframe as if it were a list, extracting or replacing a column of the hyperframe.

  • when [[.hyperframe or [[<-.hyperframe are used with two indices, as in x[[i,j]] or x[[i,j]] <- value, they index the hyperframe as if it were a matrix, and can only be used to extract or replace one element.

See Also

hyperframe

Examples

Run this code
  h <- hyperframe(X=list(square(1), square(2)), Y=list(sin, cos))
  h
  h[1, ]
  h[1, ,drop=TRUE]
  h[ , 1]
  h[ , 1, drop=TRUE]
  h[1,1]
  h[1,1,drop=TRUE]
  h[1,1,drop=TRUE,strip=FALSE]
  h[1,1] <- list(square(3))
  # extract column
  h$X
  # replace existing column
  h$Y <- list(cells, cells)
  # add new column
  h$Z <- list(tan, exp)
  #
  h[["Y"]]
  h[[2,1]]
  h[[2,1]] <- square(3)

Run the code above in your browser using DataLab