as.character2 {chinese.misc} | R Documentation |
An Enhanced Version of as.character
Description
This function manages to coerce one or more objects into a character vector. Unlike
as.character
, this function can handle data frames, lists and recursive lists
(lists of lists), even when there are factor objects inside data frames and lists. If there is any
NULL
object in a list, as.character2
will coerce that element into
character(0)
rather than the character "NULL", which is what
as.character
does. When the object is of class matrix or data frame, the function
will open it by column. The order of characters in result manages to keep accordance
with that of the input object.
Usage
as.character2(...)
Arguments
... |
one or more objects to be coerced. |
Value
a character vector
Examples
as.character2(NULL, NULL)
# Try a list of NULLs
null_list <- list(a = NULL, b = NULL, c = NULL)
# Compare the different results of as.character
# and as.character2. In fact, we usually
# want the latter one.
as.character(null_list)
as.character2(null_list)
# Try a list with a data frame in it
df <- data.frame(matrix(c(66,77,NA,99), nrow = 2))
l <- list(a = 1:4, b = factor(c(10,20,NA, 30)), c = c('x', 'y', NA, 'z'), d = df)
as.character2(l)
# Try a list of lists
l2 <- list(l, l, cha = c('a', 'b', 'c'))
as.character2(l2)
[Package chinese.misc version 0.2.3 Index]