0

运行时我收到一条错误消息,有什么对任何人来说都是显而易见的吗?

 yo <-  function(x) {

      filt <- ddply(x, .(primer,day), summarise, count=sum(timepoints==0)) # this will tell you all primers that have a 0 hr time point by giveing a 1 in the count column



 if (any(filt$count) == 0)     { # this was the case once so I implemented this if else part

      filt <- filt[filt$count == 0,]
      include <-!(x$primer%in%filt$primer)&(x$day%in%filt$day) # all primers that have 0 hrs
      x <- x[include,] 
     ### for any given replicate, divide each timepoint by its zero hour 
     x <- ddply(x, .(primer),transform, foldInduction=realConc/realConc[timepoints==0])

}


  else {
x <- ddply(x, .(primer), transform, foldInduction=realConc/realConc[timepoints==0])
   }
  x[,-9]

  } 
4

2 回答 2

3

是的,花括号的位置。

鼓励你写

 if (cond) {
     code
 } else {
     more_code
 }

随着解析器逐行进行 - 除非您使用类似的东西source(),或者像在构建包并且文件被“整体”而不是逐行使用时那样进行解析。

但作为一般规则:不要使用原始问题显示的样式。

于 2012-10-13T03:44:11.863 回答
1

好的,将我的评论推广到答案。

any(filt$count) == 0没有什么意义。为什么?像 R 中的所有逻辑强制一样,any将采用filt$count表示的数字,如果为零则返回 true,如果非零则返回 1。

> any(5)
[1] TRUE
Warning message:
In any(5) : coercing argument of type 'double' to logical

但是,一旦它是合乎逻辑的,您就可以通过将其与数字进行比较来将其强制回数字。所以你的语句真正做的是看看是否有任何一个filt$count为零(在这种情况下它返回TRUE),然后否定它。

> any( c(5,6,7) )==0
[1] FALSE
Warning message:
In any(c(5, 6, 7)) : coercing argument of type 'double' to logical
> any( c(5,6,0) )==0
[1] FALSE
Warning message:
In any(c(5, 6, 0)) : coercing argument of type 'double' to logical
> any( c(0) )==0
[1] TRUE
Warning message:
In any(c(0)) : coercing argument of type 'double' to logical

解决方案:不要那样做。

于 2012-10-13T12:04:24.370 回答