Question: for loop not working!
gravatar for akshay_e4
25 days ago by
akshay_e40 wrote:

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


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

ADD COMMENTlink written 25 days ago by akshay_e40

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 REPLYlink written 25 days ago by Sean Davis21k

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 REPLYlink written 23 days ago by k.vitting.seerup20
Please log in to add an answer.


Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.2.0
Traffic: 424 users visited in the last hour