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

Jin realstone at hotmail.com
Thu Mar 25 16:22:16 CET 2010


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 - 1] - tau_i[k - 2]): 
  replacement has length zero


Unfortunately, I can add this potential element into "tau_i" because it has
been defined initially and used mainly throughout all procedures.

When I calculate 
> k=2
> tau_i[k-1]-tau_i[k-2]
umeric(0)

But, it should be "100". Is there anyone can help me solve this problem?


Best,

Jin
NREL, Golden CO
(303) 275-4642
-- 
View this message in context: http://n4.nabble.com/how-to-deal-with-vector-0-tp1690812p1690812.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list