How can I read fixed column data (without a delimiter) from a large ASCII file directly into R? I want to read non-contiguous variables. I am trying to avoid reading it first into a DBMS and then choosing the variables. I would perfer to format and label it along while reading if possible. Something like what STATA does with dictionary. Anupam.
Not familiar w/ Stata, but these functions read data files and should provide the functionality you wish. ?read.fwf ?read.table ?scan ----- Original Message ----- From: "Anupam Tyagi" <AnupTyagi at yahoo.com> To: <r-help at stat.math.ethz.ch> Sent: Monday, September 11, 2006 8:26 AM Subject: [R] Reading fixed column format> How can I read fixed column data (without a delimiter) from a large ASCII > file > directly into R? I want to read non-contiguous variables. I am trying to > avoid > reading it first into a DBMS and then choosing the variables. I would > perfer to > format and label it along while reading if possible. Something like what > STATA > does with dictionary. Anupam. > > ______________________________________________ > R-help at stat.math.ethz.ch 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. >
Jason Barnhart <jasoncbarnhart <at> msn.com> writes:> > Not familiar w/ Stata, but these functions read data files and should > provide the functionality you wish. > ?read.fwf > ?read.table > ?scanNone of these seem to read non-coniguous variables from columns; or may be I am missing something. "read.fwf" is not meant for large files according to a post in the archives. Thanks for the pointers. I have read the R data input and output. Anupam.
On 9/13/06, Anupam Tyagi <AnupTyagi at yahoo.com> wrote:> Gabor Grothendieck <ggrothendieck <at> gmail.com> writes: > > > C:\bin>cut -c2-3,6-8 a.dat > > 23678 > > 23678 > > 23678 > > Thanks. I think this will work. How do I redirect the output to a file on > windows?Same as on UNIX cut -c2-3,6-8 a.dat > a2.dat> Is there simple way to convert the cut command to a script on windows,Using notepad or other text editor put it in file a.bat and then issue this command from the console a.bat Note that you could process it multiple time if you like: cut -c6-8 a.dat > a2.dat cut -c2-3 a2.dat > a3.dat produces the same thing but uses 2 passes and so keeps each line shorter. Be sure you do it from the tail end forward as shown above to avoid having to recalculate the positions.> because the entire command may not fit on one line? Anupam. >