Suche senden
Hochladen
Tokyor39 yokkuns
•
12 gefällt mir
•
3,310 views
Yohei Sato
Folgen
Melden
Teilen
Melden
Teilen
1 von 48
Jetzt herunterladen
Downloaden Sie, um offline zu lesen
Empfohlen
LibreOffice 4 under NetBSD with pkgsrc
LibreOffice 4 under NetBSD with pkgsrc
Ryo ONODERA
Parquetはカラムナなのか?
Parquetはカラムナなのか?
Yohei Azekatsu
mlr-grep - レコード指向grep
mlr-grep - レコード指向grep
Ryoichi KATO
Tokyor60 r data_science_part1
Tokyor60 r data_science_part1
Yohei Sato
20131206 japan r
20131206 japan r
Yohei Sato
Rでレポートメール
Rでレポートメール
Yohei Sato
Rで階層ベイズモデル
Rで階層ベイズモデル
Yohei Sato
EasyHtmlReportの紹介
EasyHtmlReportの紹介
Yohei Sato
Empfohlen
LibreOffice 4 under NetBSD with pkgsrc
LibreOffice 4 under NetBSD with pkgsrc
Ryo ONODERA
Parquetはカラムナなのか?
Parquetはカラムナなのか?
Yohei Azekatsu
mlr-grep - レコード指向grep
mlr-grep - レコード指向grep
Ryoichi KATO
Tokyor60 r data_science_part1
Tokyor60 r data_science_part1
Yohei Sato
20131206 japan r
20131206 japan r
Yohei Sato
Rでレポートメール
Rでレポートメール
Yohei Sato
Rで階層ベイズモデル
Rで階層ベイズモデル
Yohei Sato
EasyHtmlReportの紹介
EasyHtmlReportの紹介
Yohei Sato
巨大な表を高速に扱うData.table について
巨大な表を高速に扱うData.table について
Haruka Ozaki
Kubernetes + containerd で cgroup v2 に移行したら "failed to create fsnotify watcher...
Kubernetes + containerd で cgroup v2 に移行したら "failed to create fsnotify watcher...
Preferred Networks
PythonでテキストをJSONにした話(PyCon mini sapporo 2015)
PythonでテキストをJSONにした話(PyCon mini sapporo 2015)
Satoshi Yamada
2010 in-depth-v11
2010 in-depth-v11
kmiyako
実用裏方 Perl 入門
実用裏方 Perl 入門
keroyonn
ElixirでIoT 第2回「環境センシングとデータ表示をサクっと?やってみた」
ElixirでIoT 第2回「環境センシングとデータ表示をサクっと?やってみた」
Hideki Takase
about dakota6.7 gui
about dakota6.7 gui
Etsuji Nomura
Tokyo r25 hiro_macchan
Tokyo r25 hiro_macchan
Hiroki Matsui
コンテナを止めるな! PacemakerによるコンテナHAクラスタリングとKubernetesとの違いとは
コンテナを止めるな! PacemakerによるコンテナHAクラスタリングとKubernetesとの違いとは
ksk_ha
Kustoの入門編.pdf
Kustoの入門編.pdf
TED
R言語勉強会#10.pdf
R言語勉強会#10.pdf
Takuya Kubo
bicep 0.5 pre
bicep 0.5 pre
Takekazu Omi
PostgreSQLのgitレポジトリから見える2022年の開発状況(第38回PostgreSQLアンカンファレンス@オンライン 発表資料)
PostgreSQLのgitレポジトリから見える2022年の開発状況(第38回PostgreSQLアンカンファレンス@オンライン 発表資料)
NTT DATA Technology & Innovation
研究生のためのC++ no.2
研究生のためのC++ no.2
Tomohiro Namba
Maatkit で MySQL チューニング
Maatkit で MySQL チューニング
Kensuke Nagae
Tokyor60 opening
Tokyor60 opening
Yohei Sato
Tokyor45 カーネル多変量解析第2章 カーネル多変量解析の仕組み
Tokyor45 カーネル多変量解析第2章 カーネル多変量解析の仕組み
Yohei Sato
Tokyor42_r_datamining_18
Tokyor42_r_datamining_18
Yohei Sato
Tokyor42 ggplot2
Tokyor42 ggplot2
Yohei Sato
Tokyor35 人工データの発生
Tokyor35 人工データの発生
Yohei Sato
ドリコムの分析環境とデータサイエンス活用事例
ドリコムの分析環境とデータサイエンス活用事例
Yohei Sato
R言語で学ぶマーケティング分析 競争ポジショニング戦略
R言語で学ぶマーケティング分析 競争ポジショニング戦略
Yohei Sato
Weitere ähnliche Inhalte
Ähnlich wie Tokyor39 yokkuns
巨大な表を高速に扱うData.table について
巨大な表を高速に扱うData.table について
Haruka Ozaki
Kubernetes + containerd で cgroup v2 に移行したら "failed to create fsnotify watcher...
Kubernetes + containerd で cgroup v2 に移行したら "failed to create fsnotify watcher...
Preferred Networks
PythonでテキストをJSONにした話(PyCon mini sapporo 2015)
PythonでテキストをJSONにした話(PyCon mini sapporo 2015)
Satoshi Yamada
2010 in-depth-v11
2010 in-depth-v11
kmiyako
実用裏方 Perl 入門
実用裏方 Perl 入門
keroyonn
ElixirでIoT 第2回「環境センシングとデータ表示をサクっと?やってみた」
ElixirでIoT 第2回「環境センシングとデータ表示をサクっと?やってみた」
Hideki Takase
about dakota6.7 gui
about dakota6.7 gui
Etsuji Nomura
Tokyo r25 hiro_macchan
Tokyo r25 hiro_macchan
Hiroki Matsui
コンテナを止めるな! PacemakerによるコンテナHAクラスタリングとKubernetesとの違いとは
コンテナを止めるな! PacemakerによるコンテナHAクラスタリングとKubernetesとの違いとは
ksk_ha
Kustoの入門編.pdf
Kustoの入門編.pdf
TED
R言語勉強会#10.pdf
R言語勉強会#10.pdf
Takuya Kubo
bicep 0.5 pre
bicep 0.5 pre
Takekazu Omi
PostgreSQLのgitレポジトリから見える2022年の開発状況(第38回PostgreSQLアンカンファレンス@オンライン 発表資料)
PostgreSQLのgitレポジトリから見える2022年の開発状況(第38回PostgreSQLアンカンファレンス@オンライン 発表資料)
NTT DATA Technology & Innovation
研究生のためのC++ no.2
研究生のためのC++ no.2
Tomohiro Namba
Maatkit で MySQL チューニング
Maatkit で MySQL チューニング
Kensuke Nagae
Ähnlich wie Tokyor39 yokkuns
(15)
巨大な表を高速に扱うData.table について
巨大な表を高速に扱うData.table について
Kubernetes + containerd で cgroup v2 に移行したら "failed to create fsnotify watcher...
Kubernetes + containerd で cgroup v2 に移行したら "failed to create fsnotify watcher...
PythonでテキストをJSONにした話(PyCon mini sapporo 2015)
PythonでテキストをJSONにした話(PyCon mini sapporo 2015)
2010 in-depth-v11
2010 in-depth-v11
実用裏方 Perl 入門
実用裏方 Perl 入門
ElixirでIoT 第2回「環境センシングとデータ表示をサクっと?やってみた」
ElixirでIoT 第2回「環境センシングとデータ表示をサクっと?やってみた」
about dakota6.7 gui
about dakota6.7 gui
Tokyo r25 hiro_macchan
Tokyo r25 hiro_macchan
コンテナを止めるな! PacemakerによるコンテナHAクラスタリングとKubernetesとの違いとは
コンテナを止めるな! PacemakerによるコンテナHAクラスタリングとKubernetesとの違いとは
Kustoの入門編.pdf
Kustoの入門編.pdf
R言語勉強会#10.pdf
R言語勉強会#10.pdf
bicep 0.5 pre
bicep 0.5 pre
PostgreSQLのgitレポジトリから見える2022年の開発状況(第38回PostgreSQLアンカンファレンス@オンライン 発表資料)
PostgreSQLのgitレポジトリから見える2022年の開発状況(第38回PostgreSQLアンカンファレンス@オンライン 発表資料)
研究生のためのC++ no.2
研究生のためのC++ no.2
Maatkit で MySQL チューニング
Maatkit で MySQL チューニング
Mehr von Yohei Sato
Tokyor60 opening
Tokyor60 opening
Yohei Sato
Tokyor45 カーネル多変量解析第2章 カーネル多変量解析の仕組み
Tokyor45 カーネル多変量解析第2章 カーネル多変量解析の仕組み
Yohei Sato
Tokyor42_r_datamining_18
Tokyor42_r_datamining_18
Yohei Sato
Tokyor42 ggplot2
Tokyor42 ggplot2
Yohei Sato
Tokyor35 人工データの発生
Tokyor35 人工データの発生
Yohei Sato
ドリコムの分析環境とデータサイエンス活用事例
ドリコムの分析環境とデータサイエンス活用事例
Yohei Sato
R言語で学ぶマーケティング分析 競争ポジショニング戦略
R言語で学ぶマーケティング分析 競争ポジショニング戦略
Yohei Sato
Rでピボットテーブル
Rでピボットテーブル
Yohei Sato
第3回Japan rパネルディスカッション
第3回Japan rパネルディスカッション
Yohei Sato
Tokyor26 data fusion
Tokyor26 data fusion
Yohei Sato
Tokyor24 yokkuns
Tokyor24 yokkuns
Yohei Sato
Tokyowebmining19 data fusion
Tokyowebmining19 data fusion
Yohei Sato
傾向スコア解析とUplift Modelling
傾向スコア解析とUplift Modelling
Yohei Sato
Complex network ws_percolation
Complex network ws_percolation
Yohei Sato
異常行動検出入門(改)
異常行動検出入門(改)
Yohei Sato
Tokyor22 selection bias
Tokyor22 selection bias
Yohei Sato
Uplift Modelling 入門(1)
Uplift Modelling 入門(1)
Yohei Sato
エンジニアサポート新年会2012 データマイニングcross 第1部
エンジニアサポート新年会2012 データマイニングcross 第1部
Yohei Sato
Japan r2 lt_yokkuns
Japan r2 lt_yokkuns
Yohei Sato
Japan r2 tokyor
Japan r2 tokyor
Yohei Sato
Mehr von Yohei Sato
(20)
Tokyor60 opening
Tokyor60 opening
Tokyor45 カーネル多変量解析第2章 カーネル多変量解析の仕組み
Tokyor45 カーネル多変量解析第2章 カーネル多変量解析の仕組み
Tokyor42_r_datamining_18
Tokyor42_r_datamining_18
Tokyor42 ggplot2
Tokyor42 ggplot2
Tokyor35 人工データの発生
Tokyor35 人工データの発生
ドリコムの分析環境とデータサイエンス活用事例
ドリコムの分析環境とデータサイエンス活用事例
R言語で学ぶマーケティング分析 競争ポジショニング戦略
R言語で学ぶマーケティング分析 競争ポジショニング戦略
Rでピボットテーブル
Rでピボットテーブル
第3回Japan rパネルディスカッション
第3回Japan rパネルディスカッション
Tokyor26 data fusion
Tokyor26 data fusion
Tokyor24 yokkuns
Tokyor24 yokkuns
Tokyowebmining19 data fusion
Tokyowebmining19 data fusion
傾向スコア解析とUplift Modelling
傾向スコア解析とUplift Modelling
Complex network ws_percolation
Complex network ws_percolation
異常行動検出入門(改)
異常行動検出入門(改)
Tokyor22 selection bias
Tokyor22 selection bias
Uplift Modelling 入門(1)
Uplift Modelling 入門(1)
エンジニアサポート新年会2012 データマイニングcross 第1部
エンジニアサポート新年会2012 データマイニングcross 第1部
Japan r2 lt_yokkuns
Japan r2 lt_yokkuns
Japan r2 tokyor
Japan r2 tokyor
Tokyor39 yokkuns
1.
2014/5/31 データ・ハンドリング file:///Users/yokkuns/github/TokyoR/TokyoR39/yokkuns/index.html#49 1/48 データ・ハンドリングRで学ぶデータマイニングⅠデータ解析[編]14~15章 里洋平(@yokkuns)
2.
2014/5/31 データ・ハンドリング file:///Users/yokkuns/github/TokyoR/TokyoR39/yokkuns/index.html#49 2/48 AGENDA 1.
自己紹介 2. データフレームの基本操作 3. フィルタリング 4. 並び替え 5. 列の追加 6. データフレームの結合 7. ピボットテーブル(reshape2) 8. 集約処理(dplyr) 2/49
3.
2014/5/31 データ・ハンドリング file:///Users/yokkuns/github/TokyoR/TokyoR39/yokkuns/index.html#49 3/48 自己紹介 3/49
4.
2014/5/31 データ・ハンドリング file:///Users/yokkuns/github/TokyoR/TokyoR39/yokkuns/index.html#49 4/48 4/49
5.
2014/5/31 データ・ハンドリング file:///Users/yokkuns/github/TokyoR/TokyoR39/yokkuns/index.html#49 5/48 5/49
6.
2014/5/31 データ・ハンドリング file:///Users/yokkuns/github/TokyoR/TokyoR39/yokkuns/index.html#49 6/48 データフレームの基本操作 6/49
7.
2014/5/31 データ・ハンドリング file:///Users/yokkuns/github/TokyoR/TokyoR39/yokkuns/index.html#49 7/48 データフレームとは Rでデータ分析するときに最も良く使うデータ構造 行列との違い· データフレームの各行・各列はラベル(名前)を持っており、ラベルを指定してデータを取り 出せる 行列はすべての要素が同じ型だがデータフレームはバラバラのデータ型を持てる - - 7/49
8.
2014/5/31 データ・ハンドリング file:///Users/yokkuns/github/TokyoR/TokyoR39/yokkuns/index.html#49 8/48 前からN行だけ見たい head関数 デフォルトは前から6行 head(airquality) ##
Ozone Solar.R Wind Temp Month Day ## 1 41 190 7.4 67 5 1 ## 2 36 118 8.0 72 5 2 ## 3 12 149 12.6 74 5 3 ## 4 18 313 11.5 62 5 4 ## 5 NA NA 14.3 56 5 5 ## 6 28 NA 14.9 66 5 6 8/49
9.
2014/5/31 データ・ハンドリング file:///Users/yokkuns/github/TokyoR/TokyoR39/yokkuns/index.html#49 9/48 前からN行だけ見たい head関数 第2引数を指定すると、前から指定した行までを取得出来る head(airquality,
3) ## Ozone Solar.R Wind Temp Month Day ## 1 41 190 7.4 67 5 1 ## 2 36 118 8.0 72 5 2 ## 3 12 149 12.6 74 5 3 9/49
10.
2014/5/31 データ・ハンドリング file:///Users/yokkuns/github/TokyoR/TokyoR39/yokkuns/index.html#49 10/48 後からN行だけ見たい tail関数 デフォルトは後から6行 tail(airquality) ##
Ozone Solar.R Wind Temp Month Day ## 148 14 20 16.6 63 9 25 ## 149 30 193 6.9 70 9 26 ## 150 NA 145 13.2 77 9 27 ## 151 14 191 14.3 75 9 28 ## 152 18 131 8.0 76 9 29 ## 153 20 223 11.5 68 9 30 10/49
11.
2014/5/31 データ・ハンドリング file:///Users/yokkuns/github/TokyoR/TokyoR39/yokkuns/index.html#49 11/48 後からN行だけ見たい tail関数 第2引数を指定すると、後から指定した行数を取得出来る tail(airquality,
3) ## Ozone Solar.R Wind Temp Month Day ## 151 14 191 14.3 75 9 28 ## 152 18 131 8.0 76 9 29 ## 153 20 223 11.5 68 9 30 11/49
12.
2014/5/31 データ・ハンドリング file:///Users/yokkuns/github/TokyoR/TokyoR39/yokkuns/index.html#49 12/48 特定の行だけ見たい 正整数の添字ベクトルで指定する airquality[c(1,
2, 5, 100, 120), ] ## Ozone Solar.R Wind Temp Month Day ## 1 41 190 7.4 67 5 1 ## 2 36 118 8.0 72 5 2 ## 5 NA NA 14.3 56 5 5 ## 100 89 229 10.3 90 8 8 ## 120 76 203 9.7 97 8 28 12/49
13.
2014/5/31 データ・ハンドリング file:///Users/yokkuns/github/TokyoR/TokyoR39/yokkuns/index.html#49 13/48 特定の列だけ見たい 正整数の添字ベクトルで指定する head(airquality[,
c(2, 4)]) ## Solar.R Temp ## 1 190 67 ## 2 118 72 ## 3 149 74 ## 4 313 62 ## 5 NA 56 ## 6 NA 66 13/49
14.
2014/5/31 データ・ハンドリング file:///Users/yokkuns/github/TokyoR/TokyoR39/yokkuns/index.html#49 14/48 特定の列以外を見たい 負整数の添字ベクトルで指定する head(airquality[,
-c(2, 4)]) ## Ozone Wind Month Day ## 1 41 7.4 5 1 ## 2 36 8.0 5 2 ## 3 12 12.6 5 3 ## 4 18 11.5 5 4 ## 5 NA 14.3 5 5 ## 6 28 14.9 5 6 14/49
15.
2014/5/31 データ・ハンドリング file:///Users/yokkuns/github/TokyoR/TokyoR39/yokkuns/index.html#49 15/48 特定の列だけ見たい 列名ベクトルで指定する head(airquality[,
c("Ozone", "Temp", "Day")]) ## Ozone Temp Day ## 1 41 67 1 ## 2 36 72 2 ## 3 12 74 3 ## 4 18 62 4 ## 5 NA 56 5 ## 6 28 66 6 15/49
16.
2014/5/31 データ・ハンドリング file:///Users/yokkuns/github/TokyoR/TokyoR39/yokkuns/index.html#49 16/48 フィルタリング 16/49
17.
2014/5/31 データ・ハンドリング file:///Users/yokkuns/github/TokyoR/TokyoR39/yokkuns/index.html#49 17/48 欠測値のない行が欲しい na.omit関数 #
NAが存在するデータ airquality[4:6, ] ## Ozone Solar.R Wind Temp Month Day ## 4 18 313 11.5 62 5 4 ## 5 NA NA 14.3 56 5 5 ## 6 28 NA 14.9 66 5 6 # NAを除外 na.omit(airquality[4:6, ]) ## Ozone Solar.R Wind Temp Month Day ## 4 18 313 11.5 62 5 4 17/49
18.
2014/5/31 データ・ハンドリング file:///Users/yokkuns/github/TokyoR/TokyoR39/yokkuns/index.html#49 18/48 条件にマッチした行が欲しい 論理型ベクトルで指定する #
条件の論理型ベクトルの作成 idx <- airquality$Month == 5 head(idx) ## [1] TRUE TRUE TRUE TRUE TRUE TRUE # 論理型ベクトルで指定 tail(airquality[idx, ], 3) ## Ozone Solar.R Wind Temp Month Day ## 29 45 252 14.9 81 5 29 ## 30 115 223 5.7 79 5 30 ## 31 37 279 7.4 76 5 31 18/49
19.
2014/5/31 データ・ハンドリング file:///Users/yokkuns/github/TokyoR/TokyoR39/yokkuns/index.html#49 19/48 並び替え 19/49
20.
2014/5/31 データ・ハンドリング file:///Users/yokkuns/github/TokyoR/TokyoR39/yokkuns/index.html#49 20/48 並び替えた時の値ベクトルが欲しい sort関数 #
昇順 head(sort(airquality$Ozone), 20) ## [1] 1 4 6 7 7 7 8 9 9 9 10 11 11 11 12 12 13 13 13 13 # 降順 head(sort(airquality$Ozone, decreasing = T), 20) ## [1] 168 135 122 118 115 110 108 97 97 96 91 89 85 85 84 82 80 ## [18] 79 78 78 20/49
21.
2014/5/31 データ・ハンドリング file:///Users/yokkuns/github/TokyoR/TokyoR39/yokkuns/index.html#49 21/48 並び替えた時の添字ベクトルが欲しい order関数 #
昇順 head(order(airquality$Ozone)) ## [1] 21 23 18 11 76 147 head(airquality[order(airquality$Ozone), ]) ## Ozone Solar.R Wind Temp Month Day ## 21 1 8 9.7 59 5 21 ## 23 4 25 9.7 61 5 23 ## 18 6 78 18.4 57 5 18 ## 11 7 NA 6.9 74 5 11 ## 76 7 48 14.3 80 7 15 ## 147 7 49 10.3 69 9 24 21/49
22.
2014/5/31 データ・ハンドリング file:///Users/yokkuns/github/TokyoR/TokyoR39/yokkuns/index.html#49 22/48 並び替えた時の添字ベクトルが欲しい order関数 #
降順 head(order(airquality$Ozone, decreasing = T)) ## [1] 117 62 99 121 30 101 head(airquality[order(airquality$Ozone, decreasing = T), ]) ## Ozone Solar.R Wind Temp Month Day ## 117 168 238 3.4 81 8 25 ## 62 135 269 4.1 84 7 1 ## 99 122 255 4.0 89 8 7 ## 121 118 225 2.3 94 8 29 ## 30 115 223 5.7 79 5 30 ## 101 110 207 8.0 90 8 9 22/49
23.
2014/5/31 データ・ハンドリング file:///Users/yokkuns/github/TokyoR/TokyoR39/yokkuns/index.html#49 23/48 特定の列で並び替えたデータフレームが欲 しい dplyr::arrange関数 #
昇順 head(dplyr::arrange(airquality, Ozone)) ## Ozone Solar.R Wind Temp Month Day ## 1 1 8 9.7 59 5 21 ## 2 4 25 9.7 61 5 23 ## 3 6 78 18.4 57 5 18 ## 4 7 NA 6.9 74 5 11 ## 5 7 48 14.3 80 7 15 ## 6 7 49 10.3 69 9 24 23/49
24.
2014/5/31 データ・ハンドリング file:///Users/yokkuns/github/TokyoR/TokyoR39/yokkuns/index.html#49 24/48 特定の列で並び替えたデータフレームが欲 しい dplyr::arrange関数 #
降順 head(dplyr::arrange(airquality, desc(Ozone))) ## Ozone Solar.R Wind Temp Month Day ## 1 168 238 3.4 81 8 25 ## 2 135 269 4.1 84 7 1 ## 3 122 255 4.0 89 8 7 ## 4 118 225 2.3 94 8 29 ## 5 115 223 5.7 79 5 30 ## 6 110 207 8.0 90 8 9 24/49
25.
2014/5/31 データ・ハンドリング file:///Users/yokkuns/github/TokyoR/TokyoR39/yokkuns/index.html#49 25/48 特定の列で並び替えたデータフレームが欲 しい dplyr::arrange関数 #
複数の列で並び替え head(dplyr::arrange(airquality, Month, desc(Temp))) ## Ozone Solar.R Wind Temp Month Day ## 1 45 252 14.9 81 5 29 ## 2 115 223 5.7 79 5 30 ## 3 37 279 7.4 76 5 31 ## 4 12 149 12.6 74 5 3 ## 5 7 NA 6.9 74 5 11 ## 6 11 320 16.6 73 5 22 25/49
26.
2014/5/31 データ・ハンドリング file:///Users/yokkuns/github/TokyoR/TokyoR39/yokkuns/index.html#49 26/48 列の追加 26/49
27.
2014/5/31 データ・ハンドリング file:///Users/yokkuns/github/TokyoR/TokyoR39/yokkuns/index.html#49 27/48 通常の代入で追加する aq
<- airquality aq$newCol1 <- "new1" head(aq) ## Ozone Solar.R Wind Temp Month Day newCol1 ## 1 41 190 7.4 67 5 1 new1 ## 2 36 118 8.0 72 5 2 new1 ## 3 12 149 12.6 74 5 3 new1 ## 4 18 313 11.5 62 5 4 new1 ## 5 NA NA 14.3 56 5 5 new1 ## 6 28 NA 14.9 66 5 6 new1 27/49
28.
2014/5/31 データ・ハンドリング file:///Users/yokkuns/github/TokyoR/TokyoR39/yokkuns/index.html#49 28/48 関数で追加する transform関数 aq
<- transform(aq, newCol2 = "new2") head(aq) ## Ozone Solar.R Wind Temp Month Day newCol1 newCol2 ## 1 41 190 7.4 67 5 1 new1 new2 ## 2 36 118 8.0 72 5 2 new1 new2 ## 3 12 149 12.6 74 5 3 new1 new2 ## 4 18 313 11.5 62 5 4 new1 new2 ## 5 NA NA 14.3 56 5 5 new1 new2 ## 6 28 NA 14.9 66 5 6 new1 new2 28/49
29.
2014/5/31 データ・ハンドリング file:///Users/yokkuns/github/TokyoR/TokyoR39/yokkuns/index.html#49 29/48 関数で追加する dplyr::mutate関数 aq
<- dplyr::mutate(aq, newCol3 = "new3") head(aq) ## Ozone Solar.R Wind Temp Month Day newCol1 newCol2 newCol3 ## 1 41 190 7.4 67 5 1 new1 new2 new3 ## 2 36 118 8.0 72 5 2 new1 new2 new3 ## 3 12 149 12.6 74 5 3 new1 new2 new3 ## 4 18 313 11.5 62 5 4 new1 new2 new3 ## 5 NA NA 14.3 56 5 5 new1 new2 new3 ## 6 28 NA 14.9 66 5 6 new1 new2 new3 29/49
30.
2014/5/31 データ・ハンドリング file:///Users/yokkuns/github/TokyoR/TokyoR39/yokkuns/index.html#49 30/48 データフレームの結合 30/49
31.
2014/5/31 データ・ハンドリング file:///Users/yokkuns/github/TokyoR/TokyoR39/yokkuns/index.html#49 31/48 列が同じデータフレームを縦に結合する rbind関数 aq1
<- head(airquality, 3) aq2 <- tail(airquality, 3) aq12 <- rbind(aq1, aq2) aq12 ## Ozone Solar.R Wind Temp Month Day ## 1 41 190 7.4 67 5 1 ## 2 36 118 8.0 72 5 2 ## 3 12 149 12.6 74 5 3 ## 151 14 191 14.3 75 9 28 ## 152 18 131 8.0 76 9 29 ## 153 20 223 11.5 68 9 30 31/49
32.
2014/5/31 データ・ハンドリング file:///Users/yokkuns/github/TokyoR/TokyoR39/yokkuns/index.html#49 32/48 列が異なるデータフレームを縦に結合する plyr::rbind_fill関数 aq1
<- head(airquality, 3)[, 1:3] aq2 <- tail(airquality, 3)[, 1:4] aq12 <- plyr::rbind.fill(aq1, aq2) aq12 ## Ozone Solar.R Wind Temp ## 1 41 190 7.4 NA ## 2 36 118 8.0 NA ## 3 12 149 12.6 NA ## 4 14 191 14.3 75 ## 5 18 131 8.0 76 ## 6 20 223 11.5 68 32/49
33.
2014/5/31 データ・ハンドリング file:///Users/yokkuns/github/TokyoR/TokyoR39/yokkuns/index.html#49 33/48 横に結合する aq1
<- airquality[, 1:3] aq2 <- airquality[, 4:6] aq12 <- cbind(aq1, aq2) head(aq12) ## Ozone Solar.R Wind Temp Month Day ## 1 41 190 7.4 67 5 1 ## 2 36 118 8.0 72 5 2 ## 3 12 149 12.6 74 5 3 ## 4 18 313 11.5 62 5 4 ## 5 NA NA 14.3 56 5 5 ## 6 28 NA 14.9 66 5 6 33/49
34.
2014/5/31 データ・ハンドリング file:///Users/yokkuns/github/TokyoR/TokyoR39/yokkuns/index.html#49 34/48 特定の列をキーにして結合する merge関数 a
<- data.frame(id = 1:10, id2 = 11:20, x = 101:110) b <- data.frame(id = c(1, 3, 5, 11), id2 = c(11, 17, 15, 24), y = c(100, 200, 150, 400)) # 結合出来たレコードのみ ab <- merge(a, b, by = "id") ab ## id id2.x x id2.y y ## 1 1 11 101 11 100 ## 2 3 13 103 17 200 ## 3 5 15 105 15 150 34/49
35.
2014/5/31 データ・ハンドリング file:///Users/yokkuns/github/TokyoR/TokyoR39/yokkuns/index.html#49 35/48 特定の列をキーにして結合する merge関数 #
aは全部残す ab <- merge(a, b, by = "id", all.x = T) ab ## id id2.x x id2.y y ## 1 1 11 101 11 100 ## 2 2 12 102 NA NA ## 3 3 13 103 17 200 ## 4 4 14 104 NA NA ## 5 5 15 105 15 150 ## 6 6 16 106 NA NA ## 7 7 17 107 NA NA ## 8 8 18 108 NA NA ## 9 9 19 109 NA NA ## 10 10 20 110 NA NA 35/49
36.
2014/5/31 データ・ハンドリング file:///Users/yokkuns/github/TokyoR/TokyoR39/yokkuns/index.html#49 36/48 特定の列をキーにして結合する merge関数 #
bは全部残す ab <- merge(a, b, by = "id", all.y = T) ab ## id id2.x x id2.y y ## 1 1 11 101 11 100 ## 2 3 13 103 17 200 ## 3 5 15 105 15 150 ## 4 11 NA NA 24 400 36/49
37.
2014/5/31 データ・ハンドリング file:///Users/yokkuns/github/TokyoR/TokyoR39/yokkuns/index.html#49 37/48 特定の列をキーにして結合する merge関数 #
a、b両方とも全部残す ab <- merge(a, b, by = "id", all = T) ab ## id id2.x x id2.y y ## 1 1 11 101 11 100 ## 2 2 12 102 NA NA ## 3 3 13 103 17 200 ## 4 4 14 104 NA NA ## 5 5 15 105 15 150 ## 6 6 16 106 NA NA ## 7 7 17 107 NA NA ## 8 8 18 108 NA NA ## 9 9 19 109 NA NA ## 10 10 20 110 NA NA ## 11 11 NA NA 24 400 37/49
38.
2014/5/31 データ・ハンドリング file:///Users/yokkuns/github/TokyoR/TokyoR39/yokkuns/index.html#49 38/48 複数の列をキーにして結合する merge関数 #
複数の列をキーにして結合する ab <- merge(a, b, by = c("id", "id2")) ab ## id id2 x y ## 1 1 11 101 100 ## 2 5 15 105 150 38/49
39.
2014/5/31 データ・ハンドリング file:///Users/yokkuns/github/TokyoR/TokyoR39/yokkuns/index.html#49 39/48 ピボットテーブル(reshape2) 39/49
40.
2014/5/31 データ・ハンドリング file:///Users/yokkuns/github/TokyoR/TokyoR39/yokkuns/index.html#49 40/48 縦長のデータフレームを作る reshape2パッケージmelt関数 library(reshape2) aq.melt
<- melt(airquality, id.vars = c("Month", "Day")) aq.melt[seq(100, 500, 100), ] ## Month Day variable value ## 100 8 8 Ozone 89.0 ## 200 6 16 Solar.R 191.0 ## 300 9 24 Solar.R 49.0 ## 400 8 2 Wind 13.8 ## 500 6 10 Temp 87.0 40/49
41.
2014/5/31 データ・ハンドリング file:///Users/yokkuns/github/TokyoR/TokyoR39/yokkuns/index.html#49 41/48 横長のデータフレームを作る reshape2パッケージdcast関数 #
月ごとの平均 aq.cast <- dcast(aq.melt, Month ~ variable, mean, na.rm = T) head(aq.cast) ## Month Ozone Solar.R Wind Temp ## 1 5 23.62 181.3 11.623 65.55 ## 2 6 29.44 190.2 10.267 79.10 ## 3 7 59.12 216.5 8.942 83.90 ## 4 8 59.96 171.9 8.794 83.97 ## 5 9 31.45 167.4 10.180 76.90 41/49
42.
2014/5/31 データ・ハンドリング file:///Users/yokkuns/github/TokyoR/TokyoR39/yokkuns/index.html#49 42/48 横長のデータフレームを作る reshape2パッケージdcast関数 aq.cast
<- dcast(aq.melt, Month + Day ~ variable, mean, na.rm = T) head(aq.cast) ## Month Day Ozone Solar.R Wind Temp ## 1 5 1 41 190 7.4 67 ## 2 5 2 36 118 8.0 72 ## 3 5 3 12 149 12.6 74 ## 4 5 4 18 313 11.5 62 ## 5 5 5 NaN NaN 14.3 56 ## 6 5 6 28 NaN 14.9 66 42/49
43.
2014/5/31 データ・ハンドリング file:///Users/yokkuns/github/TokyoR/TokyoR39/yokkuns/index.html#49 43/48 横長のデータフレームを作る reshape2パッケージdcast関数 aq.cast
<- dcast(aq.melt, Day ~ Month + variable, mean, na.rm = T) head(aq.cast[, 1:8]) ## Day 5_Ozone 5_Solar.R 5_Wind 5_Temp 6_Ozone 6_Solar.R 6_Wind ## 1 1 41 190 7.4 67 NaN 286 8.6 ## 2 2 36 118 8.0 72 NaN 287 9.7 ## 3 3 12 149 12.6 74 NaN 242 16.1 ## 4 4 18 313 11.5 62 NaN 186 9.2 ## 5 5 NaN NaN 14.3 56 NaN 220 8.6 ## 6 6 28 NaN 14.9 66 NaN 264 14.3 43/49
44.
2014/5/31 データ・ハンドリング file:///Users/yokkuns/github/TokyoR/TokyoR39/yokkuns/index.html#49 44/48 集約処理(dplyr) library(dplyr) #
使用するデータ head(mtcars) ## mpg cyl disp hp drat wt qsec vs am gear carb ## Mazda RX4 21.0 6 160 110 3.90 2.620 16.46 0 1 4 4 ## Mazda RX4 Wag 21.0 6 160 110 3.90 2.875 17.02 0 1 4 4 ## Datsun 710 22.8 4 108 93 3.85 2.320 18.61 1 1 4 1 ## Hornet 4 Drive 21.4 6 258 110 3.08 3.215 19.44 1 0 3 1 ## Hornet Sportabout 18.7 8 360 175 3.15 3.440 17.02 0 0 3 2 ## Valiant 18.1 6 225 105 2.76 3.460 20.22 1 0 3 1 44/49
45.
2014/5/31 データ・ハンドリング file:///Users/yokkuns/github/TokyoR/TokyoR39/yokkuns/index.html#49 45/48 グループごとに集約処理したデータフレー ムを作る group_by
+ summarise mtcars %.% group_by(am) %.% summarise(mpg.mean = mean(mpg)) ## Source: local data frame [2 x 2] ## ## am mpg.mean ## 1 0 17.15 ## 2 1 24.39 45/49
46.
2014/5/31 データ・ハンドリング file:///Users/yokkuns/github/TokyoR/TokyoR39/yokkuns/index.html#49 46/48 グループごとに集約処理したデータフレー ムを作る group_by
+ summarise mtcars %.% group_by(am) %.% summarise(mpg.mean = mean(mpg), count = length(mpg), mpg.max = max(mpg), cyl.mpg.max = cyl[which.max(mpg)]) ## Source: local data frame [2 x 5] ## ## am mpg.mean count mpg.max cyl.mpg.max ## 1 0 17.15 19 24.4 4 ## 2 1 24.39 13 33.9 4 46/49
47.
2014/5/31 データ・ハンドリング file:///Users/yokkuns/github/TokyoR/TokyoR39/yokkuns/index.html#49 47/48 グループごとに集約処理した値を新たな列 として追加する group_by
+ mutate mtcars %.% group_by(am, vs) %.% mutate(mpg.mean = mean(mpg), mpg.sd = sd(mpg)) %.% as.data.frame() %.% head() ## mpg cyl disp hp drat wt qsec vs am gear carb mpg.mean mpg.sd ## 1 21.0 6 160 110 3.90 2.620 16.46 0 1 4 4 19.75 4.009 ## 2 21.0 6 160 110 3.90 2.875 17.02 0 1 4 4 19.75 4.009 ## 3 22.8 4 108 93 3.85 2.320 18.61 1 1 4 1 28.37 4.758 ## 4 21.4 6 258 110 3.08 3.215 19.44 1 0 3 1 20.74 2.471 ## 5 18.7 8 360 175 3.15 3.440 17.02 0 0 3 2 15.05 2.774 ## 6 18.1 6 225 105 2.76 3.460 20.22 1 0 3 1 20.74 2.471 47/49
48.
2014/5/31 データ・ハンドリング file:///Users/yokkuns/github/TokyoR/TokyoR39/yokkuns/index.html#49 48/48 49/49
Jetzt herunterladen