[R] remembering the state of an action in R....

akshay kulkarni @k@h@y_e4 @end|ng |rom hotm@||@com
Sun Dec 11 18:11:07 CET 2022


Dear members,
                            I am a stock trader and using R for my research. I am monitoring stock prices in real time. I have the following code:

> if (sock price q, breaches a certain value Q) { expr1; expr2; expr3}

THe point is, expr1,expr2,expr3 should execute only once, i.e when q breaches Q. I thought of something like this:

> if( q >= Q ) { expr1; expr2; expr3;}

But expressions keep repeating as long as q >= Q, NOT when q breaches Q for the first time. I did some research on myself and came up with this:

> f <- function() {expr1; expr2; expr3; j <<- j + 1}
> j <- 1; counter[[j]] <- 1;
> if ((q >= Q)  && length(counter) == 1) {f}

I just want your help to know whether it is logically right or not. ARe not there any other possibility other than using the superassignment operator?

Also, any way how to remember when the real time price q, breaches a value Q, for the first time ( the price may come back to Q again afterwards) ?

THanking you,
Yours sincerely,
AKSHAY M KULKARNI

	[[alternative HTML version deleted]]



More information about the R-help mailing list