So I would like to create a matrix of data in R using a function which I call setupdata. Basically getSymbols get stock data for the given symbols but from a loooong time. I wish to select the latest 60 trading days and therefore has design the following code.
getSymbols(c("GOOG","RBS.L","AAPL","FB"),src="yahoo")
setupdata<- function (x){
data2<-x[(dim(x)[1]-59):dim(x)[1],1:6]
print(data2)
}
setupdata(AAPL)
My problem is that i would like to be able to use "data2" without needing to call the function anymore after running it once. What am i missing out?
If you want to try it for yourself you might need the quantmod library
install.packages("quantmod")
library("quantmod")