2016-04-09 17 views
0

ユーザプロンプトから整数を読み込もうとしています。しかし、それは文字として読んでいる。どのように整数として読む?この機能を実行するRでは、ユーザープロンプトから整数を読み取る方法は?

myfunt <- function(){ 
cat("Enter an integer or whole number : \n") 
enter <- readline(prompt = "") 
cat("You sumitted : \n"); str(enter) 
} 

は生成します myfunt()

Enter an integer or whole number: 
17 
You sumitted : 
chr "17" 

任意のソリューションを?

+1

()

myfunt <- function(){ cat("Enter an integer or whole number : \n") enter <- as.integer(readline(prompt = "")) cat("You sumitted : \n"); str(enter) } 

とあなたの関数を実行している... myfunt()as.integerを使用しています。私は... as.integer()と問題が解決したと思います。ありがとう。 –

+0

私はちょうどそれを考えなかった。しかし、確かに、次回は自分で試してみます。 –

答えて

1

Ahh!シンプルな...ちょうどあなたがそれを考えている必要があり

Enter an integer or whole number: 
17 
You sumitted : 
int 17 
関連する問題