Entering edit mode
akshay_e4
•
0
@akshay_e4-14421
Last seen 6.8 years ago
I am using R to do some research on stock market.
I am writing a function to take some actions on the stock prices...However the for loop is not working properly:
for (j in 1:length(x)) {
code}
length(x) is 2. j is taking only the first value, i.e 1; if I write 2:length(x) j is taking 2.
outside the function the for loop is functioning well...
PLEASE HELP....!!!!!!!
This site is for support for Bioconductor, not for general R questions. I'd suggest trying stackoverflow if you still have problems after reading more about loops in R.
The code works for me. Have you somehow overwritten the length() function.
To generate robust code it is furthermore advicde to use seq_along(x) instead of 1:length(x).