SlideShare a Scribd company logo
1 of 27
TokyoR #57
初心者セッション
@kotatyamtema
@kotatyamtema
大学での専門は行動生態学
性的二型とsexual selection
対象は魚類:♂の背びれの伸長に
影響を与える要因を探索
職歴
家電メーカーでユーザビリティ評価
心拍や脳波,脳血流を使った身体反応評価
筋電図を使った身体負荷評価,歩容(歩く姿勢)評価
医療機器メーカーで臨床試験のデータ管理と初期分析
投薬データのダミー化と集計,欠損確認,基礎統計量の算出
活動量計データの自動集約,レポート生成スクリプトの作成
現在
DATUM STUDIO 株式会社
データアナリストとして生息中
自己紹介
データ分析
前処理あるある
上司A:
"グレー"っぽい色に
フラグ立てといて
どうしよう・・・
本日のお題
ゆるふわ文字型データの
取り扱い入門
Encodeと便利パッケージと正規表現
Encodingとは
Encodingとは
プログラムが文字を認識するためのルール
だいたい遭遇するのは2種
Windows : SJIS(cp932)
Mac/Linux : UTF-8
Encodingとは
プログラムが文字を認識するためのルール
だいたい遭遇するのは2種
Windows : SJIS(cp932)
Mac/Linux : UTF-8
SJISで保存されたデータをUTF-8環境で読み込むと
Encodingとは
プログラムが文字を認識するためのルール
だいたい遭遇するのは2種
Windows : SJIS(cp932)
Mac/Linux : UTF-8
Encodingの呪い
文字化け
解消するには「iconv関数」
iconv(hoge, "現在のEncoding",
"変換後のEncoding")
解消するには「iconv関数」
iconv(hoge, "現在のEncoding",
"変換後のEncoding")
現在のEncodingを確認するには?
解消するには「iconv関数」
iconv(hoge, "現在のEncoding",
"変換後のEncoding")
現在のEncodingを確認するには?
少量抜き出してテキストエディタで
Encoding(hoge)で確認できます
Rで文字列処理事始め
stringiパッケージとbaseを比較しながら
Rで文字列処理
おすすめパッケージは「stringi」
base処理と比較しながら
簡単な処理方法を紹介
スクリプト一覧
stringi base
特定の文字の
有無を判定
stri_detect_regex
(判定対象, hoge)
grep
(hoge, 判定対象)
特定の文字を
抽出
stri_extract_all_regex
(判定対象, hoge)
-----------
特定の文字を
置換
stri_replace_all_regex
(判定対象, 置換前, 置換後)
gsub
(置換前, 置換後, 判定対象)
スクリプト一覧
stringi base
文字の長さを
数える
stri_length
(判定対象)
nchar
(判定対象)
文字同士を
つなげる
stri_join
(kore, hoge)
paste0
(kore, hoge)
特定の文字で
分割
stri_split_regex
(判定対象, hoge)
strsplit
(判定対象, hoge)
機能はもっとたくさんあるので
以下のサイトを参照
base
http://www.okadajp.org/RWiki/?Rの文字列処理関数
stringi
https://cran.r-project.org/web/packages/stringi/stringi.pdf
http://qiita.com/kohske/items/85d49da04571e9055c44
正規表現事始め
より柔軟な文字処理のために
正規表現とは
柔軟な文字表現が出来る記述方法
→いろいろなプログラムで使用できる
拡張表現
[]で挟んだ文字全てに対して処理される
・stri_detect_regex(text, [a:c]):
textの中にa,b,cのいずれかが含まれているかどうか判定
メタ文字は前に""をつける
・メタ文字は ".  | ( ) [ { ^ $ * + ? "
"^hoge"でhogeから始まる文字を指定
"hoge$"でhogeで終わる文字を指定
繰り返し表現
'hoge{n}': hogeをちょうど n 回繰り返す
'hoge{n,}': hogeを n 回以上繰り返す
'hoge{n,m}': hogeを n 回以上、最大 m 回繰り返す
詳細は以下を参考
http://www.okadajp.org/RWiki/?R%20における正規表現
stringiと正規表現の
組み合わせで自由な文字処理
stringiと正規表現の
組み合わせで自由な文字処理
例: listの中からcsvファイル名を抽出
list[stri_detect_regex(list, ".csv$")]
stri_subset_regex(list, ".csv$")
例: "あ"で始まって"ん"で終わる5文字を抽出
stri_extract_all_regex(text, "あ.{3}ん")
Rで自由な文字処理を!
Rで自由な文字処理を!
Enjoy!

