如何在R中读取作为输入用户的向量

如何在R中读取作为输入用户的向量,r,vector,input,readline,R,Vector,Input,Readline,我是一个新的使用R的人,在我工作的时候,我有一个问题我自己还没能解决。我想在控制台中创建一个脚本或序列,让用户引入一个向量作为输入,而不是任何向量,特别是,我需要引入向量:j您可以使用(in)著名的eval(parse(text=…)构造: limStr <- readline("Enter the vector you want:"); Enter the vector you want: c(1:20, 4, 30:35); lim <- eval(parse(text

我是一个新的使用R的人,在我工作的时候,我有一个问题我自己还没能解决。我想在控制台中创建一个脚本或序列,让用户引入一个向量作为输入,而不是任何向量,特别是,我需要引入向量:
j您可以使用(in)著名的
eval(parse(text=…)
构造:

limStr <- readline("Enter the vector you want:");
Enter the vector you want: c(1:20, 4, 30:35);    
lim <- eval(parse(text = limStr));
lim;
# [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20  4 30 31 32 33
#[26] 34 35 

这正是我所需要的!谢谢你的帮助。太好了,很高兴能帮助@Víctor
limStr <- readline("Enter the vector you want:");
Enter the vector you want: c(1:20, 4, 30:35);    
lim <- eval(parse(text = limStr));
lim;
# [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20  4 30 31 32 33
#[26] 34 35 
unlist(strsplit(gsub("(c\\(|\\))", "", limStr), ", "));
#[1] "1:20"  "4"     "30:35"