从R中的键盘读取输入

标签 r

我知道这是一个非常基本的问题,因为我是 R 的新手,我有这个问题。

如何允许用户从键盘输入数字。 为用户提供他们想要从键盘输入多少个数字,并根据该提供便利来输入数字。

例如:

How many numbers you want to enter?  
> 10  
Enter numbers:  
> 5 10 15 20 25 30 35 40 45 50

最佳答案

   while(T) {
    num <- readline("How many number do you want to enter? > ")
    num <- as.numeric(num)
    if (!is.na(num)) {
      num2 <- readline(paste0("Enter ",num, " numbers > "))
      print(num2)
      break
    }
  }

关于从R中的键盘读取输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42559094/

相关文章:

r - 如何仅将函数应用于 dplyr 中组的第一行?

regex - R 正则表达式 : extracting speaker in a script

R. 为什么我的函数忽略 1(并正确处理任何数字)?

r - 在 R 中将二进制字符串转换为文本(Salesforce ID 转换 15 到 18)

r - R中多行取一列的最大值

r - 如何知道应用程序是在本地还是在服务器上运行? (R Shiny )

R Shiny : Strange behavior of the brush functionality with ggplot2

在变量幂集中运行线性模型

r - 切换R中矩阵的列顺序

r - 包 igraph0 已弃用,因此无法访问 gspan 包