Skip to content

Pulling strings from a Flat file

3 messages · Kalicin, Sarah, David Winsemius, Bill Venables

#
On Apr 5, 2011, at 7:48 PM, Kalicin, Sarah wrote:

            
> txt <- "E123456E234567E345678E456789E567891E678910E"
# You could use readLines to bring in from the file
# and assign to a character vector for work in R.

 > gsub("(E[[:digit:]]{6})", "\\1\n", txt)
[1] "E123456\nE234567\nE345678\nE456789\nE567891\nE678910\nE"
# Seems to be "working" properly

 > ?scan

 > scan(textConnection(gsub("(E[[:digit:]]{6})", "\\1\n", txt)),  
what="character")
Read 7 items
[1] "E123456" "E234567" "E345678" "E456789" "E567891" "E678910" "E"

You might be able to use read.table or variants.
David Winsemius, MD
West Hartford, CT
#
Isn't all you need read.fwf?