Re: [R] how to deal with vector[0]?

2010-03-25 Thread Sharpie
Jin wrote: Hi, I have a vector with 4 elements, e.g., tau_i=c(100,200,300,400), but potentially tau_i[0]=0. In a for loop, tau_i=c(100,200,300,400) m=4 tau_i[0]=0 # --- ? P_i=1 for(i in 2:m) { P_i = P_i*(tau_i[i-1]-tau_i[i-2]) } Error

[R] how to deal with vector[0]?

2010-03-25 Thread Jin
Hi, I have a vector with 4 elements, e.g., tau_i=c(100,200,300,400), but potentially tau_i[0]=0. In a for loop, tau_i=c(100,200,300,400) m=4 tau_i[0]=0 # --- ? P_i=1 for(i in 2:m) { P_i = P_i*(tau_i[i-1]-tau_i[i-2]) } Error in P_i = P_i * (tau_i[k

Re: [R] how to deal with vector[0]?

2010-03-25 Thread Jin
Hello Charlie, Thanks for your valuable help. You are right. So I changed tau_i=c(100,200,300,400) to tau_i=c(0,100,200,300) because 400 can be defined by another term. I appreciate for your time and knowledge. Best, JinNational Renewable Energy Lab.Golden CO, 80401(303)