Can R assign values to variables inside loop parenthesis? -
where x set inside parenthesis
i <- 2 for(x <- in x:10) { print(x) } this should print 2,3,4,5,6,7,8,9,10
can done?
essentially trying convert javascript code r
var j = ; var found = false; var counter = 0; var x = 0; var truth = false; var strength = 2; (j = strength;(j < 80)&&(found == false); j++) { price = low(-j); //p=25 x = j + 1; //x=3 truth = true; (x = (j + 1); ((x - j) <= strength)&&(truth); x++) { if (price > low(-x)) truth = false; } x = j - 1; (x = (j - 1);((j - x) <= strength)&&(truth); x--) { if (price >= low(-x)) truth = false; } if (truth) counter++; if (counter >= 1) found = true; } if (found) swinglow = price; else swinglow = -1; the code iterates through time series , finds fractal patterns in financial data.
http://www.timingthemarket.com/uploads/3/0/9/1/3091598/9585500_orig.png?876
if can convert for(***) part should able rest. didn't write original code, , me seems kinda strange way done.
i not sure think asking not possible in r. if use ?"for" can see precise guide for control loops.
here stated cond inside parenthesis must logical vector. in opinion rule out possibilities of assign variable inside cond because if type in console can see that:
> is.logical(x <- 1) [1] false edit
as other users have noted can use code:
for(i in ((x<-i):10)) { print(x) } and works in fact think not reproduces wanted (pointless in opinion) symbol change because guess r interprets saying:
for
iicalledxprevious action onx.
after intent might achieved simpler code like:
> <- 4 > for(i in i:10) print(i) [1] 4 [1] 5 [1] 6 [1] 7 [1] 8 [1] 9 [1] 10 maybe useful , allows not asking variable inside cond of for loops.
Comments
Post a Comment