Re: [Rd] vector labels are not permuted properly in a call to sort() (R 2.1)

2005-10-05 Thread David James
Martin Maechler wrote:
> > "AndyL" == Liaw, Andy <[EMAIL PROTECTED]>
> > on Tue, 4 Oct 2005 13:51:11 -0400 writes:
> 
> AndyL> The `problem' is that sort() does not doing anything special when 
> given
> AndyL> a matrix: it only treat it as a vector.  After sorting, it copies
> AndyL> attributes of the original input to the output.  Since dimnames are
> AndyL> attributes, they get copied as is.
> 
> exactly. Thanks Andy.
> 
> And I think users would want this (copying of attributes) in
> many cases; in particular for user-created attributes
> 
> ?sort  really talks about sorting of vectors and factors;
>and it doesn't mention attributes explicitly at all
>{which should probably be improved}.
> 
> One could wonder if R should keep the dim & dimnames
> attributes for arrays and matrices.  
> S-plus (6.2) simply drops them {returning a bare unnames vector}
> and that seems pretty reasonable to me.

This is as described in the Blue book, p.146, "Throwing Away Attributes".

> 
> At least the user would never make the wrong assumptions that
> Greg made about ``matrix sorting''.
> 
> 
> AndyL> Try:
> 
> >> y <- matrix(8:1, 4, 2, dimnames=list(LETTERS[1:4], NULL))
> >> y
> AndyL> [,1] [,2]
> AndyL> A84
> AndyL> B73
> AndyL> C62
> AndyL> D51
> >> sort(y)
> AndyL> [,1] [,2]
> AndyL> A15
> AndyL> B26
> AndyL> C37
> AndyL> D48
> 
> AndyL> Notice the row names stay the same.  I'd argue that this is the 
> correct
> AndyL> behavior.
> 
> AndyL> Andy
> 
> 
> >> From: Greg Finak
> >> 
> >> Not sure if this is the correct forum for this, 
> 
> yes, R-devel is the proper forum.
> {also since this is really a proposal for a change in R ...}
> 
> >> but I've found what I  
> >> would consider to be a potentially serious bug to the 
> >> unsuspecting user.
> >> Given a numeric vector V with class labels in R,  the following calls
> >> 
> >> 1.
> >> > sort(as.matrix(V))
> >> 
> >> and
> >> 
> >> 2.
> >> >as.matrix(sort(V))
> >> 
> >> produce different ouput. The vector is sorted properly in 
> >> both cases,  
> >> but only 2. produces the correct labeling of the vector. The call to  
> >> 1. produces a vector with incorrect labels (not sorted).
> >> 
> >> Code:
> >> >X<-c("A","B","C","D","E","F","G","H")
> >> >Y<-rev(1:8)
> >> >names(Y)<-X
> >> > Y
> >> A B C D E F G H
> >> 8 7 6 5 4 3 2 1
> >> > sort(as.matrix(Y))
> >> [,1]
> >> A1
> >> B2
> >> C3
> >> D4
> >> E5
> >> F6
> >> G7
> >> H8
> >> > as.matrix(sort(Y))
> >> [,1]
> >> H1
> >> G2
> >> F3
> >> E4
> >> D5
> >> C6
> >> B7
> >> A8
> >>
> 
> __
> R-devel@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel


--
David

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


[Rd] write.table and segment fault?

2006-03-29 Thread David James
Hi,

I'm experiencing R segmentation faults on multiple versions of R
when writing out a particular data.frame:

   ## dd is a 44 by 3 data.frame

   load(url("http://stat.bell-labs.com/RS-DBI/download/dd.rda";))
   write.table(dd, file = "dd.csv", sep = ",", row.names = FALSE)

this occurs on

> sessionInfo()
  R version 2.2.0, 2005-10-06, i686-pc-linux-gnu

  attached base packages:
  [1] "methods"   "stats" "graphics"  "grDevices" "utils" "datasets"
  [7] "base"

> sessionInfo()
  R version 2.2.1, 2005-12-20, i686-pc-linux-gnu
 
  attached base packages:
  [1] "methods"   "stats" "graphics"  "grDevices" "utils" "datasets"
  [7] "base"

> sessionInfo()
  Version 2.3.0 alpha (2006-03-27 r37590)
  i686-pc-linux-gnu
 
  attached base packages:
  [1] "methods"   "stats" "graphics"  "grDevices" "utils" "datasets"
  [7] "base"
  > load("dd.rda")
  > write.table(dd, file = "dd.csv", sep=",", row.names = TRUE)
 
   *** caught segfault ***
  address 0x18, cause 'memory not mapped'
 
  Traceback:
   1: write.table(dd, file = "dd.csv", sep = ",", row.names = TRUE)
   
  Possible actions:
  1: abort (with core dump)
  2: normal R exit
  3: exit R without saving workspace
  4: exit R saving workspace
  Selection: 3

--
David

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel