Skip to contents

This function allows subsetting of 'nfd' objects using the `[ ]` operator. The result of the subsetting operation is returned as an 'nfd' object.

Usage

# S3 method for class 'nfd'
x[...]

Arguments

x

An object of class `nfd`.

...

Further arguments passed to or from other methods.

i

(optional) Numeric, logical, or character vector specifying the rows to extract.

j

(optional) Numeric, logical, or character vector specifying the columns to extract.

drop

Logical indicating whether to drop dimensions (default is `FALSE`).

Value

An `nfd` object containing the subset of the original data.

Examples

# Define the 'nfd' class constructor
nfd <- function(data) {
  if (!is.matrix(data) && !is.array(data)) {
    stop("Input must be a matrix or an array.")
  }
  class(data) <- c("nfd", class(data))
  return(data)
}

# Create an 'nfd' object
mat <- matrix(1:12, nrow = 3, ncol = 4)
nfd_obj <- nfd(mat)

# Subset rows and columns
subset_nfd <- nfd_obj[1:2, 3:4]
print(subset_nfd)
#> An object of class 'nfd':
#> Dimensions: 2 x 2
#> Classes: nfd, matrix, array
#> 
#> First few entries:
#>      [,1] [,2]
#> [1,]    7   10
#> [2,]    8   11
print(class(subset_nfd))  # Should include 'nfd'
#> [1] "nfd"    "matrix" "array"