[R] How to transfer a list of space delimited character elements into a char vector?
baptiste auguie
ba208 at exeter.ac.uk
Fri Feb 20 18:08:40 CET 2009
Hi,
something like this perhaps,
create_string <- function(.s){
result <- read.table(textConnection(.s))
sapply(result, as.character)
}
(test <- create_string("ab cd ef"))
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)
>
>
> Motivation: I have a very long list of character elements (like, ab
> cd ef gg
> ww kwfl ......),
>
> I try to avoid
> typing "," between two adjacent elements,
> typing " in front of the first element,
> and typing " right after the last element.
> when using them to generate a character vector.
>
> Many Thanks in advance.
>
> -Sean
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
_____________________________
Baptiste Auguié
School of Physics
University of Exeter
Stocker Road,
Exeter, Devon,
EX4 4QL, UK
Phone: +44 1392 264187
http://newton.ex.ac.uk/research/emag
More information about the R-help
mailing list