An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20100730/c3e5d5a8/attachment.pl>
conditonal "if"
3 messages · putri wikie, Wu Gong, Erik Iverson
I replicated your error.
tau2ca <- NA
if (tau2ca==0) {x <- 0.01} else {x <- tau2ca}
Hope it helps. And I couldn't replicate your second program, but it seems
ok.
-----
A R learner.
View this message in context: http://r.789695.n4.nabble.com/conditonal-if-tp2308568p2308578.html Sent from the R help mailing list archive at Nabble.com.
On 07/30/2010 06:04 PM, putri wikie wrote:
Hi,
I have problem with my R program. Actually, it just a simple program, but I do
not know the error is. Here is part of my program:
....
if (tau2ca==0) {MVvc<- 0.01} else {MVvc<- tau2ca}
ri_vc<- si2/MVvc
vi_vc<- ri_vc + 1
Y_bar_vc<- sum(y/vi_vc)/sum((1/vi_vc))
tau2MVvc<- sum((1/vi_vc)*(y - Y_bar_vc)^2)/(k-1)
....
But then, there is an error displayed in workspace
Error in if (tau2ca == 0) { : missing value where TRUE/FALSE needed
I do not know why there is an error like that.
R is telling you exactly why there is an error. The "if" statement needs to evaluate to TRUE or FALSE, but it is evaluating to a missing value (e.g., NA). tau2ca is probably NA at that point. Since you don't provide a reproducible example as the posting guide asks, I have no idea why it is missing. > Also, I just want to make sure whether my program below is right or
not.
for (l in 1:k)
{if (a[l]==0 | b[l]==0 | c[l]==0 | d[l]==0)
{ a[l]<- a[l]+0.5
b[l]<- b[l]+0.5
c[1]<- c[1]+0.5
d[1]<- d[1]+0.5
}
}
Since this is not self-contained, nor are your objectives stated, there is no way to tell you wheter or not the program is "correct". There is surely a vectorized/list approach to what you want to do.