[R] problem with an IF statement?

Peter Dalgaard p.dalgaard at biostat.ku.dk
Thu Jul 28 18:31:08 CEST 2005


tom wright <tom at maladmin.com> writes:

> Can somebody please take a look at this and tell me whats going wrong?
> It seems to be parsing wronly around the 'if' statement and gives me a
> directory listing.
> Thanks in advance
> Tom
> N.B. datan is an invented dataset
> 
> 
> xvals<-c(1,0.4,0.2)
> datan<-data.frame(s1=c(3,4,5),s2=c(5,5,5),s3=c(21,55,34),s4=c(5,3,2))
> 
> datan$sint<-NA
> datan$sgrad<-NA
> for(icount in 1:dim(datan)[1]) {
> 	yvals<-c(datan[icount,4],datan[icount,3],datan[icount,2])
> 	if((is.na(yvals[1]) + is.na(yvals[2]) + is.na(yvals[3]))<2) {
> 		g<-lm(yvals~xvals)
> 		datan$sint[icount]<-g$coef[1]
> 		datan$sgrad[icount]<-g$coef[2]
> 	}
> }


Did you copy+paste it? The TABs will behave as if you pressed the TAB
key... 

        -p

-- 
   O__  ---- Peter Dalgaard             Øster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics     PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark          Ph:  (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)                  FAX: (+45) 35327907




More information about the R-help mailing list