SlideShare a Scribd company logo
1 of 27
TokyoR #53
初心者セッション
l@kotatyamtema
@kotatyamtema
大学での専門は行動生態学
性的二型とsexual selection
対象は魚類:♂の背びれの伸長に
影響を与える要因を探索
職歴
家電メーカーでユーザビリティ評価
心拍や脳波,脳血流を使った身体反応評価
筋電図を使った身体負荷評価,歩容(歩く姿勢)評価
医療機器メーカーで臨床試験のデータ管理と初期分析
投薬データのダミー化と集計,欠損確認,基礎統計量の算出
活動量計データの自動集約,レポート生成スクリプトの作成
現在
DATUM STUDIO 株式会社
データアナリストとして生息中
自己紹介
データ分析
前処理あるある
上司A:
"グレー"っぽい色に
フラグ立てといて
どうしよう・・・
本日のお題
ゆるふわ文字型データの
取り扱い入門
lEncodeと便利パッケージと正規表現
Encodingとは
Encodingとは
プログラムが文字を認識するためのルール
だいたい遭遇するのは2種
Windows : SJIS(cp932)
Mac : UTF-8
Encodingとは
プログラムが文字を認識するためのルール
だいたい遭遇するのは2種
Windows : SJIS(cp932)
Mac : UTF-8
SJISで保存されたデータをUTF-8環境で読み込むと
Encodingとは
プログラムが文字を認識するためのルール
だいたい遭遇するのは2種
Windows : SJIS(cp932)
Mac : UTF-8
Encodingの呪い
文字化け
解消するには「iconv関数」
iconv(hoge, "現在のEncoding",
"変換後のEncoding")
解消するには「iconv関数」
iconv(hoge, "現在のEncoding",
"変換後のEncoding")
現在のEncodingを確認するには?
解消するには「iconv関数」
iconv(hoge, "現在のEncoding",
"変換後のEncoding")
現在のEncodingを確認するには?
少量抜き出してテキストエディタで確認
Rで文字列処理事始め
lstringiパッケージと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
正規表現事始め
lより柔軟な文字処理のために
正規表現とは
柔軟な文字表現が出来る記述方法
→いろいろなプログラムで使用できる
拡張表現
[]で挟んだ文字全てに対して処理される
・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

Viewers also liked

Mofuse mobile web
Mofuse mobile webMofuse mobile web
Mofuse mobile webKr Vikas
 
Best Cellulite Removal
Best Cellulite RemovalBest Cellulite Removal
Best Cellulite Removalmaycockmc
 
Body Fat Loss Program
Body Fat Loss ProgramBody Fat Loss Program
Body Fat Loss Programmaycockmc
 
Symptoms Of Ovarian Cyst
Symptoms Of Ovarian CystSymptoms Of Ovarian Cyst
Symptoms Of Ovarian Cystbrihanylam
 
Scientists devise new way to dramatically raise rna treatment potency
Scientists devise new way to dramatically raise rna treatment potencyScientists devise new way to dramatically raise rna treatment potency
Scientists devise new way to dramatically raise rna treatment potencyDisney Scripps Florida
 
Potential Treatment for ALS and Frontotemporal Dementia Discovered
Potential Treatment for ALS and Frontotemporal Dementia DiscoveredPotential Treatment for ALS and Frontotemporal Dementia Discovered
Potential Treatment for ALS and Frontotemporal Dementia DiscoveredDisney Scripps Florida
 
Girls Looking For Men
Girls Looking For MenGirls Looking For Men
Girls Looking For Menbrihanylam
 
Power de planos
Power de planosPower de planos
Power de planosNor2012
 
Marketing upulsa mubu
Marketing upulsa mubuMarketing upulsa mubu
Marketing upulsa mubumegaanto
 
피티프로그램
피티프로그램피티프로그램
피티프로그램KG_Passone
 
A Molecular Advancement for Muscular Dystrophy
A Molecular Advancement for Muscular DystrophyA Molecular Advancement for Muscular Dystrophy
A Molecular Advancement for Muscular DystrophyDisney Scripps Florida
 
Music cover analysis
Music cover analysisMusic cover analysis
Music cover analysisToddcg12
 

Viewers also liked (19)

Skates pp.11 12
Skates pp.11 12Skates pp.11 12
Skates pp.11 12
 
Mofuse mobile web
Mofuse mobile webMofuse mobile web
Mofuse mobile web
 
Best Cellulite Removal
Best Cellulite RemovalBest Cellulite Removal
Best Cellulite Removal
 
Video Analysis
Video AnalysisVideo Analysis
Video Analysis
 
Body Fat Loss Program
Body Fat Loss ProgramBody Fat Loss Program
Body Fat Loss Program
 
Symptoms Of Ovarian Cyst
Symptoms Of Ovarian CystSymptoms Of Ovarian Cyst
Symptoms Of Ovarian Cyst
 
Scientists devise new way to dramatically raise rna treatment potency
Scientists devise new way to dramatically raise rna treatment potencyScientists devise new way to dramatically raise rna treatment potency
Scientists devise new way to dramatically raise rna treatment potency
 
Ma.candelaria parés
Ma.candelaria parés Ma.candelaria parés
Ma.candelaria parés
 
Potential Treatment for ALS and Frontotemporal Dementia Discovered
Potential Treatment for ALS and Frontotemporal Dementia DiscoveredPotential Treatment for ALS and Frontotemporal Dementia Discovered
Potential Treatment for ALS and Frontotemporal Dementia Discovered
 
Girls Looking For Men
Girls Looking For MenGirls Looking For Men
Girls Looking For Men
 
Power de planos
Power de planosPower de planos
Power de planos
 
Marketing upulsa mubu
Marketing upulsa mubuMarketing upulsa mubu
Marketing upulsa mubu
 
피티프로그램
피티프로그램피티프로그램
피티프로그램
 
Final Thriller Idea
Final Thriller IdeaFinal Thriller Idea
Final Thriller Idea
 
Thriller Directors
Thriller DirectorsThriller Directors
Thriller Directors
 
A Molecular Advancement for Muscular Dystrophy
A Molecular Advancement for Muscular DystrophyA Molecular Advancement for Muscular Dystrophy
A Molecular Advancement for Muscular Dystrophy
 
Skates nov27
Skates nov27Skates nov27
Skates nov27
 
Storyboard - Demons
Storyboard - DemonsStoryboard - Demons
Storyboard - Demons
 
Music cover analysis
Music cover analysisMusic cover analysis
Music cover analysis
 

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
 

TokyoR#53初心者セッション