R在循环中创建变量时显示错误消息 [英] R showed an error message when create a variable in a loop

查看:71
本文介绍了R在循环中创建变量时显示错误消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用Tinn-R编写了程序.当我通过使用source()在R中运行它时,显示了一条错误消息.以下示例仅包含部分循环.

I wrote my program in Tinn-R. When I ran it in R by using source(), an error message showed. The following example only includes partial loop.

          for (nn in 1:length(nSim))  ##whether the right loop???
              {
              r.all <- c()
              p.final <- array(0, c(15,5))  #1-5 a, b1, b2, b3, b4; 6 group id
              r.reference <- cbind(GRM_sim(t(p.sample[,1]), t(p.sample[,2:5]),sample.all[iS],0,rep(1,sample.all[iS]))

            DIF_ID <-c()
            DIF_index <- rep(0,15)
            for (iC in 1:length(CDIF))
            {
              if (CDIF[iC]==1)
              {
                DIF_ID <- sample(1:15,DIF.all[iDIF.all])   ##consistent DIF 
              }
               for (id in 1:length(DIF_ID))
               {
                  DIF_index[DIF_ID[id]] <-1
               }
              ...

来源错误("120413consistentMH.R"): 120413consistentMH.R:107:17:意外的符号 106:
107:DIF_ID

Error in source("120413consistentMH.R") : 120413consistentMH.R:107:17: unexpected symbol 106:
107: DIF_ID

感谢您的宝贵时间.

推荐答案

该错误是缺少括号的典型错误.让自己的编辑器与parens匹配,或者学会更自由地使用空格和回车符.滚动到该页面末尾的第五行缺少结束括号:

The error is typical for a missing paren. Get yourself an editor that matches parens or learn to make more liberal use of spaces and carriage returns. The fifth line that scrolls off the end of this webpage is missing a closing paren:

r.reference <- cbind(GRM_sim( t( p.sample[,1]  ), 
                              t( p.sample[,2:5]), 
                               sample.all[iS],0, 
                              rep(1, sample.all[iS])
                               )
                      ^
            missing paren here

这篇关于R在循环中创建变量时显示错误消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