[R] how to assign a value?

Patrick Burns pburns at pburns.seanet.com
Sun Dec 11 18:16:29 CET 2011


You are basically in R Inferno Circle 8.1.40.

http://www.burns-stat.com/pages/Tutor/R_inferno.pdf

On 11/12/2011 15:27, Jinsong Zhao wrote:
> Hi there,
>
> I hope to modify values in a vector or matrix in the following code:
>
> for (i in 1:9) {
> assign(paste("a.", i, sep = ""), 1:i)
> get(paste("a.", i, sep = ""))[i] <- i+50
> }
>
> I get the following error message:
>
> Error in get(paste("a.", i, sep = ""))[i] <- i + 50 :
> target of assignment expands to non-language object
>
> I have read the FAQ "How can I turn a string into a variable?", however,
> I don't find a way to deal with:
>
> get(paste("a.", i, sep = ""))[i] <- i+50
>
> Any suggestions? Thanks in advance!
>
> Regards,
> Jinsong
>
> ______________________________________________
> R-help at 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.
>

-- 
Patrick Burns
pburns at pburns.seanet.com
twitter: @portfolioprobe
http://www.portfolioprobe.com/blog
http://www.burns-stat.com
(home of 'Some hints for the R beginner'
and 'The R Inferno')



More information about the R-help mailing list