These are all great resposes but I think I should have given a slightly more complete description of the problem.
I am using the quantmod package and I have called getSymbols with a character vector that has a list of stock symbols. For example: library("quantmod") list=c("MSFT","AAPL","ORCL") getSymbols(list) this returns 3 objects (MSFT,AAPL, ORCL) now imagine that I want to use the Delt function (also in quantmod) to calculate the percent difference for each of these stocks using their closing price. each closing price is SYMBOL$SYMBOL.Close (can also be retrieved with Cl(SYMBOL) I want to construct the call to Delt with the symbols in list appended with $SYMBOL.Adjusted in other words I want a way to create Delt(MSFT$MSFT.Close) merged with Delt(AAPL$AAPL.Close) and so on (one object having the result of the Delt function for each stock). I am sure that there are many ways to solve this particular problem. Perhaps what I need to understand is how to take the characters in the list and construct an expression and then evaluate the expression. On Feb 5, 2009, at 5:50 PM, <markle...@verizon.net> wrote: > Hi: there's mget but I couldn't figure out how to use it. if you > figure > it out, let me know. > I'm sure one of the guRus will reply with something that uses mget. > List > is slow now > because Europe is sleeping. Good luck. > > > > > On Thu, Feb 5, 2009 at 5:42 PM, Ira Fuchs wrote: > > > Thanks, that is better but doesn't actually solve my problem which > is > > that n is an arbitrary length vector and I'd like to find a way that > > avoids having to enumerate the elements of the character vector. > > Thanks, > > Ira > > ----- Original Message ----- > > From: markle...@verizon.net <markle...@verizon.net> > > To: Fuchs Ira <irafu...@gmail.com> > > Sent: Thu Feb 05 17:25:39 2009 > > Subject: RE: [R] eval and as.name > > > > > > Hi: below works but it's not much shorter than yours. there must > be a > > better way so I'm sending off line in order to encourage better > > replies. > > > > sum(get(n[1]),get(n[2])) > > > > > > > > > > On Thu, Feb 5, 2009 at 5:10 PM, Fuchs Ira wrote: > > > >> I'm sure there is a more general way to ask this question but how > do > >> you use the elements of a character vector as names of objects in > an > >> expression? > >> For example, say you have: > >> > >> a = c(1,3,5,7) > >> b = c(2,4,6,8) > >> > >> n=c("a","b") > >> > >> and you want to use the names a and b in a function (e.g. sum) > >> > >> sum(eval(as.name(n[1])),eval(as.name(n[2]))) > >> > >> works but > >> > >> what is a simpler way to effect this level of indirection? > >> > >> ______________________________________________ > >> 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. > [[alternative HTML version deleted]] ______________________________________________ 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.