[R] How to separate the string?

Petr PIKAL petr.pikal at precheza.cz
Tue Jul 7 11:00:21 CEST 2009


Hi

If you have data frame like this

test=data.frame(x=c("abcd", "abc", "abcde"))
than
strsplit(as.matrix(test), "")

makes a list with splitted character vectors. If you want them in data 
frame you would need to combine vectors of unequal length.

However I would try reading your text file with

read.fwf(file, 1)

Regards
Petr


Hemavathi Ramulu <hema.ramulu at gmail.com> napsal dne 07.07.2009 10:36:40:

> Hi Petr,
> 
> The data in text file and not csv format. 
> The word "separate " which I mean in this content is like split/separate 
the 
> string to each alphabet 
> where each alphabet will be in different column.
> 
> thanks alot.
> 
> regards,
> Hema.

> On Tue, Jul 7, 2009 at 4:12 PM, Petr PIKAL <petr.pikal at precheza.cz> 
wrote:
> Hi
> 
> r-help-bounces at r-project.org napsal dne 07.07.2009 09:54:30:
> 
> > Hi everyone,
> > Hi want to separate the string(column1) for example

> Well, how did you get the data in R? Are they in separated columns of
> data.frame? What do you mean by "separate"?
> 
> >
> > column1 column2 column3 column4 column5 column6
> > bear           b           e             a          r
> > cat             c           a              t
> > tiger            t           i               g          e           r
> >
> > I know how to do this in excel where using MID function.

> As Microsoft is more user friendly and uses translated functions in
> language specific versions of Excel I do not have function MID. I 
suspect
> it takes values from middle of string set by some identifiers. If it is
> the case see
> 
> ?substr
> 
> However I would start with
> 
> ?read.table
> 
> and related read.* functions to get the data into R in appropriate 
shape.
> 
> Regards
> Petr
> 
> 
> > Now I want to solve it using R. The list of strings is in text file. I
> > looked up the help but did not find it.
> > Can someone help me here?
> >
> > Thank you very much.
> >
> > Regards,
> > Hema
> >
> >    [[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.

> 
> 
>




More information about the R-help mailing list