toChar | R Documentation |
For inputs containing only a single string, returns a character vector of single chars (UTF8s) by default. For inputs containing multiple strings, or if drop= FALSE is set, returns a list of character vectors (of single chars) named for the string. Duplicate names are fine.
toChar(x, drop = TRUE, use.names = TRUE)
x |
A vector of strings to convert |
drop |
Only affects output when |
use.names |
By default the list will use the original strings as names. This may not be reasonable for large strings; set this false to just use numeric ordering (the same as the input string order). |
The input strings, split into vectors of single characters. If more
than one string is input, or if drop= FALSE
is set this outputs a list
of vectors. Vectors will be named for the input string, if possible.
toChar( c("ABC", "ABC", "A\u00dfB", 123, "", "x", NA ) )
#=> $ABC
#=> [1] "A" "B" "C"
#=>
#=> $ABC
#=> [1] "A" "B" "C"
#=>
#=> $AßB
#=> [1] "A" "ß" "B"
#=>
#=> $`123`
#=> [1] "1" "2" "3"
#=>
#=> [[5]]
#=> [1] ""
#=>
#=> $x
#=> [1] "x"
#=>
#=> $<NA>
#=> [1] NA
toChar( "ABC" )
#=> [1] "A" "B" "C"
toChar( c("ABC", "ABC", use.names= FALSE) )
#=> [[1]]
#=> [1] "A" "B" "C"
#=>
#=> [[1]]
#=> [1] "A" "B" "C"
toChar( "ABC", drop= FALSE )
#=> $ABC
#=> [1] "A" "B" "C"
toChar( "ABC", drop= FALSE, use.names= FALSE )
#=> [[1]]
#=> [1] "A" "B" "C"
toChar( 123 )
#=> [1] "1" "2" "3"
toChar( NULL )
#=> character(0)
toChar( character(0) )
#=> character(0)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.