8
11

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Rで例外処理

Last updated at Posted at 2017-07-24
tryCatch(
  { エラーを出すかもしれない処理 }
  , error = function(e) { エラーに対して行う処理 }
)

と書く。遺伝子発現行列geneに対して網羅的にt検定をしてp値を得たい場合。Rのt検定の関数は一群すべてNAだった場合などにはエラーとなってしまう。このような項目にはとりあえず1を入れて処理したい場合。

ps = c()
for(i in 1:nrow(genes)){
  tryCatch(
    {ps[i] = t.test(genes[i,case], genes[i,cont])$p.value}
    , error = function(e){ps[i] = 1}
  ) 
}
8
11
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
11

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?