1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
| ###############################################################################
# Matrix & Vector concatenation
concat = function(X,collaps="",sepa="",ext=TRUE,roc=3)
{
# PURPOSE: Concatenate the different element of a vector or a matrix,
# with the possibility to do it in columns or in rows
#---------------------------------------------------------
# INPUT:
# * X = Vector or matrix of data
# * sepa = separator if needed
# * ext = separator in exterior of the vector
# * roc = concat in row or columns or all element of the matrix
# -------------------------------------------------------------
# OUTPUT:
# * xma = filtered data
# -------------------------------------------------------------
# C. CARPENTIER (2009)
if( is.null( dim(X) ) ) {
if (ext==TRUE) { ex =collaps } else { ex =""}
paste(ex,paste(X,collapse=collaps,sep=sepa),ex,sep=sepa)
} else {
if (roc ==3) {
Y <- as.vector(X)
concat(Y,collaps,sepa,ext)
} else { apply(X, roc, concat, collaps,sepa, ext) }
}
} |
Partager