On 02/05/2007 8:11 AM, elyakhlifi mustapha wrote: > hello, > I need help because I don't understand the syntaxe "else" how can I write it > for example I writed a script to cut missings values and I have errors > >> if(na==length(C)){ > + pos=match(0,match(donGeno[[na-1]],donGeno[[na]],nomatch=0)) > + for(k in 1:(na-1)) { > + if(pos==1) {donGeno[[k]] <- > donGeno[[k]][2:C[k]]} > + if(pos==C[k]){donGeno[[k]] <- donGeno[[k]][1:(C[k]-1)]} > + else{donGeno[[k]] <- > c(donGeno[[k]][1:(pos-1)],donGeno[[k]][(pos+1):C(k)])} > + } > + } >> if(na==1){ > + pos=match(0,match(donGeno[[na+1]],donGeno[[na]],nomatch=0)) > + for(k in 2:length(C)){ > + if(pos==1) {donGeno[[k]] <- donGeno[[k]][2:C[k]]} > + if(pos==C[k]){donGeno[[k]] <- donGeno[[k]][1:(C[k]-1)]} > + else{donGeno[[k]] <- c(donGeno[[k]][1:(pos-1)],donGeno[[k]][(pos+1):C(k)])} > + } > + } >> else{for(k in 1:(na-1)){ > Erreur : erreur de syntaxe dans "else"
R will parse a complete statement if you enter one. Your if() was complete before the else was entered, so the else got orphaned. The usual convention to avoid this is to put the else on the same line as the brace that closes the if, e.g. if(na==1){ ... } else { ... } Duncan Murdoch >> if(pos==1) {donGeno[[k]] <- donGeno[[k]][2:C[k]]} >> if(pos==C[k]){donGeno[[k]] <- donGeno[[k]][1:(C[k]-1)]} >> else{donGeno[[k]] <- c(donGeno[[k]][1:(pos-1)],donGeno[[k]][(pos+1):C(k)])} > Erreur : erreur de syntaxe dans " else" >> } > Erreur : erreur de syntaxe dans " }" >> for(k in 1:(na-1)){ > + if(pos==1) {donGeno[[k]] <- donGeno[[k]][2:C[k]]} > + if(pos==C[k]){donGeno[[k]] <- donGeno[[k]][1:(C[k]-1)]} > + else{donGeno[[k]] <- > c(donGeno[[k]][1:(pos-1)],donGeno[[k]][(pos+1):C(k)])} > + } > Erreur dans C(k) : objet non interprétable comme un facteur >> } > Erreur : erreur de syntaxe dans " }" > > > Have you got some ideas? > > > > ___________________________________________________________________________ > > > > > > [[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.