[R] Matrix column name

alex lam (RI) alex.lam at bbsrc.ac.uk
Tue May 1 19:03:04 CEST 2007


Dear R users,

Having searched the mail archive I think the conclusion was that it is
not possible to have a column name when there is only one column in the
matrix. But I thought I'd check with the more experienced users.

What I tried to do was: in a loop I pick a column, record the column
name and remove the column from the matrix. But when there were 2
columns left, after one column was removed, the last column name
disappeared by default. It means that I always miss out the last column.

I tried this by hand:  

> matrix.a
            801       802       803
[1,] -0.0906346 0.0906346 0.0906346
[2,] -0.0804911 0.0804911 0.0804911
[3,] -0.0703796 0.0703796 0.0703796
> matrix.a<-as.matrix(matrix.a[,-1])
> matrix.a
           802       803
[1,] 0.0906346 0.0906346
[2,] 0.0804911 0.0804911
[3,] 0.0703796 0.0703796
> matrix.a<-as.matrix(matrix.a[,-1])
> matrix.a
          [,1]
[1,] 0.0906346
[2,] 0.0804911
[3,] 0.0703796

Is there a way to force the column name to remain in such a case?

Thanks,
Alex

> sessionInfo()
R version 2.4.1 (2006-12-18) 
i386-pc-mingw32 

locale:
LC_COLLATE=English_United Kingdom.1252;LC_CTYPE=English_United
Kingdom.1252;LC_MONETARY=English_United
Kingdom.1252;LC_NUMERIC=C;LC_TIME=English_United Kingdom.1252

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

------------------------------------
Alex Lam
PhD student
Department of Genetics and Genomics
Roslin Institute (Edinburgh)
Roslin
Midlothian EH25 9PS
Great Britain

Phone +44 131 5274471
Web   http://www.roslin.ac.uk

Roslin Institute is a company limited by guarantee, registered in
Scotland (registered number SC157100) and a Scottish Charity (registered
number SC023592). Our registered office is at Roslin, Midlothian, EH25
9PS. VAT registration number 847380013.

The information contained in this e-mail (including any attachments) is
confidential and is intended for the use of the addressee only.   The
opinions expressed within this e-mail (including any attachments) are
the opinions of the sender and do not necessarily constitute those of
Roslin Institute (Edinburgh) ("the Institute") unless specifically
stated by a sender who is duly authorised to do so on behalf of the
Institute



More information about the R-help mailing list