Description Usage Arguments Details Value See Also Examples
These functions facilitate working with variables as categorical or continous rather than logical, integer, numeric, factor, character, ..
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | cat_cont(x)
is_cat(x)
## Default S3 method:
is_cat(x)
## S3 method for class 'ordered'
is_cat(x)
## S3 method for class 'factor'
is_cat(x)
## S3 method for class 'logical'
is_cat(x)
is_cont(x)
## Default S3 method:
is_cont(x)
## S3 method for class 'logical'
is_cont(x)
## S3 method for class 'factor'
is_cont(x)
## S3 method for class 'ordered'
is_cont(x)
which_cat(x, ..., names = FALSE)
which_cont(x, ..., names = FALSE)
|
x |
object |
... |
arguments passed to other functions. |
names |
logical; whether to return the names of the variables instead of their index? |
These functions are used to test and identify which/if a variable or
variables are categorical or continuos. is_cat
and is_cont
take single variable arguments.
Mostly, the categorical and continuos assessment is straight-
forward. Continuous variables are respresented by integer
, double
or complex
types. All other types are categorical. There are a few
opinionated exceptions:
factors are categorical (though typed 'integer')
ordered factors are (though typed 'integer')
logical are categorical
For simplicity, it is assumed that a vector cannot be simultaneous categorical and continous, though in some cases (e.g. ordered factors) this may be the case.
cat_cont
returns a named character with values either "cat
" or "cont
".
If x
is a atomic vector, a single string is given. If x
is recursive,
a "cat
"/"cont
" value is given for each element. Names correspond to the
names of the element.
is_cat
and is_cont
return logical
.
which_cat
and which.cont
report which variables in an object
are categorical and continuous. By default, interger indices are
return. If names=TRUE
, the names of the variables are returned
instead.
base::typeof()
base::is.numeric()
methods::is()
base::which()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | data(iris)
cat_cont(iris)
is_cat(letters) # TRUE
is_cat(factor(letters)) # TRUE
is_cat(TRUE) # TRUE
is_cat(FALSE) # TRUE
is_cat(1:10) # FALSE
is_cat(rnorm(10)) # FALSE
is_cat( Sys.Date() ) # FALSE
is_cat( complex(1,2) ) # FALSE
is_cont(letters) # FALSE
is_cont(factor(letters)) # FALSE
is_cont(TRUE) # FALSE
is_cont(FALSE) # FALSE
is_cont(1:10) # TRUE
is_cont(rnorm(10)) # TRUE
is_cont( Sys.Date() ) # TRUE
is_cont( complex(1,2) ) # TRUE
which_cat(iris)
which_cat( iris, names=TRUE )
which_cont(iris)
which_cont( iris, names=TRUE )
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.