cbind&rbind

Combine R Objects by Rows or Columns

Package:
base

Take a sequence of vector, matrix or data frames arguments and combine by columns or rows, respectively. These are generic functions with methods for other R classes.

Usage

cbind(..., deparse.level = 1)
rbind(..., deparse.level = 1)
> m<-cbind(1,1:7) # the '1' (= shorter vector) is recycled
 > m     
    [,1] [,2]
[1,] 1 1
[2,] 1 2
[3,] 1 3
[4,] 1 4
[5,] 1 5
[6,] 1 6
[7,] 1 7
> m<-cbind(m,8:14)[,c(1,3,2)]# insert a column中间列,次序是1,3,2 
> m
    [,1] [,2] [,3]
[1,] 1 8 1
[2,] 1 9 2
[3,] 1 10 3
[4,] 1 11 4
[5,] 1 12 5
[6,] 1 13 6
[7,] 1 14 7
> rbind(1,1:4)      
    [,1] [,2] [,3] [,4]
[1,] 1 1 1 1
[2,] 1 2 3 4
posted @ 2012-12-14 12:29  蒋蒋  阅读(2114)  评论(0编辑  收藏  举报