[R] 1.8.1 behavior change?

Al Piszcz apiszcz at solarrain.com
Sat Nov 22 23:07:49 CET 2003


Thank you very much!

This method works with R 1.8.0 and R 1.8.1



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 <- vector("list", 4)
> stt[[1]]<-as.matrix(read.table("a"))
> stt[[2]]<-as.matrix(read.table("b"))
> stt[[3]]<-as.matrix(read.table("c"))
> stt[[4]]<-as.matrix(read.table("d"))
> stt.allmat <- do.call("rbind", stt)
> stt
[[1]]
  V1 V2 V3
1  1  2  3
2  4  5  6
3  7  8  9

[[2]]
  V1 V2 V3
1 10 11 12
2 13 14 15
3 16 17 18

[[3]]
  V1 V2 V3
1 19 20 21
2 22 23 24
3 25 26 27

[[4]]
  V1 V2 V3
1 28 29 30
2 31 32 33
3 34 35 36
4 37 38 39

> stt[[4]]
  V1 V2 V3
1 28 29 30
2 31 32 33
3 34 35 36
4 37 38 39






On Sat, 22 Nov 2003, Patrick
Burns wrote:

> Date: Sat, 22 Nov 2003 21:25:56 +0000
> From: Patrick Burns <pburns at pburns.seanet.com>
> To: Al Piszcz <apiszcz at solarrain.com>
> Subject: Re: [R] 1.8.1 behavior change?
>
> I would suggest a list that is n long, or alternatively rbind
> the matrices together (assuming that the columns all have
> the same meaning and are in the same order).
>
> stt <- vector("list", n)
> for(i in 1:n) stt[[i]] <- as.matrix(read.table(... ))
>
> stt.allmat <- do.call("rbind", stt)
>
> Patrick Burns
>
> Burns Statistics
> patrick at burns-stat.com
> +44 (0)20 8525 0696
> http://www.burns-stat.com
> (home of S Poetry and "A Guide for the Unwilling S User")
>
> Al Piszcz wrote:
>
> >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
> >>
> >>
> >>
> >
> >______________________________________________
> >R-help at stat.math.ethz.ch mailing list
> >https://www.stat.math.ethz.ch/mailman/listinfo/r-help
> >
> >
> >
> >
>
>




More information about the R-help mailing list