score.binary | R Documentation |
Creates a new variable from a series of logical conditions. The new
variable can be a hierarchical category or score derived from considering
the rightmost TRUE
value among the input variables, an additive point
score, a union, or any of several others by specifying a function using the
fun
argument.
score.binary(..., fun=max, points=1:p,
na.rm=funtext == "max", retfactor=TRUE)
... |
a list of variables or expressions which are considered to be binary or logical |
fun |
a function to compute on each row of the matrix represented by
a specific observation of all the variables in |
points |
points to assign to successive elements of |
na.rm |
set to |
retfactor |
applies if |
a factor
object if retfactor=TRUE
and fun=max
or a numeric vector
otherwise. Will not contain NAs if na.rm=TRUE
unless every variable in
a row is NA
. If a factor
object
is returned, it has levels "none"
followed by character
string versions of the arguments given in ...
.
any
, sum
, max
, factor
set.seed(1)
age <- rnorm(25, 70, 15)
previous.disease <- sample(0:1, 25, TRUE)
#Hierarchical scale, highest of 1:age>70 2:previous.disease
score.binary(age>70, previous.disease, retfactor=FALSE)
#Same as above but return factor variable with levels "none" "age>70"
# "previous.disease"
score.binary(age>70, previous.disease)
#Additive scale with weights 1:age>70 2:previous.disease
score.binary(age>70, previous.disease, fun=sum)
#Additive scale, equal weights
score.binary(age>70, previous.disease, fun=sum, points=c(1,1))
#Same as saying points=1
#Union of variables, to create a new binary variable
score.binary(age>70, previous.disease, fun=any)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.