drop: Drop redundant information

dropR Documentation

Drop redundant information

Description

Coerce disord objects to vector when this makes sense

Usage

drop(x)
allsame(x)

Arguments

x

disord object

Details

If one has a disord object all of whose elements are identical, one usually wants to drop the disord attribute and coerce to a vector. This can be done without breaking disordR discipline. Function disord() takes a drop argument, defaulting to TRUE, which drops the disord class from its return value if all the elements are the same.

Similarly, function drop() takes a disord object and if all elements are identical it returns the elements in the form of a vector. Some extraction methods take a drop argument, which does the same thing if TRUE. This is only useful for disord objects created with disord(...,drop=FALSE)

The drop functionality is conceptually similar to the drop argument of base R's array extraction, as in

     a <- matrix(1:30,5,6)
     a[1,,drop=TRUE]
     a[1,,drop=FALSE]
   

Function allsame() takes a vector and returns TRUE if all elements are identical.

Value

Function drop() returns either a vector or object of class disord as appropriate; allsame() returns a Boolean.

Author(s)

Robin K. S. Hankin

Examples

disord(c(3,3,3,3,3))             # default is drop=TRUE
disord(c(3,3,3,3,3),drop=FALSE)  # retains disord class

drop(disord(c(3,3,3,3),drop=FALSE)) 

## In extraction, argument drop discards disorderliness when possible:
a <- rdis()
a
a[] <- 6 # a becomes a vector
a


disordR documentation built on May 29, 2024, 11:06 a.m.