On 11-05-14 4:14 AM, Sparks, John James wrote:
Dear R Helpers,
I am trying to adjust the attribute of an R object pulled from quantmod.
Since I want to do this for many such objects, I was trying to make the
adjustment programmatic. Unfortunately, I am having a huge amount of
trouble using attr in combination with paste (and perhaps get, and perhaps
assign, none of which seem to help). When I hard-code the change it works
fine. Your help would be much appreciated.
require(quantmod)
getFin("NYSE:A")
attr(NYSE.A.f,"symbol")<-"A" #works fine
ticker<-"A"
attr(paste("NYSE.",ticker,".f",sep=""),"symbol")<-"A" #doesn't work
attr(get(paste("NYSE.",ticker,".f",sep="")),"symbol")<-"A" #nor does
this, nor the hundred other combinations I have tried
This should work:
name <- paste("NYSE.",ticker,".f",sep="")
x <- get(name)
attr(x, "symbol") <- "A"
assign(name, x)
Duncan Murdoch
______________________________________________
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.