Sean Zhang
2009-Feb-20 16:38 UTC
[R] How to transfer a list of space delimited character elements into a char vector?
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]]
baptiste auguie
2009-Feb-20 17:08 UTC
[R] How to transfer a list of space delimited character elements into a char vector?
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
Possibly Parallel Threads
- About Creating a List by Parsing Text
- How to write a function that accepts unlimited number of input arguments?
- R strings, null-terminated or size delimited?
- How to create tab-delimited text files
- Fastest way to merge matrix columns into a comma delimited string?