Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在R中获取多个用户输入_R - Fatal编程技术网

在R中获取多个用户输入

在R中获取多个用户输入,r,R,我正在创建一个程序,跟踪R中仓库周围的工具。以下是我目前掌握的信息: tool <- readline(prompt='Enter a Barcode: ') if (! tool %in% df$Barcode.Number) { message("Barcodes not found.") } else { initials <- readline(prompt='Enter your Initials: ') job <- readline(prompt='Enter j

我正在创建一个程序,跟踪R中仓库周围的工具。以下是我目前掌握的信息:

tool <- readline(prompt='Enter a Barcode: ')
if (! tool %in% df$Barcode.Number) {
message("Barcodes not found.")
} else {
initials <- readline(prompt='Enter your Initials: ')
job <- readline(prompt='Enter job number: ')
suppressMessages(library(dplyr))
message("Good to Go!")
df[df$Barcode.Number == tool, "DATE"]  = as.character(Sys.Date())
df[df$Barcode.Number == tool, 'Initial'] = initials
df[df$Barcode.Number == tool, 'Job.Number'] = job
df1 <- df %>% filter(df$Barcode.Number == tool) %>% 
select(Type.Equipment, Location)
print(df1)
df[df$Barcode.Number == tool, "Usage"] = df[df$Barcode.Number == 
tool, "Usage"] + 0.5
df$Status <- ifelse((df$Usage %% 1) , 'Out', 'In')
}
如您所见,它接受一个工具参数,以及一个初始和工作编号输入,并根据用户的输入更新列Date、Job number、Times.Used和initial。我在为变量工具输入多个值时遇到问题。目前,一次只能取一个数字,而对于那些希望在同一首字母和工作下签出多个不同项目的人来说,这并不一定实用。这个问题可能很简单,但我如何接受工具的多个不同输入编号,并使它仍然能够同时更新两个工具的数据帧。我尝试了以下方法:

tool <- readline(prompt='Enter the Barcodes: ')
tools <-scan(text=tool,quiet=TRUE,sep=",")

tool首先使用:
您可以使用
scan
获取所需的值。然后
cat
将它们打印出来

number <- readline(prompt='Enter a Number: ')
cat("Your Numbers are:",scan(text=number,quiet=TRUE,sep=","))

感谢您的回复,从这里开始,作为一个用户,如何将多个语句输入到一行代码中?如果我的输入是“输入一个数字”,而我输入了45、65、72,它会接受该数字为“45、65、72”,而不是“45”、“65”和“72”。你建议我怎么解决这个问题?再次感谢。我的最后两行回答和你的意思完全一样@GregPedersenThanks的回应!我想我的问题更符合,作为一个用户,如何在一个输入语句中输入多个值。例如,如果我在上面的输入输出值中输入“64,53,72”,它将接受“64,53,72”,而不是“64”,“53”和“72”,我如何解决这个问题?用户是否有其他输入方式,或者我是否需要更改input语句以允许这样做?再次感谢。
number <- readline(prompt='Enter a Number: ')
values = read.table(text = number,sep=",")
number <- readline(prompt='Enter a Number: ')
print(paste("Your numbers are",number), quote=FALSE)
number <- readline(prompt='Enter a Number: ')
cat("Your Numbers are:",scan(text=number,quiet=TRUE,sep=","))
getnumbers = function(){
  number <- readline(prompt='Enter the Numbers: ')
  numbers <-scan(text=number,quiet=TRUE,sep=",")
  cat("Your Numbers are:",numbers)
  invisible(numbers)
 }
getnumbers()
Enter the Numbers: 1,2,3,4,5,6,7,13,43
Your Numbers are: 1 2 3 4 5 6 7 13 43
saved =getnumbers()
Enter the Numbers: 1,2,3,4
Your Numbers are: 1 2 3 4
saved
[1] 1 2 3 4