intervals: Use standard mathematical interval notation in 'recode' from...

Description Usage Arguments Value Author(s) Examples

Description

The recode function from the car package is an excellent function for recoding data. When defining open intervals though, the recoding definitions will quickly become hard to read. The intervals function allows to use standard mathematical interval notation, e.g. like [1,4), to define (open) intervals. It will convert the intervals definition into a format required by the recode function from car. The standard intervals can simply be used additionally to the standard recoding definitions as required by recode.

Usage

1
intervals(rec, e = 10^-8)

Arguments

rec

recoding definition as required by the recode function from the car package, additionally allowing for standard mathematical interval notation. An interval notation consists of two brackets containing the interval values seperated by a comma. Open and closed intervals may be defined, e.g. (1,2), [1,2], (1,2], [1,2). The tags lo and hi for the highest and lowest value in the dataset may also be used, e.g. [lo,4], [0,hi).

e

Deviation from given interval values when an open interval is used (i.e. excluding the given value). The default deviation is 10e-8. This means that e.g. the interval (1,2) is converted into the definition 1+10e-8:2-10e-8 to be used in the recode function.

Value

A string with recoding definitions for intervals as required by recode from car.

Author(s)

Mark Heckmann

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
## Not run: 
 library(car)

 # the standard way if we want to recode [1,2) to the value 3
 recode(c(1, 1.999, 2, 2.001), "1:2-1e-4=3")

 # the same using interval notation
 intervals("[1,2)=3")
 recode(c(1, 1.999, 2, 2.001), intervals("[1,2)=3"))

 # another example: the car way
 e <- 10^-8
 recode(1:9/3.01, "lo:1-e=0; 1:2-e=1; 2:3-e=2")
 # using intervals
 recode(1:9/3.01, intervals("[lo,1)=0; [1,2)=1; [2,3)=2"))

## End(Not run)

ryouready documentation built on May 1, 2019, 8:39 p.m.