First of all, 'colnum' does not exist when the 'paste' is called.  This
probably does what you want:

for (colnum in 1:ncol(A)){
    mmatplot(colnum, 1:nrow(A), A, main=paste("Array input, column",
colnum))
}



On 3/4/07, Thaden, John J <ThadenJohnJ@uams.edu> wrote:
>
> Hello, The code below is supposed to be a wrapper for matplot to
> do columnwise visible comparison of several matrices, but I'm
> doing something wrong because I can't access an argument called
> 'colnum'.  I'd be most grateful for some insight.
>
> Thanks,
> John Thaden
> Little Rock, AR
> ################################
> # mmatplot is a matplot wrapper to compare the same column of
> # several matrices. Arg y is either a list of matrices with
> # equal number of rows, or an array. The scalar n gives the
> # column of each matrix or array slab to plot. par values and
> # matplot args are accepted, e.g., ylog.  mmatplot is intended
> # to be mapply-compatible to test multiple columns.
>
> mmatplot <- function(colnum, x, y, ...){
> switch(class(y),
>    array = y <- y[, colnum, ],
>    list = y <- sapply(X = y, FUN = subset, select = colnum))
> stopifnot(is.matrix(y))
> matplot(x, y, ...)
> }
>
> #This is just a tester function
> mmatplotTest <- function(){
> oldmf <- par("mfrow")
> par(mfrow = c(2,3))
> A <- array(data = rnorm(90), dim = c(10, 3, 3))
> L <- list(A[, , 1], A[, , 2], A[, , 3])
>
> # The 'main' argument below throws the error, but if
> # commented out, another error crops up due to 'colnum'.
> # Test with class(y) == "array"
> mapply(X = 1:ncol(A), FUN = mmatplot, x = 1:nrow(A), y = A,
>                 main = paste("Array input, column", colnum))
> # Test with class(y) == "list"
> mapply(1:ncol(L[[1]]), mmatplot, x = 1:nrow(L[[1]]), y = L,
>                 main = paste("List input, column", colnum))
> par(mfrow = oldmf)
> }
>
> #Run the test
> mmatplotTest()
>
> ______________________________________________
> R-help@stat.math.ethz.ch 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.
>



-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem you are trying to solve?

	[[alternative HTML version deleted]]

