[R] 1.8.1 behavior change? W EXAMPLE
Al Piszcz
apiszcz at solarrain.com
Sat Nov 22 21:36:19 CET 2003
Here is a working example with R 1.8.0, followed by the
test files, and finally the R 1.8.1 error messages.
**** [1] R 1.8.0 WORKING EXAMPLE
R
R : Copyright 2003, The R Development Core Team
Version 1.8.0 (2003-10-08)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
R is a collaborative project with many contributors.
Type 'contributors()' for more information.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for a HTML browser interface to help.
Type 'q()' to quit R.
> stt <- data.frame()
> stt[1]<-as.matrix(read.table("a"))
> stt[2]<-as.matrix(read.table("b"))
> stt[3]<-as.matrix(read.table("c"))
> stt[1]
[1] V1
<0 rows> (or 0-length row.names)
> stt[,1]
V1 V2 V3
1 1 2 3
2 4 5 6
3 7 8 9
> stt[,2]
V1 V2 V3
1 10 11 12
2 13 14 15
3 16 17 18
> stt[,3]
V1 V2 V3
1 19 20 21
2 22 23 24
3 25 26 27
>
**** [2] FILES
::::::::::::::
a
::::::::::::::
1 2 3
4 5 6
7 8 9
::::::::::::::
b
::::::::::::::
10 11 12
13 14 15
16 17 18
::::::::::::::
c
::::::::::::::
19 20 21
22 23 24
25 26 27
**** [3] R 1.8.1 Error
$ R
R : Copyright 2003, The R Foundation for Statistical Computing
Version 1.8.1 (2003-11-21), ISBN 3-900051-00-3
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for a HTML browser interface to help.
Type 'q()' to quit R.
[Previously saved workspace restored]
> stt <- data.frame()
> stt[1]<-as.matrix(read.table("a"))
Error in "[<-.data.frame"(`*tmp*`, 1, value = as.matrix(read.table("a")))
:
replacement has 3 rows, data has 0
apiszcz at l1:/x/t_16 $ R
R : Copyright 2003, The R Foundation for Statistical Computing
Version 1.8.1 (2003-11-21), ISBN 3-900051-00-3
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for a HTML browser interface to help.
Type 'q()' to quit R.
[Previously saved workspace restored]
> stt <- data.frame()
> stt[1]<-as.matrix(read.table("a"))
Error in "[<-.data.frame"(`*tmp*`, 1, value = as.matrix(read.table("a")))
:
replacement has 3 rows, data has 0
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