Description Usage Arguments Value Author(s) Examples
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
.
1 |
rec |
recoding definition as required by the |
e |
Deviation from given interval values when an open interval is used
(i.e. excluding the given value). The default deviation is |
A string with recoding definitions for intervals as required by recode
from
car
.
Mark Heckmann
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)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.