tags:

views:

175

answers:

1

I'm using the quantmod package to import financial series data from Yahoo.

library(quantmod)
getSymbols("^GSPC")
[1] "GSPC"

I'd like to change the name of object "GSPC" to "SPX". I've tried the rename function in the reshape package, but it only changes the variable names. The "GSPC" object has vectors GSPC.Open, GSPC.High, etc. I'd like my renaming of "GSPC" to "SPX" to also change GSPC.Open to SPX.Open and so on.

+1  A: 

Renaming an object and the colnames within it is a two step process:

SPY <- GSPC # assign the object to the new name (creates a copy)
colnames(SPY) <- gsub("GSPC", "SPY", colnames(SPY)) # rename the column names

Otherwise, the getSymbols function allows you to not auto assign, in which case you could skip the first step (you will still need to rename the columns).

SPY <- getSymbols("^GSPC", auto.assign=FALSE)
Shane
The gsub() function works perfectly for my purposes. Thank again Shane.
Milktrader