More Related Content

More from kotora_0507

TokyoR102_BeginnersSession.pdf
TokyoR102_BeginnersSession.pdfTokyoR102_BeginnersSession.pdf
TokyoR102_BeginnersSession.pdfkotora_0507
 
TokyoR101_BeginnersSession2.pdf
TokyoR101_BeginnersSession2.pdfTokyoR101_BeginnersSession2.pdf
TokyoR101_BeginnersSession2.pdfkotora_0507
 
TokyoR101_BeginnersSession1.pdf
TokyoR101_BeginnersSession1.pdfTokyoR101_BeginnersSession1.pdf
TokyoR101_BeginnersSession1.pdfkotora_0507
 
TokyoR98_BeginnersSession1.pdf
TokyoR98_BeginnersSession1.pdfTokyoR98_BeginnersSession1.pdf
TokyoR98_BeginnersSession1.pdfkotora_0507
 
Tokyo r94 beginnerssession3
Tokyo r94 beginnerssession3Tokyo r94 beginnerssession3
Tokyo r94 beginnerssession3kotora_0507
 
Tokyo r80 beginnerssession1
Tokyo r80 beginnerssession1Tokyo r80 beginnerssession1
Tokyo r80 beginnerssession1kotora_0507
 
TokyoR79 beginnerssession1
TokyoR79 beginnerssession1TokyoR79 beginnerssession1
TokyoR79 beginnerssession1kotora_0507
 
Sendai r01 beginnerssession1
Sendai r01 beginnerssession1Sendai r01 beginnerssession1
Sendai r01 beginnerssession1kotora_0507
 
Beginners session2 in TokyoR69
Beginners session2 in TokyoR69Beginners session2 in TokyoR69
Beginners session2 in TokyoR69kotora_0507
 
Beginners session2 68
Beginners session2 68Beginners session2 68
Beginners session2 68kotora_0507
 

More from kotora_0507 (10)

TokyoR102_BeginnersSession.pdf
TokyoR102_BeginnersSession.pdfTokyoR102_BeginnersSession.pdf
TokyoR102_BeginnersSession.pdf
 
TokyoR101_BeginnersSession2.pdf
TokyoR101_BeginnersSession2.pdfTokyoR101_BeginnersSession2.pdf
TokyoR101_BeginnersSession2.pdf
 
TokyoR101_BeginnersSession1.pdf
TokyoR101_BeginnersSession1.pdfTokyoR101_BeginnersSession1.pdf
TokyoR101_BeginnersSession1.pdf
 
TokyoR98_BeginnersSession1.pdf
TokyoR98_BeginnersSession1.pdfTokyoR98_BeginnersSession1.pdf
TokyoR98_BeginnersSession1.pdf
 
Tokyo r94 beginnerssession3
Tokyo r94 beginnerssession3Tokyo r94 beginnerssession3
Tokyo r94 beginnerssession3
 
Tokyo r80 beginnerssession1
Tokyo r80 beginnerssession1Tokyo r80 beginnerssession1
Tokyo r80 beginnerssession1
 
TokyoR79 beginnerssession1
TokyoR79 beginnerssession1TokyoR79 beginnerssession1
TokyoR79 beginnerssession1
 
Sendai r01 beginnerssession1
Sendai r01 beginnerssession1Sendai r01 beginnerssession1
Sendai r01 beginnerssession1
 
Beginners session2 in TokyoR69
Beginners session2 in TokyoR69Beginners session2 in TokyoR69
Beginners session2 in TokyoR69
 
Beginners session2 68
Beginners session2 68Beginners session2 68
Beginners session2 68
 

Recently uploaded

Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介
Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介
Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介Yuma Ohgami
 
【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)
【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)
【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)Hiroki Ichikura
 
