Re: [R] Changing Attribute With Paste

From: Duncan Murdoch <murdoch.duncan_at_gmail.com>
Date: Sat, 14 May 2011 06:42:35 -0400

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_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. Received on Sat 14 May 2011 - 10:45:06 GMT

This quarter's messages: by month, or sorted: [ by date ] [ by thread ] [ by subject ] [ by author ]

All messages

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sat 14 May 2011 - 11:40:07 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive