トップ 履歴 一覧 Farm ソース 検索 ヘルプ PDF RSS ログイン

ifelse

*disclaimer
633255

R

ifelse

ifelse(条件, 合っている場合, 合ってない場合)
gakunen2$case <- ifelse(gakunen2$Topic == "WFM", -1, ifelse(gakunen2$Topic == "WIM", -0.5, ifelse(gakunen2$Topic == "WMG", 0.5, 1)))

str(gakunen2)

xtabs(~ case + Topic, gakunen2)

      Topic
case   WFM WIM WMG WPL
  -1   149   0   0   0
  -0.5   0 150   0   0
  0.5    0   0 150   0
  1      0   0   0 149



ipsynW.score.nona.gakunen2$FM <- ifelse(ipsynW.score.nona.gakunen2$Topic == "WFM", 1,0)
ipsynW.score.nona.gakunen2$IM <- ifelse(ipsynW.score.nona.gakunen2$Topic == "WIM", 1,0)
ipsynW.score.nona.gakunen2$MG <- ifelse(ipsynW.score.nona.gakunen2$Topic == "WMG", 1,0)
ipsynW.score.nona.gakunen2$PL <- ifelse(ipsynW.score.nona.gakunen2$Topic == "WPL", 1,0)