for loop not working!
0
0
Entering edit mode
akshay_e4 • 0
@akshay_e4-14421
Last seen 6.3 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....!!!!!!!

code not working properly • 738 views
ADD COMMENT
0
Entering edit mode

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. 

ADD REPLY
0
Entering edit mode

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).

ADD REPLY

Login before adding your answer.

Traffic: 756 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6