>>>>> "Fernando" == Fernando Saldanha <[EMAIL PROTECTED]>
>>>>>     on Thu, 28 Apr 2005 02:01:13 -0400 writes:

    Fernando> Thanks, Prasad. That works. Another alternative is:
    Fernando> eval(parse(text = paste('a', '[1] <- 0', sep = '')))

yes, unfortunately that's an alternative that people seem to use
     "on and on"...

*NO*, that's really not something you should use as an
 --   alternative to assign()!!

I think Peter Dalgaard has a ``paper - yet to be written'' on
the subject that if you use
    eval(parse(text = .....))
you should think twice and try doing it differently.

I'm too busy to go into details but didn't want to let this
"pass" ...

Martin

    Fernando> On 4/27/05, Chalasani, Prasad <[EMAIL PROTECTED]> wrote:
    >> how about
    >> 
    >> assign( 'a', { z <- get('a'); z[1] <- 0; z } )
    >> 
    >> 
    >> -----Original Message-----
    >> From: [EMAIL PROTECTED]
    >> [mailto:[EMAIL PROTECTED] On Behalf Of Fernando Saldanha
    >> Sent: Wednesday, April 27, 2005 3:22 PM
    >> To: Submissions to R help
    >> Subject: [R] assign to an element of a vector
    >> 
    >> I am trying to find a way to assign values to elements of a vector that 
will
    >> be defined by a user. So I don't have the name of the vector and cannot 
hard
    >> code the assignment in advance. In the example below I have to get() the
    >> vector using its name. When I try to assign to an element I get an error:
    >> 
    >> > a <- c(1,2,3)
    >> > get('a')[1] <- 0
    >> Error: Target of assignment expands to non-language object
    >> 
    >> Any suggestions?
    >> 
    >> FS
    >> 
    >> ______________________________________________
    >> [email protected] mailing list
    >> https://stat.ethz.ch/mailman/listinfo/r-help
    >> PLEASE do read the posting guide!
    >> http://www.R-project.org/posting-guide.html
    >> 

    Fernando> ______________________________________________
    Fernando> [email protected] mailing list
    Fernando> https://stat.ethz.ch/mailman/listinfo/r-help
    Fernando> PLEASE do read the posting guide! 
http://www.R-project.org/posting-guide.html

______________________________________________
[email protected] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

Reply via email to