在R中指定任何数字

时间:2014-08-07 15:51:39

标签: r numbers

这可能很简单,但无法在任何地方找到。

w <- function(finaltable) {
  if (tail(names(finaltable),1) == c("carried##")) {
    (ncol(finaltable)-2)
  } else {
    (ncol(finaltable)-1)
  }
}

如果有两个##符号,我想指定任何数字组合。

1 个答案:

答案 0 :(得分:1)

我认为您可以使用seq创建一个数字序列,然后在for循环中连接所有数字

seq <- seq(1,100)

for(element in seq):
{
  w <- function(finaltable) {
    if (tail(names(finaltable),1) == c("carried", as.character(element))) {
      (ncol(finaltable)-2)
    } else {
      (ncol(finaltable)-1)
    }
  }
}

如果你想要一个特定的序列,你可以使用seq的参数

Arguments

... 
arguments passed to or from methods.

from, to    
the starting and (maximal) end values of the sequence. Of length 1 unless just from is supplied as an unnamed argument.

by  
number: increment of the sequence.

length.out  
desired length of the sequence. A non-negative number, which for seq and seq.int will be rounded up if fractional.

along.with  
take the length from the length of this argument.