Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
34 の変数と約 25,000 の観測値を持つデータセットがあります。各観測は、特定のインシデントを指します。次のようにフォーマットされています。
no id date .... 1 363 006 2005-11-05 2 939 012 2007-01-23 3 541 090 2009-06-14
このデータセットに含まれる 5 年間の各月のインシデントの総数を取得する方法を教えてもらえないだろうか。
tapply( dfrm$no, sub(".+-(.+)-.+", "\\1", dfrm$date), sum, na.rm=TRUE)
MM-YYYY 形式の月と年には、これをカテゴリ コードとして使用します。
.... , sub("(.+)-(.+)-.+", "\\2-\\1", data$date) , ....