[R] list(0) to integer

Romain François francoisromain at free.fr
Thu Dec 30 19:30:11 CET 2004


Re-Hello frederic,

Don't worry, i have the same english speaking problem, here is what i 
suggest :

n <- natScan()

natScan <- function(){
  cat("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n")
  cat("Give me a natural (everything after the '.' will be ignored)\n")
  n <- scan("", character(), 1,quiet=T)
  n  <- as.integer(n)
  if(length(n)==0||is.na(n)){
     cat("!! that's not what i want !!\n")
     return(natScan())
  }
  return(n)
}

Hope this helps


Frederic renaud a écrit :

>Because if the user write something else (a real or a
>character), the program stop. I want in this case (if
>the user don't write a natural) that the program write
>again :" A natural, please!"
>I've some difficult to speak english! Do you
>understand?
>Thanks
>Fred
>
>
>--- Romain François <francoisromain at free.fr> wrote:
>
>  
>
>>Hello frederic,
>>
>>why don't you just try something like :
>>
>>n <- scan("", integer(), 1)
>>
>>
>>You may also need to take a look there : 
>>http://zoonek2.free.fr/UNIX/48_R/all.html
>>and maybe there http://addictedtor.free.fr (for the
>>moment there is 
>>noting usefull there but soon ....)
>>
>>
>>Frederic renaud a écrit :
>>
>>    
>>
>>>Hello
>>>I've another question :-)
>>>I would like to transform a list to a integer.
>>>I must be sure that the number entered by the user
>>>      
>>>
>>is
>>    
>>
>>>an integer! Thus, I've made :
>>>
>>>
>>>repeat{
>>> cat("Effectif des populations (integer):")
>>> n<-scan("",n=1,what=list(0),quiet=TRUE)
>>>
>>> if (is.integer(n[[1]])==TRUE) break
>>> print("L'effectif des population doit etre un
>>>entier")
>>> }
>>>
>>>That doesn't work of course but I've no idea to do
>>>this. How verify that n[[1]] is an integer an
>>>transform them as an integer (as.integer(n) doesn't
>>>work!) Someone can help me? Thanks!
>>>Fred
>>>
>>>_
>>>      
>>>
-- 
Romain FRANCOIS : francoisromain at free.fr
page web : http://addictedtor.free.fr/  (en construction)
06 18 39 14 69 / 01 46 80 65 60
_______________________________________________________
Etudiant en 3eme année
Institut de Statistique de l'Université de Paris (ISUP)
Filière Industrie et Services
http://www.isup.cicrp.jussieu.fr/




More information about the R-help mailing list