[R] Subcripting matrix

Christofer Bogaso bogaso.christofer at gmail.com
Fri Sep 20 12:52:37 CEST 2013


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,



More information about the R-help mailing list