[R] 1.8.1 behavior change?

Al Piszcz apiszcz at solarrain.com
Sat Nov 22 21:14:31 CET 2003


I would like to have one handle or reference to
'n' matrices. The matrices vary in size.
All data is floating point.
The input files have 21 columns and a varying
number of rows.

I am open to any data structure that will
support this.








On Sat, 22 Nov 2003, Prof Brian Ripley wrote:

> Date: Sat, 22 Nov 2003 18:41:55 +0000 (GMT)
> From: Prof Brian Ripley <ripley at stats.ox.ac.uk>
> To: Al Piszcz <apiszcz at solarrain.com>
> Cc: r-help at stat.math.ethz.ch
> Subject: Re: [R] 1.8.1 behavior change?
>
> On Sat, 22 Nov 2003, Al Piszcz wrote:
>
> > In <R 1.8.1 the following fragment worked properly, now (1.8.1)
>
> I take it you mean R < 1.8.1?  In trying to reproduce something
> like this
>
> stt <- data.frame()
> stt[1] <- as.matrix(data.frame(foo=1:10, bar=letters[1:10]))
>
> in 1.8.0 I got
>
> > stt
> [1] V1
> <0 rows> (or 0-length row.names)
>
> so is that what `worked properly' means?  (It is also what S+6.1 does, but
> I am pretty sure it is not what anyone wanted.  Note the number of
> columns is wrong, too.)
>
> In 1.7.1 it gave a similar error to 1.8.1.
>
> So as far as I can see (given you did not supply a test example) 1.8.1 is
> just more helpful by pointing out your user error.  The rule is that the
> existing columns should be replicated an exact number of times when
> extending a data frame: and that includes the row names so applies even if
> there are no other columns.
>
> I hope each of your input files except the last have just one column (in
> which case your code is very clunky) as otherwise you are asking for
> columns to be overwritten.  I would advise you to use cbind for this,
> or dimension the data frame correctly in the first place and replace
> sections at a time.
>
> > it creates the following warning/error:
> >
> > Any advice appreciated.
>
> Supply reproducible examples, as the FAQ asks.  I have no idea why you
> have given the same code twice here, BTW, so I remove the first copy.
>
>
> > >   stt <- data.frame()
> > >   # load all datasets into a dataframe
> > >   for (ds in 1:n) {
> > +     stt[ds] <- as.matrix(read.table(fileList[ds]))
> > +   }
> > Error in "[<-.data.frame"(`*tmp*`, ds, value =
> > as.matrix(read.table(fileList[ds]))) :
> >         replacement has 358 rows, data has 0
>
> --
> Brian D. Ripley,                  ripley at stats.ox.ac.uk
> Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
> University of Oxford,             Tel:  +44 1865 272861 (self)
> 1 South Parks Road,                     +44 1865 272866 (PA)
> Oxford OX1 3TG, UK                Fax:  +44 1865 272595
>




More information about the R-help mailing list