is.vec.logical | R Documentation |
This is an improvement on base:is.logical because data may be encoded as a different type (e.g, string, "TRUE", "FALSE") especially if imported from a file. This does not include logical vectors coded as 0,1; such will return FALSE with this function.
is.vec.logical(x, thresh = 0.9)
x |
a vector to check for logical status |
thresh |
threshold to decide that a variable is logical. NA values will be ignored in the test. Then it looks at the proportion of values that are successfully coerced to logical without giving 'NA'. If this threshold is 0.9, then any column where at least 90 converted to logical type, will return TRUE for this function call. |
returns a logical TRUE or FALSE for the logical status of x.
Nicholas Cooper
numeric <- 1:10 string <- paste("one", "two", "three", "four") logic1 <- c(TRUE,FALSE,FALSE,TRUE,FALSE,NA) logic2 <- c("TRUE", "FALSE", "TRUE", NA, "TRUE", NA, NA, NA) logic3 <- c("True", "False", "True", "False") numlogic <- c(0,1,0,0,0,1,1,1,0) is.vec.logical(numeric) is.vec.logical(string) is.vec.logical(logic1) is.vec.logical(logic2) is.vec.logical(logic3) is.vec.logical(numlogic)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.