[R] selecting characters from a line of text

Stephen Tucker brown_emu at yahoo.com
Tue Jun 12 01:34:23 CEST 2007


Maybe substring() is what you're looking for? Some examples:

> substring("textstring",1,5)
[1] "texts"
> substring("textstring",3)
[1] "xtstring"
> substring("textstring",3,nchar("textstring"))
[1] "xtstring"


--- Tim Holland <timothyholland at gmail.com> wrote:

> Is there a way in R to select certain characters from a line of text?  I
> have some data that is presently in a large number of text files, and I
> would like to be able to select elements of each text file (elements are
> always on the same line, in the same position) and organize them into a
> table.  Is there a tool to select text in this way in R?  What I am looking
> for would be somewhat similar to the left() and right() functions in Excel.
> I have looked at the parse() and scan() functions, but don't think they can
> do what I want (although I could be wrong).
> Thank you,
> Tim
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> 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.
>



More information about the R-help mailing list