Benjamin, Dimitris,
Thanks very much. Neat work!
Murali
-Original Message-
From: Nutter, Benjamin [mailto:nutt...@ccf.org]
Sent: 27 March 2009 13:52
To: MENON Murali; r-help@r-project.org
Subject: RE: [R] adding matrices with common column names
Shucks, Dimitris beat me to it. And his
Shucks, Dimitris beat me to it. And his code is a bit more elegant than
mine. But since I did the work I may as well post it, right?
This version incorporates a couple of error checks to make sure all your
arguments are matrices with the same number of rows.
add.by.name <- function(...){
args
one approach is:
a <- matrix(1:20,ncol=4); colnames(a) <- c("a","b","c","d")
b <- matrix(1:20,ncol=4); colnames(b) <- c("b","c","d", "e")
cc <- matrix(1:10,ncol=2); colnames(cc) <- c("e","f")
f <- function (...) {
mat.lis <- list(...)
unq.cnams <- unique(unlist(lapply(mat.lis, colnames))
3 matches
Mail list logo