I thought that's what I had:

> b
[1] "MSFT$MSFT.Adjusted"
> eval(as.name(b))
Error in eval(expr, envir, enclos) :
  object "MSFT$MSFT.Adjusted" not found

However, Patrick's suggestion of eliminating the '$' gave me what I was looking for:

> b=paste(a,'.Adjusted',sep='')
> eval(as.name(a))[,b]
           MSFT.Adjusted
2009-03-02         15.79
2009-03-03         15.88
2009-03-04         16.12

Thanks for your help.

On Mar 5, 2009, at 11:33 AM, Wacek Kusnierczyk wrote:

Fuchs Ira wrote:
Can someone please tell me why the following (last line) doesn't work
(as I expect it to :-)

library(quantmod)
a = getSymbols("MSFT",from="2009-3-01")
a
MSFT
eval(as.name(a))
MSFT$MSFT.Adjusted
b=paste(a,'$MSFT.Adjusted',sep='')
b
eval(as.name(b))

Why does this last line not work the way the earlier eval does?


because eval(as.name(b)) looks for `MSFT$MSFT.Adjusted`, not for
`MSFT`$`MSFT.Adjusted`:

   'MSFT$MSFT.Adjusted' = 'rubbish'
   eval(as.name(b))
   # "rubbish"

vQ

______________________________________________
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.

Reply via email to