Re: [R] I need help

From: Duncan Murdoch <murdoch_at_stats.uwo.ca>
Date: Wed, 02 May 2007 08:29:14 -0400

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_at_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_at_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. Received on Wed 02 May 2007 - 12:37:39 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 02 May 2007 - 13:31:53 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.