Dear list! I would like to write a function to transform matrix, which is input argument of a written function. It is easy with new matrix (see below), but my idea is to transform input argument (matrix) of function without any additional matrixes. Here is an example:
fun1 <- function(xy) { xy <- cbind(xy[,1], xy[,2], xy[,1] + xy[,2]) return(xy) } df1 <- matrix(c(1,2,3,1,2,3), ncol = 2) fun1(df1) fun2 <- function(xy) { xy <- cbind(xy[,1], xy[,2], xy[,1] + xy[,2]) return(invisible(xy)) } fun2(df1) df1 > should be [,1] [,2] [,3] [1,] 1 1 2 [2,] 2 2 4 [3,] 3 3 6 Thanks to all for help, OV [[alternative HTML version deleted]]
______________________________________________ R-help@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.