[R] cbind() function : Not able to display columns

arun smartpink111 at yahoo.com
Wed Oct 23 05:57:50 CEST 2013


Hi,

Try:

  k[,"a"]
#[1] "1" "2" "3"
 k[,"b"]
#[1] "a" "b" "c"
 k[,"c"]
#[1] "ee" "tt" "rr"
A.K.






On Tuesday, October 22, 2013 11:37 PM, Vivek Singh <vksingh.iiitb at gmail.com> wrote:
Hi All,


I have create a matrix using cbind() function as follows:


> a=c(1,2,3)

> b=c('a','b','c')

> c=c("ee","tt","rr")


> k=cbind(a,b,c)


Problem: when we print the matrix k,

> k

    a   b   c

[1,] "1" "a" "ee"

[2,] "2" "b" "tt"

[3,] "3" "c" "rr"

we can see that rows are represented by [1,] , [2,] and [3,]. Similarly,
the columns are denoted by [a], [b] and [c]. When we try to print the
corresponding columns, we are able to print for k[a], i.e., the first
column but not able to correctly print the second and third columns.

> k[a]

[1] "1" "2" "3"

> k[b]

[1] NA NA NA

> k[c]

[1] NA NA NA

Please let me know what am I doing wrong.

-- 
Thanks and Regards,

Vivek Kumar Singh

Research Assistant,
School of Computing,
National University of Singapore
Mobile:(0065) 82721535

    [[alternative HTML version deleted]]

______________________________________________
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.




More information about the R-help mailing list