I would like know whether it is permitted to use an equals (=
) sign in the recodes
parameter of the recode
function in the car package?
For instance, the following fails:
library(car)
n <- c(0, 10, 20, 21, 60, 70)
r <- recode(n, " 0:20 = '<= 20' ; 20:70 = '> 20' ")
# Error in recode(n, " 0:20 = '<= 20' ; 20:70 = '> 20' ") :
# in recode term: 0:20 = '<= 20'
# message: Error in parse(text = strsplit(term, "=")[[1]][2]) :
# <text>:1:2: unexpected INCOMPLETE_STRING
# 1: '<
# ^
Removing the =
from <= 20
works fine:
r <- recode(n, " 0:20 = '< 20' ; 20:70 = '> 20' ")
table(r)
r
# < 20 > 20
# 3 3
Given I'm using recode
in a context where I'm taking the recodes
argument as user input, I'm hoping any solution does not require explicit escape characters being necessary as this would be burdensome.
I'm running R version 3.2.3 (2015-12-10) -- "Wooden Christmas-Tree"