Re: [R] selecting characters from a line of text

From: Vladimir Eremeev <>
Date: Tue, 12 Jun 2007 01:03:23 -0700 (PDT)

Tim Holland 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?

Use substr() or substring() to select characters from a a text string, nchar() will give you its length,
scan() can also help in reading data from text files, grep() can be used for search and selecting character strings in an array, having certain patterns.

If your files are formatted in some way, consider read.table(), read.csv(), read.fwf() and friends.

You should also read the "Data import/export" manual from the R documentation.
Its pdf version was, probably, installed on your hard drive with R, and html is here: pdf version is also here:

View this message in context:
Sent from the R help mailing list archive at

______________________________________________ mailing list
PLEASE do read the posting guide
and provide commented, minimal, self-contained, reproducible code.
Received on Tue 12 Jun 2007 - 08:08:27 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 12 Jun 2007 - 08:31:52 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.