[R] Subcripting matrix

Olivier Crouzet olivier.crouzet at univ-nantes.fr
Fri Sep 20 13:19:07 CEST 2013


Hi,

it seems the following works as needed...

Mat[,colnames(Mat)=="a"]

Olivier.

On Fri, 20 Sep 2013 16:22:37 +0530
Christofer Bogaso <bogaso.christofer at gmail.com> wrote:

> Hello again,
> 
> I have one question on subscripting matrix. Let say I have following
> matrix:
> 
> > Mat <- matrix(1:9, 3)
> > colnames(Mat) <- c("a", "b", "a")
> > Mat
>      a b a
> [1,] 1 4 7
> [2,] 2 5 8
> [3,] 3 6 9
> 
> 
> Now I want to fetch data for colnames 'a'.I did following:
> 
> > Mat[, "a"]
> [1] 1 2 3
> 
> 
> However it is not taking second 'a' colume. Basically I expected to
> get 1st and 3rd columns
> 
> Can somebody tell me how to achieve that?
> 
> Thanks and regards,
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html and provide commented,
> minimal, self-contained, reproducible code.


-- 
  Olivier Crouzet, PhD
  Laboratoire de Linguistique -- EA3827
  Université de Nantes
  Chemin de la Censive du Tertre - BP 81227
  44312 Nantes cedex 3
  France

     phone:        (+33) 02 40 14 14 05 (lab.)
                   (+33) 02 40 14 14 36 (office)
     fax:          (+33) 02 40 14 13 27
     e-mail:       olivier.crouzet at univ-nantes.fr
 		
  http://www.lling.univ-nantes.fr/



More information about the R-help mailing list