[R] rbind ing matrices and resetting column numbers
David Winsemius
dwinsemius at comcast.net
Thu Oct 14 16:40:47 CEST 2010
On Oct 14, 2010, at 10:31 AM, Maas James Dr (MED) wrote:
> Sorry for the verbose example. I want to row bind two matrices, and
> all works except I want the column labelled "row" to be sequential
> in the new matrix, shown as "mat3" here, i.e. needs to be 1:6 and
> not 1:3 repeated twice. Any suggestions?
cbind( row=1:sum(nrow(mat1),nrow(mat2)),
rbind(mat1[ ,-1],mat2[ ,-1])
)
--
David.
>
> Thanks
>
> J
>
>> colnm1 <- c("row","ti","counti")
>> colnm2 <- c("row","tj","countj")
>> mat1 <- matrix(c(1,7,9,2,8,5,3,7,9),byrow=T,nrow=3)
>> colnames(mat1) <- colnm1
>> mat1
> row ti counti
> [1,] 1 7 9
> [2,] 2 8 5
> [3,] 3 7 9
>> mat2 <- matrix(c(1,5,3,2,6,8,3,3,7),byrow=T,nrow=3)
>> colnames(mat2) <- colnm2
>> mat2
> row tj countj
> [1,] 1 5 3
> [2,] 2 6 8
> [3,] 3 3 7
>> mat3 <- rbind(mat1,mat2)
>> mat3
> row ti counti
> [1,] 1 7 9
> [2,] 2 8 5
> [3,] 3 7 9
> [4,] 1 5 3
> [5,] 2 6 8
> [6,] 3 3 7
>
>
> ===============================
> Dr. Jim Maas
> University of East Anglia
>
>
> [[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.
David Winsemius, MD
West Hartford, CT
More information about the R-help
mailing list