[Rd] problem with as.table (PR#8652)

Peter Dalgaard p.dalgaard at biostat.ku.dk
Thu Mar 2 14:24:29 CET 2006


I.J.Wilson at ncl.ac.uk writes:

> # Your mailer is set to "none" (default on Windows),
> # hence we cannot send the bug report directly from R.
> # Please copy the bug report (after finishing it) to
> # your favorite email program and send it to
> #
> #       r-bugs at r-project.org
> #
> ######################################################
> 
> 
> There is a problem with as.table converting from a matrix with
> more than 26 rows (or columns) .
> 
> rows past 26 are set to <NA>.  This makes operations such as
> turning the data back into a data.frame difficult.
> 
> example causing problems:
> 
> b <-  as.table(matrix(1:60,ncol=2))
> as.integer(as.data.frame(b)[,1])

You can add dimnames to b or the original matrix for a workaround.

Probably the easiest fix is (in as.table.default) to replace

 LETTERS[seq(length = dim(x)[i])]

with 

 make.unique(LETTERS[seq(from=0, length = dim(x)[i]) %% 26 + 1], sep="")

The effect would be like

> make.unique(LETTERS[(0:59)%%26+1], sep="")
 [1] "A"  "B"  "C"  "D"  "E"  "F"  "G"  "H"  "I"  "J"  "K"  "L"  "M"  "N"  "O"
[16] "P"  "Q"  "R"  "S"  "T"  "U"  "V"  "W"  "X"  "Y"  "Z"  "A1" "B1" "C1" "D1"
[31] "E1" "F1" "G1" "H1" "I1" "J1" "K1" "L1" "M1" "N1" "O1" "P1" "Q1" "R1" "S1"
[46] "T1" "U1" "V1" "W1" "X1" "Y1" "Z1" "A2" "B2" "C2" "D2" "E2" "F2" "G2" "H2"

Users might prefer a different scheme, but wouldn't really deserve
it... (If they want otherwise, they can just set it themselves).



-- 
   O__  ---- Peter Dalgaard             Øster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics     PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark          Ph:  (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)                  FAX: (+45) 35327907



More information about the R-devel mailing list