Reputation: 5729
I am little confused here:
I have this variable gene <-c("IDH3G", "SSR4" )
. when I do
c(gene,gene)
, I get:
"IDH3G" "SSR4" "IDH3G" "SSR4"
, but when I do cbind (gene, gene)
, I get :
gene gene
[1,] "IDH3G" "IDH3G"
[2,] "SSR4" "SSR4"
Shouldn't this be same as what we get from c(gene,gene)
? Can someone please clarify?
Upvotes: 0
Views: 391
Reputation: 3376
The c
function combine the vectors and generate a vector character.
class(c(gene,gene))
[1] "character"
but cbind (gene, gene)
consider the gene
as a vertical vector and combine them to make a matrix:
class(cbind (gene, gene))
[1] "matrix"
From R help ?cbind
:
Combine R Objects by Rows or Columns
Description:
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.
Upvotes: 3