[R] Read in a all-character file and specify field separator and records separator
David Winsemius
dwinsemius at comcast.net
Mon Aug 30 07:34:43 CEST 2010
On Aug 30, 2010, at 12:18 AM, Yong Wang wrote:
> Dear list
>
> I used to use python or awk do preliminary process and then feed into
> R. In some circumstances, the data transmission becomes quite a pain.
> I am wondering if there is a convenient way to read in R text file
> (not data, text file in common sense) and specify field separator and
> records separator, so the whole work can be reduced to one-stop
> shopping.
> or simply, is there one simple way to read in the text file with each
> row in a single column. scan(....sep="\n") does not work as expected.
>
You should not need to use sep=\n or any separator for a single column
output. If what= is not specified you will just get a numeric vector,
but if it's text, you need to specify "character". Try the obvious
modifications to this:
char.vec <- scan(file="/filepath/filename.ext", what="character" )
Multiple columns require something like what=list("character",
"numeric", "logical"), but you could do what the rest of us use
because it's all wrapped up with sensible defaults (with the possible
exception of stringsAsFactors ) in the read.table function.
--
David.
.
More information about the R-help
mailing list