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.
.

______________________________________________
R-help@r-project.org 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.

Reply via email to