我是一个新的R用户,我正在编写一个函数,该函数将使用readline()提示用户输入数据。我希望稍后在函数中使用公式中的答案。
我收到错误,“w / m错误:二元运算符的非数字参数”
我发现用户的输入是字符类,我想将其转换为数字,以便我可以通过(wh)公式运行它。
我的代码看起来像这样......
lands<-function(w, g, r, b, u, l, au, mc, uw, gw, wr, bw, gr, gb, ug, rb, ur, ub){
l<-readline("How many lands are you playing?")
au<-readline("How many of these lands can be tapped for more than or less than 2 colors of mana? note: omit fetch lands that get two different types of land, but include fetch lands that can get any basic.")
mc<-readline("Count the number of mana symbols on your cards an input the number. Be sure to include flash back costs that differ from regular mana costs, hybrid mana should be split (add 1 for odd numbers).")
w<-readline("How many mana symbols are white?")
wh<-(((w/mc)*(l-au))) ##-((uw+gw+wr+bw)/2))
}
答案 0 :(得分:3)
您需要通过as.numeric
foo <- as.numeric(readline("Question text? "))