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) 
275-4642jinsuk....@nrel.gov
Date: Thu, 25 Mar 2010 07:48:40 -0800
From: ml-node+1690861-886360020-66...@n4.nabble.com
To: realst...@hotmail.com
Subject: Re: how to deal with vector[0]?




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


I'm a little confused on exactly what you're trying to achieve here-- vector 
indexes in R start at 1, not 0, and so trying to assign any value to tau_i[ 0 ] 
is meaningless.


Using tau_i[ 0 ] in a calculation is equivalent to using numeric( 0 ) -- i.e. a 
numeric vector of *length* zero, which contains no values at all.


Does this help?


-CçCharlie Sharpsteen

Undergraduate-- Environmental Resources Engineering

Humboldt State University





View message @ 
http://n4.nabble.com/how-to-deal-with-vector-0-tp1690812p1690861.html


To unsubscribe from how to deal with vector[0]?, click here.


                                          
_________________________________________________________________
Hotmail: Trusted email with powerful SPAM protection.

-- 
View this message in context: 
http://n4.nabble.com/how-to-deal-with-vector-0-tp1690812p1690983.html
Sent from the R help mailing list archive at Nabble.com.

        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to