tryCatch does not seem to return my variable

后端 未结 1 811
春和景丽
春和景丽 2021-01-15 04:35

I\'m trying to use tryCatch to generate a list of p-values there are several rows in the matrix that don\'t have enough observations for a t test. Here is the code I generat

1条回答
  •  不思量自难忘°
    2021-01-15 04:56

    The pvalues in your function is a local variable. You might be able to fix this with <<-, but it would be preferred to have the function just return the one desired value and collect them outside the function with sapply. Perhaps something like (untested):

    pValues <- sapply(rownames(collapsed.gs.raw), function(i) {
      tryCatch({
        t.test(as.numeric(collapsed.gs.raw[i,]) ~ group)$p.value
      },
      error = function(err) {
        message("Error")
        return(NA)
      })
    })
    

    0 讨论(0)
提交回复
热议问题