[R] if statement error

2006-10-17 Thread Jenny Stadt
Hi List,

I was not able to make this work. I know it is a simple one, sorry to bother. 
Give me some hints pls. Thanks!

Jen





if(length(real.d)=30  length(real.b)=30  beta1*beta2*theta1*theta20 )

{ r - 1;  corr - 1;  }


real.d and real.b are two vectors, beta1,beta2,theta1,and theta2 are constants. 
The error occurred like this:


Error in if (length(real.d) = 30  length(real.b) = 30  beta1 * beta2 *  : 
missing value where TRUE/FALSE needed

[[alternative HTML version deleted]]

__
R-help@stat.math.ethz.ch 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.


Re: [R] if statement error

2006-10-17 Thread Alberto Monteiro
Jenny Stadt wrote:
 
 I was not able to make this work. I know it is a simple one, sorry 
 to bother. Give me some hints pls. Thanks!
 
Are you a C programmer? :-)

 if(length(real.d)=30  length(real.b)=30  
 beta1*beta2*theta1*theta20 )
 
 { r - 1;  corr - 1;  }
 
I _think_ you should use  instead of . And drop the second ;.

Also, don't forget that return x is wrong [it took me a long
time to figure out that R != C, and it's just return(x)]

Alberto Monteiro

__
R-help@stat.math.ethz.ch 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.


Re: [R] if statement error

2006-10-17 Thread Dieter Menne
Jenny Stadt jennystadt at yahoo.ca writes:

 if(length(real.d)=30  length(real.b)=30  
   beta1*beta2*theta1*theta20 )
 
 { r - 1;  corr - 1;  }
 
 real.d and real.b are two vectors, beta1,beta2,theta1,and theta2 are
 constants. The error occurred like this:
 
 Error in 
 if (length(real.d) = 30  length(real.b) = 30  beta1 * beta2 *  : 
 missing value where TRUE/FALSE needed

Please follow the advice and provide a full example, where beta1 really is
a vector. This works for me below, but it give the message you mentioned if 
you uncomment second line.

Dieter

-
beta1 = beta2 =  theta1 = theta2 = 1.0
#beta1 = NULL
real.d = runif(35)
real.b = runif(35)
r=corr=0
if(
  length(real.d)=30  
  length(real.b)=30  
  beta1*beta2*theta1*theta20 ) { 
  r - 1;  
  corr - 1;  
}

__
R-help@stat.math.ethz.ch 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.


Re: [R] if statement error

2006-10-17 Thread mike waters
Jenny,
are there any missing values in your vectors? If so, what effect do you
think this will have on an expression like that required by the if statement
that must resolve fully to either true or false?

Regards,

Mike

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Jenny Stadt
Sent: 17 October 2006 18:19
To: r-help@stat.math.ethz.ch
Subject: [R] if statement error

Hi List,

I was not able to make this work. I know it is a simple one, sorry to
bother. Give me some hints pls. Thanks!

Jen





if(length(real.d)=30  length(real.b)=30  beta1*beta2*theta1*theta20 )

{ r - 1;  corr - 1;  }


real.d and real.b are two vectors, beta1,beta2,theta1,and theta2 are
constants. The error occurred like this:


Error in if (length(real.d) = 30  length(real.b) = 30  beta1 * beta2 *
: 
missing value where TRUE/FALSE needed

[[alternative HTML version deleted]]

__
R-help@stat.math.ethz.ch 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.

__
R-help@stat.math.ethz.ch 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.


Re: [R] if statement error

2006-10-17 Thread Lucke, Joseph F
Jenny

This following example works: 
 real.d - rep(NA,30)
 real.b - rep(NA,30)
 b1=runif(1); b2=runif(1); t1=runif(1); t2=runif(1)
 if (length(real.d)=30  length(real.b)=30 
b1*b2*t1*t20){bool=TRUE}
 bool
[1] TRUE

But this one doesn't:
 real.d - rep(NA,30)
 real.b - rep(NA,30)
 b1=runif(1); b2=runif(1); t1=runif(1); t2=NA
 if (length(real.d)=30  length(real.b)=30 
b1*b2*t1*t20){bool=TRUE}
Error in if (length(real.d) = 30  length(real.b) = 30  b1 * b2 *
: 
missing value where TRUE/FALSE needed
  

NA's in the vector make no difference.   is correct.
So, it appears at least one of your scalars is missing

JFL

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Jenny Stadt
Sent: Tuesday, October 17, 2006 12:19 PM
To: r-help@stat.math.ethz.ch
Subject: [R] if statement error

Hi List,

I was not able to make this work. I know it is a simple one, sorry to
bother. Give me some hints pls. Thanks!

Jen





if(length(real.d)=30  length(real.b)=30 
beta1*beta2*theta1*theta20 )

{ r - 1;  corr - 1;  }


real.d and real.b are two vectors, beta1,beta2,theta1,and theta2 are
constants. The error occurred like this:


Error in if (length(real.d) = 30  length(real.b) = 30  beta1 *
beta2 *  : 
missing value where TRUE/FALSE needed

[[alternative HTML version deleted]]

__
R-help@stat.math.ethz.ch 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.

__
R-help@stat.math.ethz.ch 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.


Re: [R] if statement error

2006-10-17 Thread Alex Brown

On 17 Oct 2006, at 18:34, Alberto Monteiro wrote:

 Jenny Stadt wrote:

 I was not able to make this work. I know it is a simple one, sorry
 to bother. Give me some hints pls. Thanks!

 Are you a C programmer? :-)

 if(length(real.d)=30  length(real.b)=30 
 beta1*beta2*theta1*theta20 )

 { r - 1;  corr - 1;  }

 I _think_ you should use  instead of . And drop the second ;.


The  is correct in this case.
 is the vector logical AND operator in R (and analogously the  
bitwise logical AND in C)
 is the lazy scalar (atomic) logical AND operator in C and R.  If  
it operates on a vector in R, it ignores all but the first element.   
see help()
since if() in R is scalar (atomic) the  is appropriate.

The second ';' is syntactically correct in R and C, although optional  
in R.

-Alex

Out of interest, for a vector equivalent to if, see help(ifelse)

 Also, don't forget that return x is wrong [it took me a long
 time to figure out that R != C, and it's just return(x)]

 Alberto Monteiro

 __
 R-help@stat.math.ethz.ch 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.

__
R-help@stat.math.ethz.ch 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.


Re: [R] if statement error

2006-10-17 Thread Jenny Stadt
Thank you all for the advice here. I followed the suggestion that check the 
output of the parameters, and found that there might be two possibilities to 
cause the problem. First was there was missing value in real.d / real.b; the 
second was when beta2 was NA. I fixed the data set and the error no longer 
shows up.

Thank you very much!

Jen

-Original Message-
From:Alberto Monteiro ,   [EMAIL PROTECTED]
Sent: 2006-10-17,  11:36:40
To: r-help@stat.math.ethz.ch
CC:
Subject: Re: [R] if statement error
Jenny Stadt wrote:
 
 I was not able to make this work. I know it is a simple one, sorry 
 to bother. Give me some hints pls. Thanks!
 
Are you a C programmer? :-)

 if(length(real.d) =30  length(real.b) =30  
 beta1*beta2*theta1*theta2 0 )
 
 { r  - 1;  corr  - 1;  }
 
I _think_ you should use  instead of . And drop the second ;.

Also, don't forget that return x is wrong [it took me a long
time to figure out that R != C, and it's just return(x)]

Alberto Monteiro

__
R-help@stat.math.ethz.ch 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.

[[alternative HTML version deleted]]

__
R-help@stat.math.ethz.ch 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.