スマートフォンを用いた新生児あやし動作の教示システム
スマートフォンを用いた新生児あやし動作の教示システムスマートフォンを用いた新生児あやし動作の教示システム
スマートフォンを用いた新生児あやし動作の教示システムsugiuralab
 
TSAL operation mechanism and circuit diagram.pdf
TSAL operation mechanism and circuit diagram.pdfTSAL operation mechanism and circuit diagram.pdf
TSAL operation mechanism and circuit diagram.pdftaisei2219
 
[DevOpsDays Tokyo 2024] 〜デジタルとアナログのはざまに〜 スマートビルディング爆速開発を支える 自動化テスト戦略
[DevOpsDays Tokyo 2024] 〜デジタルとアナログのはざまに〜 スマートビルディング爆速開発を支える 自動化テスト戦略[DevOpsDays Tokyo 2024] 〜デジタルとアナログのはざまに〜 スマートビルディング爆速開発を支える 自動化テスト戦略
[DevOpsDays Tokyo 2024] 〜デジタルとアナログのはざまに〜 スマートビルディング爆速開発を支える 自動化テスト戦略Ryo Sasaki
 
論文紹介:Semantic segmentation using Vision Transformers: A survey
論文紹介:Semantic segmentation using Vision Transformers: A survey論文紹介:Semantic segmentation using Vision Transformers: A survey
論文紹介:Semantic segmentation using Vision Transformers: A surveyToru Tamaki
 
論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...
論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...
論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...Toru Tamaki
 
論文紹介:Automated Classification of Model Errors on ImageNet
論文紹介:Automated Classification of Model Errors on ImageNet論文紹介:Automated Classification of Model Errors on ImageNet
論文紹介:Automated Classification of Model Errors on ImageNetToru Tamaki
 
SOPを理解する 2024/04/19 の勉強会で発表されたものです
SOPを理解する       2024/04/19 の勉強会で発表されたものですSOPを理解する       2024/04/19 の勉強会で発表されたものです
SOPを理解する 2024/04/19 の勉強会で発表されたものですiPride Co., Ltd.
 

Recently uploaded (9)

Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介
Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介
Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介
 
【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)
【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)
【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)
 
スマートフォンを用いた新生児あやし動作の教示システム
スマートフォンを用いた新生児あやし動作の教示システムスマートフォンを用いた新生児あやし動作の教示システム
スマートフォンを用いた新生児あやし動作の教示システム
 
TSAL operation mechanism and circuit diagram.pdf
TSAL operation mechanism and circuit diagram.pdfTSAL operation mechanism and circuit diagram.pdf
TSAL operation mechanism and circuit diagram.pdf
 
[DevOpsDays Tokyo 2024] 〜デジタルとアナログのはざまに〜 スマートビルディング爆速開発を支える 自動化テスト戦略
[DevOpsDays Tokyo 2024] 〜デジタルとアナログのはざまに〜 スマートビルディング爆速開発を支える 自動化テスト戦略[DevOpsDays Tokyo 2024] 〜デジタルとアナログのはざまに〜 スマートビルディング爆速開発を支える 自動化テスト戦略
[DevOpsDays Tokyo 2024] 〜デジタルとアナログのはざまに〜 スマートビルディング爆速開発を支える 自動化テスト戦略
 
論文紹介:Semantic segmentation using Vision Transformers: A survey
論文紹介:Semantic segmentation using Vision Transformers: A survey論文紹介:Semantic segmentation using Vision Transformers: A survey
論文紹介:Semantic segmentation using Vision Transformers: A survey
 
論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...
論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...
論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...
 
論文紹介:Automated Classification of Model Errors on ImageNet
論文紹介:Automated Classification of Model Errors on ImageNet論文紹介:Automated Classification of Model Errors on ImageNet
論文紹介:Automated Classification of Model Errors on ImageNet
 
SOPを理解する 2024/04/19 の勉強会で発表されたものです
SOPを理解する       2024/04/19 の勉強会で発表されたものですSOPを理解する       2024/04/19 の勉強会で発表されたものです
SOPを理解する 2024/04/19 の勉強会で発表されたものです
 

TokyoR #57 初心者セッション