[R] problem with putting Hmisc labeled matrix into a data.frame.

John Kane jrkrideau at yahoo.ca
Mon Mar 26 20:06:33 CEST 2007


# I seem to be having a bit of a problem with Hmisc.
At least, I assume it is
# coming from there. When I try to put a labeled
matrix into a data.frame
# I get a very strange result. If you would run the
two examples I think
# you will see my problem.

# Example 1  no label
library(Hmisc)
mydata <- matrix(1:12, 3, 4)
myvec <- matrix( c("a","b","c"), 3)

mf <- data.frame(myvec, mydata) ; mf    # works fine

#  with label

ndata <- matrix(1:12, 3, 4)
label(ndata) <- "Great matrix"
nvec <- matrix( c("a","b","c"), 3)

nf <- data.frame(nvec, ndata) ; nf   #  Not so fine


>
> nf <- data.frame(nvec, ndata) ; nf   #
   nvec ndata.1 ndata.2 ndata.3 ndata.4
1     a       1       4       7      10
2     b       2       5       8      11
3     c       3       6       9      12
4     a    <NA>    <NA>    <NA>    <NA>
5     b    <NA>    <NA>    <NA>    <NA>
6     c    <NA>    <NA>    <NA>    <NA>
7     a    <NA>    <NA>    <NA>    <NA>
8     b    <NA>    <NA>    <NA>    <NA>
9     c    <NA>    <NA>    <NA>    <NA>
10    a    <NA>    <NA>    <NA>    <NA>
11    b    <NA>    <NA>    <NA>    <NA>
12    c    <NA>    <NA>    <NA>    <NA>
Warning message:
corrupt data frame: columns will be truncated or
padded with NAs in: format.data.frame(x, digits =
digits, na.encode = FALSE)
>


# Am I missing something obvious or should I bring
this to the
# attention of the package maintainer?  I did not find
anything in the archives.

# Running Windows XP,  R 2.4.1



More information about the R-help mailing list