Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
はじめてのR@fukuoka.R#08
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
nonki1974
July 07, 2017
Technology
580
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
はじめてのR@fukuoka.R#08
nonki1974
July 07, 2017
More Decks by nonki1974
See All by nonki1974
GTFS with Tidytransit package
nonki1974
0
350
TokyoR#84_Rexams
nonki1974
0
240
都道府県別焼き鳥屋ランキングの作成
nonki1974
1
940
Introduction to R
nonki1974
0
400
Introduction to dplyr
nonki1974
0
570
Introduction to ggplot2
nonki1974
1
560
Analyzing PSB tracks with R
nonki1974
0
640
introduction to fukuoka.R @ Fukuoka.LT
nonki1974
0
85
所要時間のヒートマップを作成する
nonki1974
0
610
Other Decks in Technology
See All in Technology
全社共通データ基盤をつくる。ソニーのDatabricks活用とデータガバナンス設計の裏側
sony
0
160
AWS FinOps Agent 結局何が得意なの?
siromi
0
220
spanner-autoscalerに学ぶ CRD設計パターン 〜自動化と緊急時対応を両立する Kubernetesコントローラーの作り方〜
tkuchiki
0
200
AIに書かせて、プラットフォームで縛る ― EKSプラットフォームで実践した責任境界と権限設計
elmodev09
1
970
生成AIを使って「人が」考える技術 ― AI時代の人機共想と実践ノウハウ|UNITT AC2026
ishiirikie
0
380
TiDBファミリーにDWHが新登場!! TiDB最新情報 / TiDB update 202609
yoshiakiyamasaki
0
150
3人で1000GPU超を統合運用する?マルチクラウド&オンプレを跨ぐ、構築と運用のリアル!
kazukun0716
2
710
あなたの知らないAmazon VPC Route Server/Amazon VPC Route Server you don't know about
masakiokuda
0
110
キャリアLT今日までそして明日から
kentapapa
1
100
LT:「このままでいいのかな?」から一歩踏み出した私のデータキャリア選択〜社会人3年目に上京を決意したリアル〜Snowflake女子会 vol.8
snowwmn0824
0
110
JSONataとAWS Step Functionsで目指すRuntimelessな世界
mu7889yoon
1
550
【データ横丁主催】AI Agentがコンテキストを使って仕事をした後、何が残るのか― 組織の経験を次の判断に引き継ぐ「Agent Memory」
shisyu_gaku
2
200
Featured
See All Featured
Navigating the moral maze — ethical principles for Al-driven product design
skipperchong
2
590
Producing Creativity
orderedlist
PRO
348
41k
Heart Work Chapter 1 - Part 1
lfama
PRO
10
36k
[RailsConf 2023] Rails as a piece of cake
palkan
59
7k
30 Presentation Tips
portentint
PRO
1
410
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
35
2.9k
Groundhog Day: Seeking Process in Gaming for Health
codingconduct
0
380
Digital Ethics as a Driver of Design Innovation
axbom
PRO
1
440
SEOcharity - Dark patterns in SEO and UX: How to avoid them and build a more ethical web
sarafernandez
0
290
Building a A Zero-Code AI SEO Workflow
portentint
PRO
0
750
Embracing the Ebb and Flow
colly
88
5.2k
Agile Actions for Facilitating Distributed Teams - ADO2019
mkilby
0
290
Transcript
はじめてのR @nonki1974 2017/07/07 fukuoka.R#08 20分で分かる!
R | 統計解析ソフトウェア・環境・言語 スクリプトでデータ分析手順を記録できる 異なるデータへの同じ処理の適用 豊富なパッケージ群(10000以上!) カスタマイズ可能な統計グラフィックス R Markdownによるレポートへの分析結果の埋め込み
Rのダウンロードとインストール CRAN:http://cran.r-project.org/ 国内ミラーサイト:http://cran.ism.ac.jp/
Rの起動 ここにコマンドを入力
簡易エディタ [Ctrl]+[r]でコンソールに 送られて実行される
Macでも [Command]+[Enter] でコンソールに 送られて実行される
Rの基本 データ構造 データ型 ベクトル 行列・配列 リスト データフレーム 整数型 実数型 論理型
文字列 因子型
ベクトル|データ構造の基本 > # 正規乱数を6個生成 > rnorm(6) [1] 0.005495013 -0.890328528 -0.263456883
[4] -1.157257872 1.834184513 0.045427708 行の先頭が何番目の 要素かを示している
ベクトル 数値も長さ1のベクトルとして扱われる! > 3+4 [1] 7
変数への代入 > x <- rnorm(2) > x [1] -0.6129402 0.9781342
代入記号は <- 変数+[Enter]で中身を表示
ベクトルの作成 > y <- c(3, 4.5) > y [1] 3.0
4.5 c()関数で値をつなげて ベクトルを作成
行列・配列 次元属性を持ったベクトル > x <- rnorm(6) > x [1] 0.18895713
-0.95296182 -0.44022548 [4] 1.16125533 0.69121613 0.00886386 > dim(x) <- c(2,3) > x [,1] [,2] [,3] [1,] 0.1889571 -0.4402255 0.69121613 [2,] -0.9529618 1.1612553 0.00886386 > x[2,3] [1] 0.00886386 > x[5] [1] 0.6912161
リスト データ型の異なる複数のベクトルや、 複数のリストを一括して保持できるデータ構造 分析結果はリストで返されることが多い > date <- "2017-07-07" > name
<- c("コイキング", "イーブイ") > cp <- c(23, 182) > > pokemon <- list(date=date, name=name, cp=cp) > pokemon $date [1] "2017-07-07" $name [1] "コイキング" "イーブイ" $cp [1] 23 182
リスト | 要素の参照 > pokemon$name [1] "コイキング" "イーブイ" > pokemon[[2]]
[1] "コイキング" "イーブイ" > pokemon[2] $name [1] "コイキング" "イーブイ" [[要素番号]] もしくは $要素名で オブジェクト自身を参照可能 [要素番号] の場合はリストが返される
データフレーム 行列風の外見を持つリスト 同じ大きさのベクトルを要素とする > name <- c("コイキング", "イーブイ", "フシギダネ") >
cp <- c(23, 182, 128) > weight <- c(7.95, 7.54, 6.95) > height <- c(0.78, 0.32, 0.65) > df <- data.frame(name, cp, weight, height) > df name cp weight height 1 コイキング 23 7.95 0.78 2 イーブイ 182 7.54 0.32 3 フシギダネ 128 6.95 0.65
データフレーム|要素の参照 > df$cp [1] 23 182 128 > df[,2] [1]
23 182 128 > df[1,] name cp weight height 1 コイキング 23 7.95 0.78 > colnames(df) [1] "name" "cp" "weight" "height" > rownames(df) [1] "1" "2" "3"
csvファイルの読み込み | read.csv()関数 csvファイルを読み込んで、データフレームに格納 > setwd(“~/temp/work”) > pokemon <- read.csv("pokemon.csv")
> head(pokemon[,c("id","name","CP","weight","height")]) id name CP weight height 1 2 フシギソウ 303 13.61 1.04 2 7 ゼニガメ 91 11.66 0.53 3 11 トランセル 83 3.41 0.63 4 15 スピアー 69 29.50 1.06 5 18 ピジョット 783 19.12 1.45 6 20 ラッタ 474 2.97 0.70
要約 | summary()関数 > summary(pokemon) id name CP sex Min.
: 2.00 イーブイ : 2 Min. : 10.0 オス:45 1st Qu.: 54.25 アーボック: 1 1st Qu.: 142.8 なし: 4 Median :108.50 アズマオウ: 1 Median : 299.5 メス:23 Mean :107.44 イシツブテ: 1 Mean : 371.6 3rd Qu.:152.75 イトマル : 1 3rd Qu.: 506.2 Max. :226.00 ウソッキー: 1 Max. :1324.0 (Other) :65 HP weight height type1 Min. : 10.00 Min. : 0.120 Min. :0.1900 みず :15 1st Qu.: 31.00 1st Qu.: 5.122 1st Qu.:0.4475 ノーマル:13 Median : 48.50 Median : 11.125 Median :0.8800 むし : 8 Mean : 50.26 Mean : 23.148 Mean :0.9422 くさ : 7 3rd Qu.: 62.25 3rd Qu.: 31.545 3rd Qu.:1.2800 ほのお : 6 Max. :137.00 Max. :136.010 Max. :3.9800 いわ : 4 (Other) :19
要約の続き | summary()関数 type2 waza1 AP1 :39 たいあたり :12 Min.
: 0.000 ひこう :10 みずてっぽう : 5 1st Qu.: 5.000 どく : 8 でんこうせっか: 4 Median : 6.500 エスパー: 3 ねんりき : 4 Mean : 8.167 じめん : 3 ひのこ : 4 3rd Qu.:10.000 いわ : 2 あわ : 3 Max. :20.000 (Other) : 7 (Other) :40 waza2 AP2 date pref こごえるかぜ : 4 Min. : 35.00 2017/6/20: 8 東京都: 2 10まんボルト: 3 1st Qu.: 55.00 2016/7/24: 6 福岡県:70 アクアテール : 3 Median : 70.00 2016/7/25: 4 ニトロチャージ: 3 Mean : 73.53 2016/7/26: 4 ヘドロばくだん: 3 3rd Qu.: 90.00 2016/7/27: 4 わるあがき : 3 Max. :180.00 2016/7/30: 4 (Other) :53 (Other) :42 city 江東区 : 1 港区 : 1 福岡市中央区: 6 福岡市東区 :10 福岡市南区 :54
プロットの例 > plot(height~weight, data=pokemon) > hist(pokemon$CP)
パッケージのインストール&ロード > # パッケージのインストール > install.packages(c("ggplot2", "dplyr")) > # パッケージのロード
> library(ggplot2) > library(dplyr)
パッケージ利用例 | dplyr & ggplot2 > pokemon %>% + select(CP,
weight, height, type1) %>% + group_by(type1) %>% + summarise_all(mean) %>% + ggplot(aes(weight, height, label=type1)) + + geom_text(aes(color=type1), size=8) + + theme_bw(base_size=20) + + theme(legend.position="none")
出力結果
次のステップとして・・・ • RStudio • 欠損値 • 因子型(factor) • dplyrパッケージ •
文字列処理 • apply系関数群 • R Markdown
書籍 分析手法の説明 +Rでの実行例 グラフ作成の リファレンス R言語全般の リファレンス
enjoy!