[R] if() for() { }
Nicolas Degallier
Nicolas.Degallier at ird.fr
Fri Feb 16 17:10:05 CET 2007
Dear R'helpers,
I guess the solution is trivial but despite some hours of testing and
looking at the doc, I was unable to fix the following problem.
I want to do either:
for (i in 1:lat) a[i,which(a[i,]==0] <- NA
or:
for (i in 1:lat) a[i,which(a[i,]==-9999|a[i,]==9999|a[i,]==9998|a[i,]
==-9998)] <- NA
if the word "Time" is or is not present in variable "nomfichier":
test<-grep("Time",nomfichier)
the controlling test would be:
if (test==1)
But in either cases I obtain:
if (grep("Time",nomfichier)>0) for (i in 1:lat) a[i,which(a[i,]==0]
<- NA
Erreur : syntax error
> if (grep("Time",nomfichier)<>0) {for (i in 1:lat) a[i,which(a[i,]
==-9999|a[i,]==9999|a[i,]==9998|a[i,]==-9998)] <- NA}
Erreur : syntax error
>
I would appreciate if someone can show me the right way to do this.
Sincerely
Nicolas
Nicolas Degallier
UMR 7159 / IRD UR182
Laboratoire d'Océanographie et du Climat, Expérimentation et
Approches Numériques (LOCEAN)
Tour 45-55, 4e ét., case 100, 4 place Jussieu
75252 Paris Cedex 5 France
tél: (33) 01 44 27 51 57
fax: (33) 01 44 27 38 05
E-mail: <Nicolas.Degallier at ird.fr>
pdf reprints (login="anonymous"; password="your at email.address"):
ftp://ftp.locean-ipsl.upmc.fr/LOCEAN/ndelod
More information about the R-help
mailing list