R Cat功能/输入

时间:2018-04-05 03:57:51

标签: r

我正在努力提出一个问题&答案格式,答案成为每个变量的输入。即,sexinterest rate此处。

cat("Select Sex", ":M = Male, F = Female", "\n", sep=" ")
Sex <- readline("Sex = ")

cat("Input interest rate in  annual compounding basis", "\n", sep=" ")
interest.rate <- as.numeric(readline("Interest rate = "))

我需要在每个下面添加什么才能将每个答案作为输入?

我真的很感激!

1 个答案:

答案 0 :(得分:0)

我不确定我是否理解这个问题,但如果我做得好,你会希望将来自read.line的输入重新用作其他地方的输入吗?

那样的东西?

cat("Select Sex", ":M = Male, F = Female", "\n", sep=" ")
Sex <- readline("Sex = ")

cat("Input interest rate in  annual compounding basis", "\n", sep=" ")
interest.rate <- as.numeric(readline("Interest rate = "))

cat(paste0("Input values where ", Sex, " (Sex) and ", interest.rate, " (interest rate)."))