在R函数中实现TRUE / FALSE标志

时间:2014-01-28 20:09:35

标签: r function

我有一个R函数:

subsequences <- function(data){
  sequences.sts <- seqdef(data, left = "DEL", gaps = "DEL", right = "DEL")
  sub.sequences <- seqsubsn(sequences.sts, DSS = FALSE)
  (sub.sequences)
}

现在我想实现一个TRUE/FALSE标志来运行一些额外的规范化代码,如下所示:

subsequences <- function(data, normalization = TRUE/FALSE){
   sequences.sts <- seqdef(data, left = "DEL", gaps = "DEL", right = "DEL")
   sub.sequences <- seqsubsn(sequences.sts, DSS = FALSE)
   (sub.sequences)  

      IF normalization=TRUE, RUN CODE BELOW, IF FALSE -> END
         sequences.length <- seqlength(sequences.sts)
         order_normalized <- sub.sequences/(2^(max(sequences.length)))

   (order_normalized*1000000)
}

我该如何实现?

1 个答案:

答案 0 :(得分:1)

library(TraMineR)

subsequences <- function(data, normalization){
  sequences.sts <- seqdef(data, left = "DEL", gaps = "DEL", right = "DEL")
  sub.sequences <- seqsubsn(sequences.sts, DSS = FALSE) 

  if(normalization){
  sequences.length <- seqlength(sequences.sts)
  order_normalized <- sub.sequences/(2^(max(sequences.length)))
  (order_normalized*1000000)}

  else {return(sub.sequences)}
}