I am trying to write a small program in R that will randomly select a stock from the NYSE and display that stock's YTD information in a data.frame.
I currently have:
Stock.List<-data.frame(StockListNew)
colnames(Stock.List)<-c("Number", "Ticker", "Company Name")
# Renamed Columns to number, ticker and company name
random.stock<-sample.rows(data.frame(Stock.List),1,replace=TRUE)
Stock.List[sample.int(3284,size=1,replace=TRUE),2]
#Selects a Random Stock Ticker and Name from Stock.List
So far this has worked for me. When I run...
Stock.List[sample.int(3284,size=1,replace=TRUE),2]
I successfully return the random ticket in the console, for example:
> Stock.List[sample.int(3284,size=1,replace=TRUE),2]
[1] WPP
3284 Levels: A AA AA-B AAC AAN AAP AAT AAV AB ABB ABBV ... ZX
I end up getting the second line which I don't understand why R is relisting the Stock.List as levels.
Ultimately my goal is to then have R open quantmod and use the getSymbols() function to grab the random stock I selected and download the data.frame from January 1st, 2015 to Dec 18th, 2015.
I know that I need to get the randomly selected stock into a string(?) to properly use the getSymbols function.
Sorry if my language is not proper I am brand new to R and programming languages.