Learn R Programming

disordR (version 0.9-8-7)

misc: Miscellaneous functions

Description

This page documents various functions that work for disords, and I will add to these from time to time as I add new functions that make sense for disord objects (or identify functions that break disord discipline).

Usage

# S4 method for disord
length(x)
# S4 method for disord
sort(x, decreasing = FALSE, ...)
# S4 method for disord
rev(x)
# S4 method for disord
sapply(X, FUN, ..., simplify = TRUE, USE.NAMES = TRUE)
# S4 method for disord
lapply(X, FUN, ...)
# S4 method for disord,ANY
match(x, table, nomatch = NA_integer_, incomparables = NULL)
# S4 method for ANY,disord
match(x, table, nomatch = NA_integer_, incomparables = NULL)
# S4 method for disord,disord
match(x, table, nomatch = NA_integer_, incomparables = NULL)
# S4 method for disord
unlist(x, recursive = TRUE)
# S4 method for disord
diff(x, ...)
# S4 method for disord
jitter(x, factor=1, amount=NULL)
binder(x,y)

Value

Returns a disord

Arguments

x, y, X

A disord or disindex object

table

Target table for matching

nomatch

The value to be returned in the case when no match is found

incomparables

A vector of values that cannot be matched

FUN

The function to be applied

decreasing

Logical indicating if the sort order should be decreasing

recursive, simplify, USE.NAMES

Standard options passed to base functions

factor, amount

Passed to jitter()

...

Further arguments passed to underlying methods

Author

Robin K. S. Hankin

Details

Functions like sin() and abs() work as expected: they take and return disord objects with the same hash as x (which means that idiom like x + sin(x) is accepted). However, there are a few functions that are a little more involved:

  • rev() reverses its argument and returns a disord object with a reversed hash, which ensures that rev(rev(x))==x (and the two are consistent).

  • sort() returns a vector of sorted elements (not a disord)

  • length() returns the length of the data component of the object

  • sapply(X,f) returns a disord object which is the result of applying f() to each element of X.

  • match(x,table) should behave as expected but note that if table is a disord, the result is not defined (because it is not known where the elements of x occur in table). Nevertheless x %in% table is defined and returns a disord object.

  • lapply(x,f) returns disord(lapply(elements(x),f,...),h=hash(x)). Note that double square bracket extraction, as in x[[i]], is disallowed (see extract.Rd).

  • which() returns a disind object when given a Boolean disord

  • unlist() takes a disord list, flattens it and returns a disord vector. It requires the recursive flag of base::unlist() to be TRUE, which it is by default, interpreting this to mean “kill all the structure in any sublists”. If the list comprises only length-one vectors, the returned value retains the same hash as the argument; if not, a new hash is generated.

  • diff() is undefined for disord objects.

  • rbind() and cbind() are undefined for disord objects as they break disord discipline. Function binder() returns a generic, and hopefully informative, error message [the package defines methods for rbind2() and cbind2()]

  • jitter() takes a disord object, jitters the elements, and returns a disord object with the correct hash code.

See Also

extract

Examples

Run this code
a <- disord(c(a=1,b=2,c=7))
a
names(a)
length(a)
sqrt(a)


# powers() and vars() in the mvp package return lists; see the vignette
# for more discussion.

l <- disord(list(3, 6:9, 1:10))  
sapply(l, length)

unlist(l)

## Quick illustration of rev():

revstring <- function(s){paste(rev(unlist(strsplit(s, NULL))),collapse="")}
x <- rdis()
revstring(hash(x)) == hash(rev(x))

Run the code above in your browser using DataLab