[R] Read in a all-character file and specify field separator and records separator
Joshua Wiley
jwiley.psych at gmail.com
Mon Aug 30 07:29:50 CEST 2010
On Sun, Aug 29, 2010 at 9:18 PM, Yong Wang <wangyong1 at gmail.com> 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.
Do either of these do what you want?
readLines(con = file("example.txt", open = "r"))
read.table(file = "example.txt", sep = "\n")
Both throw a warning in a little text file I made, but both read each
line into one column.
Josh
>
> Thanks
>
> yong
>
> ______________________________________________
> R-help at 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.
>
--
Joshua Wiley
Ph.D. Student, Health Psychology
University of California, Los Angeles
http://www.joshuawiley.com/
More information about the R-help
mailing list