[R] data import problem
Gabor Grothendieck
ggrothendieck at gmail.com
Wed Mar 8 15:14:07 CET 2006
Check out:
http://finzi.psych.upenn.edu/R/Rhelp02a/archive/52957.html
for a similar problem.
On 3/8/06, Arne.Muller at sanofi-aventis.com
<Arne.Muller at sanofi-aventis.com> wrote:
> Dear All,
>
> I'm trying to read a text data file that contains several records separated by a blank line. Each record starts with a row that contains it's ID and the number of rows for the records (two columns), then the data table itself, e.g.
>
> 123 5
> 89.1791 1.1024
> 90.5735 1.1024
> 92.5666 1.1024
> 95.0725 1.1024
> 101.2070 1.1024
>
> 321 3
> 60.1601 1.1024
> 64.8023 1.1024
> 70.0593 2.1502
>
> ...
>
> I thought I coudl simply use something line this:
>
> con <- file("test2.txt");
> do {
> e <- read.table(con, nlines = 1);
> if ( length(e) == 2 ) {
> d <- read.table(con, nrows = e[1,2]);
> #process data frame d
> }
> } while (length(e) == 2);
>
> The problem is that read.table closes the connection object, I assumed that it would not close the connection, and instead contines where it last stopped.
>
> Since the data is nearly a simple table I though read.table could work rather than using scan directly. Any suggestions to read this file efficently are welcome (the file can contain several thousand record and each record can contain several thousand rows).
>
> thanks a lot for your help,
> +kind regards,
>
> Arne
>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> 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
>
More information about the R-help
mailing list