Jonathan,
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()
sapply(stocks,pricelts,quote="Close")
Then, stocklist will be a list that can be accessed like:
plot(stocklist[["IBM"]])
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:
example(command)
Sean
----- Original Message -----
From: "Jonathan Q." <jqm475 at gmail.com>
To: "Sean Davis" <sdavis2 at mail.nih.gov>
Sent: Sunday, May 01, 2005 2:23 PM
Subject: Re: [R] how to replace text...
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 <sdavis2 at mail.nih.gov>
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):
>
> http://cran.r-project.org/doc/FAQ/R-FAQ.html
>
> 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
>
>
--
Jonathan
jqm475 at gmail.com