[R] syntax error in function 'for'

Petr Pikal petr.pikal at precheza.cz
Thu May 6 10:18:39 CEST 2004


Hi

On 5 May 2004 at 11:53, John Fox wrote:

> Dear Ulrich,
> 
> I believe that you want ifelse(), not if(), but there are likely some
> other problems lurking here: You're removing missing data
> independently from the several vectors -- unless the NAs are all in
> the same places, things will not work or not work correctly. As well,
> what do you want to happen if the condition fails?

maybe complete.cases() is more appropriate but it also depends on what is A,B,C 
D and what is your real intention.

e.g.
> A<-1:10
> B<-11:20
> C<-101:110
> D<-runif(10)*10
> D
 [1] 3.834122 7.422188 2.741723 2.065324 2.775822 6.991390 1.899406 
7.741244 7.026734 3.417432
> A[5]<-NA
> C[8]<-NA
> D[2]<-NA
> fff<-function(a,b,c) a-b+sqrt(c)
> na.omit(subset(fff(A,B,C), sqrt(D)>2))
[1] 0.2956301 0.4403065
attr(,"na.action")
[1] 2
attr(,"class")
[1] "omit"


Cheers
Petr

> 
> John 
> 
> > -----Original Message-----
> > From: r-help-bounces at stat.math.ethz.ch 
> > [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Ulrich
> > Leopold Sent: Wednesday, May 05, 2004 10:06 AM To: R-help Subject:
> > [R] syntax error in function 'for'
> > 
> > Dear list,
> > 
> > I get a syntax error for the following function:
> > 
> > for(na.omit(sqrt(D))>2) {na.omit(A)-(na.omit(B)+(na.omit(sqrt(C))))}
> > 
> > Any idea what is wrong?
> > 
> > I am using R 1.8.1 on Linux, Kernel 2.4.21-i686.
> > 
> > Regards, Ulrich
> > 
> > --
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html

Petr Pikal
petr.pikal at precheza.cz




More information about the R-help mailing list