I am using getSymbols function from quantmod package to get price data from
internet.
Currently I have:
my.ticker <- "IBM"
getSymbols(my.ticker,src="google")
This creates an xts object named my.ticker which contains historical price
data for IBM.
How can I call and manipulating this xts object using my original string
my.ticker?
I want to do:
colnames(my.ticker) <-
c("open","high","low","close","vol")
However, this does not work as my.ticker refers to the string "IBM"
rather
than the xts object called IBM.
Out of desperation, I have also tried:
colnames(paste(my.ticker)) <-
c("open","high","low","close","vol")
colnames(as.xts(my.ticker)) <-
c("open","high","low","close","vol")
Thanks
Kushan
[[alternative HTML version deleted]]
this works:
colnames(IBM) <-
c("open","high","low","close","vol")
scott
On Wednesday, February 23, 2011 at 7:55 AM, Kushan Thakkar wrote:
> colnames(my.ticker) <-
c("open","high","low","close","vol")
[[alternative HTML version deleted]]
On Feb 23, 2011, at 8:55 AM, Kushan Thakkar wrote:> I am using getSymbols function from quantmod package to get price > data from > internet. > > Currently I have: > > my.ticker <- "IBM" > getSymbols(my.ticker,src="google") > > This creates an xts object named my.ticker which contains > historical price > data for IBM. > > How can I call and manipulating this xts object using my original > string > my.ticker? > > I want to do: > colnames(my.ticker) <- c("open","high","low","close","vol")If you want to change the colnames (an attribute) of the object now named "IBM" in your global environment, then look a: ?attributes ?attr> > However, this does not work as my.ticker refers to the string "IBM" > rather > than the xts object called IBM. > > Out of desperation, I have also tried: > colnames(paste(my.ticker)) <- c("open","high","low","close","vol") > colnames(as.xts(my.ticker)) <- c("open","high","low","close","vol")But why are you do this??? It already has a perfectly servicable set of names: > colnames(get(my.ticker)) [1] "IBM.Open" "IBM.High" "IBM.Low" "IBM.Close" "IBM.Volume" -- David.> > Thanks > Kushan > > [[alternative HTML version deleted]] > > ______________________________________________ > 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.David Winsemius, MD West Hartford, CT
On Wed, Feb 23, 2011 at 8:55 AM, Kushan Thakkar <kthakk4 at gmail.com> wrote:> I am using getSymbols function from quantmod package to get price data from > internet. > > Currently I have: > > my.ticker <- "IBM" > getSymbols(my.ticker,src="google") > > This ?creates an xts object named my.ticker which contains historical price > data for IBM. > > How can I call and manipulating this xts object using my original string > my.ticker? > > I want to do: > colnames(my.ticker) <- c("open","high","low","close","vol") > > However, this does not work as my.ticker refers to the string "IBM" rather > than the xts object called IBM. > > Out of desperation, I have also tried: > colnames(paste(my.ticker)) <- c("open","high","low","close","vol") > colnames(as.xts(my.ticker)) <- c("open","high","low","close","vol")Try this: library(quantmod) ibm <- getSymbols("IBM", src = "google", auto.assign = FALSE) colnames(ibm) <- c("open","high","low","close","vol") -- Statistics & Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com