Dear all,

 
I wrote a function :

idrecfun <- function(x)
  {
  
  idi <- 1
  esn <- x[order(x)]
  if !(all(esn==x)) stop("x not ordered")
  esn <- as.character(esn)
  for (i in 2:length(esn)) if(esn[i]==esn[i-1]) 
  idi[i] <- idi[i-1] else idi[i] <- idi[i-1] + 1
  idi
 }


for whichever I send the code R give to me this error:
> idrecfun <- function(x)
+   {
+   
+   idi <- 1
+   esn <- x[order(x)]
+   if !(all(esn==x)) stop("x not ordered")
Error: unexpected '!' in:
"  esn <- x[order(x)]
  if !"
>   esn <- as.character(esn)
Error: object 'esn' not found
>   for (i in 2:length(esn)) if(esn[i]==esn[i-1]) 
+   idi[i] <- idi[i-1] else idi[i] <- idi[i-1] + 1
Error: object 'esn' not found
>   idi
Error: object 'idi' not found
>  }
Error: unexpected '}' in " }"
> 

What's wrong with my code? Anyone may help me, please?

Massimiliano
 This is the output of sessionInfo():

R version 3.0.3 (2014-03-06)
Platform: x86_64-w64-mingw32/x64 (64-bit)

locale:
[1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252  
 
[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C                         
 
[5] LC_TIME=English_United States.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

loaded via a namespace (and not attached):
[1] tools_3.0.3


-- 
Massimiliano Tripoli 
Collaboratore T.E.R. scado il 31/12/2014 
ISTAT - DCCN - Direzione Centrale della Contabilità Nazionale 
U.O. Contabilità dei flussi di materia del sistema economico - CSA/C 
Via Depretis, 74/B 00184 Roma 
Tel. 06.4673.3132 
E-mail: mtrip...@istat.it 

Precedentemente:

Collaboratore T.E.R. scado il 31/12/2014 
Dipartimento    DICS Dipartimento per i conti nazionali e le statistiche 
economiche
Direzione       DCCN Direzione Centrale della contabilità nazionale
Servizio        FIP Servizio Statistiche della Finanza Pubblica
Ufficio         FIP/E U.O. Conti trimestrali delle amministrazioni pubbliche e 
conti della sanità
Via Depretis, 74/B 00184 Roma 
Tel. 06.4673.3132 
E-mail: mtrip...@istat.it 

______________________________________________
R-help@r-project.org 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.

Reply via email to