samedi 26 décembre 2015

if statement to indicate whether a market has gone up or down

I have a dataset from library(ISLR) and I would like to make my own up and down, but my if statement always fail, any help would be appreciated:

library(ISLR)
attach(Smarket)

for (i in 1:nrow(Smarket)){
Smarket$myown = ()
if (Smarket[i, "Today"]>0) { Smarket$myown = "Up"
} else { Smarket$myown = "Down"
}}

Please note that if I use the statement ifelse then the issue is solved, but I want your help to MODIFY the above code, so I may learn

 Smarket$myown = ifelse(Smarket[, "Today"]> 0, "Up", "Down")  

Aucun commentaire:

Enregistrer un commentaire