简体   繁体   中英

cbind and combine in R

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?

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. 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM