2016-03-19 41 views
0

我有點困惑在這裏: 我有這個變量gene <-c("IDH3G", "SSR4")。當我做 c(gene,gene),我得到: "IDH3G" "SSR4" "IDH3G" "SSR4",但是當我做cbind (gene, gene),我得到:cbind和結合在R

gene gene 
[1,] "IDH3G" "IDH3G" 
[2,] "SSR4" "SSR4" 

不應該這個是一樣的我們從c(gene,gene)得到什麼?有人可以澄清?

+0

你期待cbind(矩陣(基因,nrow = 1),矩陣(基因,nrow = 1))嗎? – baptiste

+0

@baptiste是的,這就是我期待的,就像'gene'有多行一樣。 – MAPK

回答

2

c函數結合了矢量並生成一個矢量字符。

class(c(gene,gene)) 
[1] "character" 

cbind (gene, gene)考慮gene作爲垂直向量,並結合他們作出一個矩陣:

class(cbind (gene, gene)) 
[1] "matrix" 

從r幫助?cbind

的行或列

合併[R對象

描述:

Take a sequence of vector, matrix or data-frame arguments and 
combine by _c_olumns or _r_ows, respectively. These are generic 
functions with methods for other R classes. 
+0

謝謝,明白了! 'cbind'總是在整個矩陣中以蛇形順序排列矢量元素。 – MAPK