integerOrNumeric-class: Union of a Integer and a Numeric

Description Author(s) Examples

Description

Allows the same S4 subsetting function to be specified for object[i] and object[i:j], where i and j are integers.

Author(s)

Dario Strbenac

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
  setClass("Container", representation(scores = "numeric"))
  setMethod("[", c("Container", "integerOrNumeric", "missing", "ANY"),
           function(x, i, j, ..., drop = TRUE)
           {
             new("Container", scores = x@scores[i])
           })
           
  dataset <- new("Container", scores = 1:10)
  dataset[1] # 1 is numeric.
  dataset[4:6] # 4:6 is a sequence of integers.

ClassifyR documentation built on Nov. 8, 2020, 6:53 p.m.