Re: [R] how to replace text...

From: Sean Davis <>
Date: Mon 02 May 2005 - 10:44:01 EST


Just for future reference, you can send replies to the list--everyone benefits then.

I'm not sure how pricelts works, but you can type ?pricelts to see. It is possible that pricelts takes a vector of stock names. You need to look at the "Value" part of the help to see what pricelts returns. Depending on how pricelts works, much of the work may be done for you.

However, if you have a vector of stock names like:

stocks <- c('IBM','QQQ','RRR')

You could do something like:

stocklist <- list()

Then, stocklist will be a list that can be accessed like:


Or, to plot all of them, you could do:

par(ask=T) #this will ask you to hit return before making a plot lapply(stocklist,plot) #this will go through each stock in stocklist one at a time, plotting each one, asking you to press return between each plot

Remember, anything command above you don't understand (actually, every command at LEAST once) deserves a FULL read of the documentation. If it doesn't make sense, that is OK, but then read it again after a bit. Also, remember that almost every command has an example (or several examples) that you can see if you type:



sorry for so long in getting back. It does work (only error was priceIts vs priceits), however the faq 7.21 deals with "7.21 How can I turn a string into a variable?" - not sure what this has to do with lists.

While I have more reading to do, my goal is to do what you mentioned but instead of having to retype

pricelist[['STOCK']] <- pricelts('STOCK',quote="Close")

for each stock, if I could somehow have it reference a file with all the tickers and loop through them. I am sure as I get through all the R material I will figure this out, but if you know in advance that would be great. Regards/Jonathan

On 4/29/05, Sean Davis <> wrote:
> On Apr 29, 2005, at 6:11 AM, Jonathan Q. wrote:
> > if I have....
> >
> > QQQQ<-priceIts("QQQQ",quote="Close")
> > QQQQ<-priceIts("QQQQ",quote="Close");plot(QQQQ)
> >
> > and then i want to do the same thing but say with IBM instead of QQQQ
> > is there an easy way like replace qqqq/ibm
> >
> You should probably use a list instead. This is a FAQ (see 7.21):
> Here is about how you might do it (untested):
> pricelist <- list()
> pricelist[['IBM']] <- pricelts('IBM',quote="Close")
> pricelist[['QQQQ']] <- pricelts('QQQQ',quote="Close")
> par(ask=T)
> lapply(pricelist,plot)
> Does this do what you want?
> Sean


______________________________________________ mailing list
PLEASE do read the posting guide!
Received on Mon May 02 10:47:45 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:31:31 EST