Skip to content

(no subject)

3 messages · Akhil dua, Hasan Diwan, Rui Barradas

#
Hello,

Or maybe to avoid the typo (Market is column 5), use variables names, in 
something like


myData <- read.table(text="
Date               Stock1  Stock2   Stock3    Market
01/01/2000         1           2          3             4
01/02/2000         5           6          7             8
01/03/2000         1           2          3             4
01/04/2000         5           6          7             8
", header=TRUE, stringsAsFactors=FALSE)
myData$Date <- as.Date(myData$Date, fortmat="%m/%d/%Y")
myData

# Avoid typos
stocks <- grep("Stock", names(myData))
models <- lapply(myData[, stocks], function(x) lm(x ~ myData$Market))

# Do whatever you want with results
lapply(models, summary)


Hope this helps,

Rui Barradas

Em 04-07-2012 06:29, Hasan Diwan escreveu: