LoginSignup
5
6

More than 5 years have passed since last update.

R言語でキーボード入力に応じて行う処理を選択するサンプルプログラム

Posted at

R言語でキーボード入力に応じて行う処理を選択するサンプルプログラムを書いたので投稿します。

02_Input_and_Output.R
data <- NULL

while(TRUE){ 
  #menuでキーボード入力待ちになる
  input <- menu(c("OK", "NG","EXIT"))

  #inputに応じて処理を分ける
 if(input==1){
    s<-sprintf("Input is %d: %s",input,"OK")
    data <- c(data,input)
    print(s)
  }else if(input==2){
    s<-sprintf("Input is %d: %s",input,"NG")
    data <- c(data,input)
    print(s)
  }else{
    s<-sprintf("Input is %d: %s",input,"EXIT")
    print(s)
    break #whileループを抜ける
  }
  #dataをプロットする
  plot(data)
}

#InputしたデータをCSVファイルへ出力する。
save_data = data.frame(data)
names(save_data) <- c("Input")
write.csv(save_data, "02_Output.csv", quote=FALSE, row.names=FALSE)
5
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
6