Say I have this vector:
vars <- c(1, "2")
Since those two elements are in the same vector, they are both coerced to character. Even if I treat them as independent elements on a list, once they are extracted from the same vector, they keep their type on the list:
sapply(as.list(vars), class)
[1] "character" "character"
What function would find that not all of the elements in vector vars
are of type character? Maybe another way to put it is: what function would detect that not all of the elements on vector vars
are quoted?
Instead of keeping in a vector
, create a list
which can have multiple type
for each element
vars <- list(1, "2")
sapply(vars, class)
#[1] "numeric" "character"
When we start this as a vector
, there is no way to know which element should be numeric or character because both the elements once created are character