简体   繁体   English

嗨,我是一个新的 R 学习者。在编辑器上写了下面两个相同的代码,第二个运行正常,而第一个有错误..第一个有什么问题

[英]Hi am a new R learner.. wrote below two identical code on editior, 2nd one runs fine, while first one has error.. what is wrong with 1st one

1st One第一个

Not run there is an error没有运行有错误

repeat{
sc=scan(nmax=1)
if (sc>9) {break} else{
b=switch(sc,"ONE","TWO","THREE","FOUR","FIVE","SIX","SEVEN","EIGHT","NINE")
cat(“\n The Number Entered is “, sc ,” In Alpha it is  “, b,”\n”) } }

the Error is Error: unexpected input in: "b=switch(sc,"ONE","TWO","THREE","FOUR","FIVE","SIX","SEVEN","EIGHT","NINE") cat(“"错误是错误:意外输入:“b=switch(sc,”ONE”,”TWO”,”THREE”,”FOUR”,”FIVE”,”SIX”,”SEVEN”,”EIGHT”,”NINE “) 猫(””

2nd One This one runs ok第二个这个运行正常

repeat{
sc=scan(nmax=1)
if (sc>9) {break} else{
b=switch(sc,"ONE","TWO","THREE","FOUR","FIVE","SIX","SEVEN","EIGHT","NINE")
cat("\n The Entered Number is ", sc ," In Alpha it is ", b,"\n") } }

1: 4 Read 1 item The Entered Number is 4 In Alpha it is FOUR 1:4 阅读 1 项 输入的数字是 4 在 Alpha 中是 4

“ is not allowed in R as a parentheses. " 不允许在 R 中作为括号。

In the first piece of code you are using “ instead of ".在第一段代码中,您使用“而不是”。

“ may appear if you copy your code into MS Word first and then into.R file.如果先将代码复制到 MS Word 中,然后再复制到 .R 文件中,可能会出现“。 To securely copy the code pls use Notepad (Notepad++ or IDE) so it preserves " symbol as is and does not transform it into “.要安全地复制代码,请使用记事本(Notepad++ 或 IDE),这样它会按原样保留“符号,不会将其转换为”。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 更改 R 中的二维数组。第一维是行号,第二维是一维像素 - Changing 2D Array in R. 1st Dimension is a Row Number, and 2nd Dimension is a Pixel with one dimension 如何找到第一四分位数、中位数和第二四分位数的索引号? - How do one find the index number of 1st quartile, median and 2nd quartile? 你好。 我在执行下面的 r 代码以用另一个替换一个列值时卡住了 - Hi. I got stuck in while executing the below r code to replace one column value with another 在 R 中嵌套 for 循环使得第二个索引 = 第一个索引 + 1 - Nested for loops in R such that index of the 2nd = index of the 1st + 1 r:2个子功能,第2个有效,但第一个不起作用 - r: 2 subset function, 2nd works but 1st don't 创建一个新的数据框,该数据框仅具有原始数据框的第1 8列 - Create a data frame new that only has the 1st 8 columns of ​the original one R:确定两个不同数据帧的两个文本字符串之间的第一,第二,第三,第四匹配 - R: Identify 1st, 2nd, 3rd, 4th match between two text strings of two different dataframes 根据 R 中 dataframe 的另一列的相等值,在新列(在第一个数据帧中)中添加值(来自第二个数据帧) - Add value (from 2nd dataframe) in new column (in 1st dataframe) based on equality value of another column from both dataframe in R R,创建由第一列组成的新列,或者如果满足条件,则创建第二列/第三列的值 - R, create new column that consists of 1st column or if condition is met, a value from the 2nd/3rd column 第1组的唯一值,然后是第1组和第2组,依此类推 - Unique values for the 1st group then the 1st and 2nd and so on
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM