[R] How to transfer a list of space delimited character elements into a char vector?

Wacek Kusnierczyk Waclaw.Marcin.Kusnierczyk at idi.ntnu.no
Fri Feb 20 19:31:31 CET 2009


baptiste auguie wrote:
> Hi,
>
> something like this perhaps,
>
>
> create_string <- function(.s){
>     result <- read.table(textConnection(.s))
>     sapply(result, as.character)
> }
>
> (test <- create_string("ab cd ef"))

or:

unlist(strsplit('ab cd ef', split=' '))

vQ

>
> hope this helps
>
> baptiste
>
> On 20 Feb 2009, at 16:38, Sean Zhang wrote:
>
>> My dear R-helpers:
>>
>> I am a novice in R and have the following text string manipulation
>> question.
>>
>> Is there a function that performs the job described below?
>> Say,
>> wanted_output <- c("ab", "cd", "ef")
>> #the function_wanted can generate  c("ab", "cd", "ef") using ab cd ef
>> as the
>> single input argument
>> wanted_output <- function_wanted(ab cd ef)
>>




More information about the R-help mailing list