Misc R helper functions

Description

eqc(x, number=4, overlap=1/sqrt(length(x))) an abbreviation for equal.count with useful defaults. Often useful for Lattice plots.

grep.b(pattern, x) performs a grep, but returns the result as a logical (boolean, thus the .b) vector along x rather than as an integer vector indices. Often useful for Lattice subset calls.

grep.s(pattern, x) performs grep(pattern, x, value=TRUE) and thus returns the matched strings rather than their indices.

orderavg(x, by) orders the observations from vector x using the equal-weighted ranking criteria given in matrix by (which has length(x) rows and n colums), a by vector is coerced. The ranks computed from each matrix column are summed row-wise, the resulting vector is sorted according to these rank sums, and returned. This function can be used to pair elements from two vectors (by ranking them both by equivalent criteria).

tableNA abbreviation for table with an additional argument exclude = NULL so that NA and NaN values are tabulated as well.

or.else(x, alternative = 0) returns x where available and alternative where is.na(x). alternative can be a scalar or vector and should have the same mode as x.

printn(x, digits) prints name and value of x. If the optional argument digits is used, x will be coerced to numeric and formatted with digits digits precision. Useful for quick-and-dirty debugging output.

tracebck() is like traceback except that it returns (rather than prints) only the first line of each frame. This is useful because the argument lists of calls often contain large data objects which clutter the output of traceback and make it very difficult to read.

Details

Type the name of a function to see its source code for details.

Author(s)

Lutz Prechelt prechelt@inf.fu-berlin.de

See Also

equal.count, grep, order, ifelse, table, traceback.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
## Not run: plot(rnorm(8)~runif(8),xlim=c(10,NA))
## Not run: traceback()
## Not run: tracebck()

data(iris)
xyplot(Sepal.Width ~ Sepal.Length | eqc(Sepal.Length),
       subset=grep.b("v",Species), data=iris)

x = c(4,9,NA,4,4,27,NA,27)
table(or.else(x,88))
table(x)
tableNA(x)

printn(levels(iris$Species))