VOOZH about

URL: https://qiita.com/sk427/items/cff2bd883f3693f79cf6

⇱ Rで例外処理 #R - Qiita


👁 Image
8

Go to list of users who liked

11

Share on X(Twitter)

Share on Facebook

Add to Hatena Bookmark

More than 5 years have passed since last update.

Rで例外処理

8
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

Go to list of users who liked

11
0

Go to list of comments

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

Go to list of users who liked

11