Dear R People:
I am trying to split a character vector into a set of individual
letters:
Ideal:
x3 <- c("dog")
"d" "o" "g"
I tried the following:> strsplit(x3)
Error in strsplit(x3) : argument "split" is missing, with no
default> strsplit(x3,1)
[[1]]
[1] "dog"
I know that this is incredibly simple, but what am I doing wrong?
Either Windows or Linux 2.3.1
Thanks in advance!
Sincerely,
Erin Hodgess
Associate Professor
Department of Computer and Mathematical Sciences
University of Houston - Downtown
mailto: hodgess at gator.uhd.edu
On Tue, 29 Aug 2006, Erin Hodgess wrote:> Dear R People: > > I am trying to split a character vector into a set of individual > letters: > > Ideal: > x3 <- c("dog") > "d" "o" "g" > > I tried the following: >> strsplit(x3) > Error in strsplit(x3) : argument "split" is missing, with no default >> strsplit(x3,1) > [[1]] > [1] "dog" > > I know that this is incredibly simple, but what am I doing wrong? >This is the first example on the help page for strsplit. -thomas
Use '' as parameter to strsplit> x3 <- 'dog' > strsplit(x3, '')[[1]] [1] "d" "o" "g">On 8/29/06, Erin Hodgess <hodgess at gator.dt.uh.edu> wrote:> Dear R People: > > I am trying to split a character vector into a set of individual > letters: > > Ideal: > x3 <- c("dog") > "d" "o" "g" > > I tried the following: > > strsplit(x3) > Error in strsplit(x3) : argument "split" is missing, with no default > > strsplit(x3,1) > [[1]] > [1] "dog" > > I know that this is incredibly simple, but what am I doing wrong? > > Either Windows or Linux 2.3.1 > > Thanks in advance! > > > Sincerely, > Erin Hodgess > Associate Professor > Department of Computer and Mathematical Sciences > University of Houston - Downtown > mailto: hodgess at gator.uhd.edu > > ______________________________________________ > R-help at stat.math.ethz.ch 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. >-- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem you are trying to solve?
you can also use substring(), e.g.,
substring(x3, 1:nchar(x3), 1:nchar(x3))
Best,
Dimitris
----
Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven
Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
http://www.student.kuleuven.be/~m0390867/dimitris.htm
----- Original Message -----
From: "Erin Hodgess" <hodgess at gator.dt.uh.edu>
To: <r-help at stat.math.ethz.ch>
Sent: Wednesday, August 30, 2006 12:25 AM
Subject: [R] Substring and strsplit
> Dear R People:
>
> I am trying to split a character vector into a set of individual
> letters:
>
> Ideal:
> x3 <- c("dog")
> "d" "o" "g"
>
> I tried the following:
>> strsplit(x3)
> Error in strsplit(x3) : argument "split" is missing, with no
default
>> strsplit(x3,1)
> [[1]]
> [1] "dog"
>
> I know that this is incredibly simple, but what am I doing wrong?
>
> Either Windows or Linux 2.3.1
>
> Thanks in advance!
>
>
> Sincerely,
> Erin Hodgess
> Associate Professor
> Department of Computer and Mathematical Sciences
> University of Houston - Downtown
> mailto: hodgess at gator.uhd.edu
>
> ______________________________________________
> R-help at stat.math.ethz.ch 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.
>
Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm