[R] selecting characters from a line of text

Vladimir Eremeev wl2776 at gmail.com
Tue Jun 12 10:03:23 CEST 2007



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: 
http://cran.r-project.org/doc/manuals/R-data.html
pdf version is also here:
http://cran.r-project.org/doc/manuals/R-data.pdf
-- 
View this message in context: http://www.nabble.com/selecting-characters-from-a-line-of-text-tf3904063.html#a11074650
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list