[R] convert the contents of a date.frame to a matrix

David Winsemius dwinsemius at comcast.net
Sun May 31 18:03:03 CEST 2009


On May 31, 2009, at 10:49 AM, Hongyuan Cao wrote:

> x = read.table("hongyuan_5_30_forsafe.txt", sep = "\t")

 > x = read.table("/Users/davidwinsemius/Downloads/ 
hongyuan_5_30_forsafe.txt", sep = "\t")
 > str(x)
'data.frame':	7131 obs. of  74 variables:
  $ V1 : Factor w/ 7131 levels "","A28102_at",..: 1 934 120 122 118  
126 124 130 128 134 ...
  $ V2 : Factor w/ 5528 levels "","2-Sep","6-Mar",..: 1 5528 NA NA NA  
NA NA NA NA NA ...
  $ V3 : Factor w/ 2375 levels "-1","-10","-100",..: 2374 2375 195 106  
499 2262 287 483 1254 143 ...
  $ V4 : Factor w/ 2326 levels "-1","-10","-100",..: 2325 2326 75 533  
1 1442 231 357 299 117 ...

My guess (which became a conclusion after testing) was that you have  
encountered the stringsAsFactors pitfall. (It's probably in the R  
Inferno someplace bu my favorite quote is from Terry Terneau:
.)

Try reading the table in with stringsAsFactors=FALSE or as.is=TRUE.

After doing that and applying the rest of your code, I get:

 > head(y)
                   X1   X2   X3   X4   X5   X6   X7   X8   X9  X10   
X11  X12  X13  X14  X15  X16  X17
AFFX-BioB-5_at  -214 -139  -76 -135 -106 -138  -72 -413    5  -88  
-165  -67  -92 -113 -107 -117 -476
AFFX-BioB-M_at  -153  -73  -49 -114 -125  -85 -144 -260 -127 -105  
-155  -93 -119 -147  -72 -219 -213
AFFX-BioB-3_at   -58   -1 -307  265  -76  215  238    7  106   42   
-71   84  -31 -118 -126  -50  -18
AFFX-BioC-5_at    88  283  309   12  168   71   55   -2  268  219    
82   25  173  243  149  257  301
AFFX-BioC-3_at  -295 -264 -376 -419 -230 -272 -399 -541 -210 -178 -163  
-179 -233 -127 -205 -218 -403
AFFX-BioDn-5_at -558 -400 -650 -585 -284 -558 -551 -790 -535 -246 -430  
-323 -227 -398 -284 -402 -394
.....
...snipped the rest of the output.


You replied to me only personally which is against R-help practice, so  
I am adding back the list to the address list.

(You should also configure your maile-client so that it sends plain  
text to the r-help list.)

-- 
David Winsemius, MD
Heritage Laboratories
West Hartford, CT



More information about the R-help mailing list