Hello,

With a little broader searching, I did find a solution by Fernando Saldanha
(http://tolstoy.newcastle.edu.au/R/help/05/04/3559.html):

eval(parse(text = paste('testMatrix', '[1,] <- 4', sep = '')))

Thanks anyway!!

Best,

Dave



On Mon, Feb 8, 2010 at 12:19 AM, Dave Deriso <dder...@ucsd.edu> wrote:

> Hello,
>
> I am attempting to write a function that assigns a value to a row or column
> within the matrix that it runs on. I am, however, having trouble accessing
> the row or column within this dynamic variable. I have looked through the
> archives (nothing there) and read the rules for posting to this list. Please
> help me out!
>
> Here is a sample of the problem:
>
>
> testMatrix = matrix(data=2, nrow=10, ncol=10)
>
> testFunction = function (input)
> {
>     inputName <<- deparse(substitute(input))
>
>     assign(inputName[1,], 4, envir = .GlobalEnv)
> }
>
> #this will give you the error
> testFunction(testMatrix)
>
>
> When I try to access "inputName[1,]" instead of "inputName," it fails.
> Does anyone know how to do this?
>
> Thanks in advance!!
>
>
> Best Regards,
>
> Dave Deriso
> Undergraduate Researcher
> UCSD Psychiatry

        [[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.

Reply via email to