「データセットについてのメモ」の中で,table 関数を使うたびに分析で使う変数と ケースの subset を作っている。
少なくとも,変数の subset を毎回作る必要はない。
また,3次元以上の集計表を第3次元ごとに繰り返している。
で、35歳で層別化して出産回数と人工流産回数を見たい場合は、こんな感じでしょうか?
> table(subset(x,subset=age=="<35",select=c(parity, induced)))
induced
parity 0 1 more
1 52 17 0
>1 40 33 26
> table(subset(x,subset=age!="<35",select=c(parity, induced)))
induced
parity 0 1 more
1 24 6 0
>1 27 12 11
これは,xtabs 関数を使うと,何の苦もなく一発で結果が出る。x は既に作成されているデータフレーム。
> xtabs(~parity+induced+age, x)
, , age = <35
induced
parity 0 1 more
1 52 17 0
>1 40 33 26
, , age = >=35
induced
parity 0 1 more
1 24 6 0
>1 27 12 11
最新の画像[もっと見る]
-
算額(その1147) 1時間前
-
算額(その1146) 10時間前
-
算額(その1144) 14時間前
-
算額(その1143) 2日前
-
算額(その1142) 2日前
-
算額(その1141) 2日前
-
算額(その1140) 2日前
-
算額(その1139) 3日前
-
算額(その1138) 4日前
-
算額(その1137) 4日前
※コメント投稿者のブログIDはブログ作成者のみに通知されます