[R] Help Getting the Price of Gold

Duncan Murdoch murdoch.duncan at gmail.com
Thu Oct 23 15:13:56 CEST 2014


On 23/10/2014, 8:56 AM, Robert Sherry wrote:
> I am trying to get the current price of gold for my application. I am 
> using the library quantmod. The
> R commands I use are:
>       getMetals(c('XAU'), from=Sys.Date(), autoassign = FALSE )
>       XAUUSD$XAU.USD[1,1]
> 
> I would expect the value in  XAUUSD$XAU.USD[1,1] to be a scalar but it 
> comes back with a date and a number. All I want is the current value, 
> not today's date. How do I just get the value?

That function returns time series objects (of class c("xts", "zoo")).
Use as.numeric() to convert to plain numbers, e.g.

as.numeric(XAUUSD$XAU.USD[1,1])

Duncan Murdoch



More information about the R-help mailing list