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
BeginnerSession1_69th_TokyoR
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
kilometer
April 21, 2018
Technology
530
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
BeginnerSession1_69th_TokyoR
第69回TokyoR初心者セッション1の資料です。
kilometer
April 21, 2018
More Decks by kilometer
See All by kilometer
TokyoR#111_ANOVA
kilometer
2
1k
TokyoR109.pdf
kilometer
1
590
TokyoR#108_NestedDataHandling
kilometer
0
960
TokyoR#107_R_GeoData
kilometer
0
540
SappoRo.R_roundrobin
kilometer
0
220
TokyoR#104_DataProcessing
kilometer
1
810
TokyoR#103_DataProcessing
kilometer
0
1k
TokyoR#102_RMarkdown
kilometer
1
750
TokyoR#101_RegressionAnalysis
kilometer
0
580
Other Decks in Technology
See All in Technology
OptunaHub: ブラックボックス最適化のためのプラットフォーム
pfn
PRO
0
150
パスキーの自動テストはどこまでいけるのか
teamlab
PRO
0
300
日本語に強いオープンな大規模言語モデル「LLM-jp」
odashi
5
1.2k
JAWS-UGグッズ職人仕事の流儀
kentapapa
0
130
ブラウザとサーバーから考えるAI時代のフロントエンド監視
shogo4131
3
1k
「私が一番顧客に詳しい」を捨てる~ 全員が一次情報に精通する開発チームをつくり、PMが次のボトルネックへ染み出すまで
kaminashi
0
200
Temporal 最高!でも改めて「日付」について調べたら人類の負債すぎる件
riyaamemiya
0
210
PagerDuty Tech Hub-鳴らすけれど、人は動かない
ezaki
0
190
AI駆動で「他アプリの音を加工できる」アプリを作った
satomasahiro2005
0
180
1つのリクエストを追って理解する - llm-dのP/D分離
akhino
1
180
初海外で注意すべきこと12選!!!安全快適なre:invent生活にするために
yuuuuuuu168
1
190
コンテナ運用におけるネットワーク・コンテナコストの削減方法/How to Reduce Network and Container Costs in Container Operations
masakiokuda
2
330
Featured
See All Featured
The Organizational Zoo: Understanding Human Behavior Agility Through Metaphoric Constructive Conversations (based on the works of Arthur Shelley, Ph.D)
kimpetersen
PRO
0
500
Amusing Abliteration
ianozsvald
1
350
Building Flexible Design Systems
yeseniaperezcruz
330
41k
SEO for Brand Visibility & Recognition
aleyda
0
4.8k
Digital Projects Gone Horribly Wrong (And the UX Pros Who Still Save the Day) - Dean Schuster
uxyall
1
3.4k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
123
22k
Music & Morning Musume
bryan
48
7.4k
The Cult of Friendly URLs
andyhume
79
7k
HU Berlin: Industrial-Strength Natural Language Processing with spaCy and Prodigy
inesmontani
PRO
0
760
Conquering PDFs: document understanding beyond plain text
inesmontani
PRO
4
3.2k
Leo the Paperboy
mayatellez
10
2.4k
How to Grow Your eCommerce with AI & Automation
katarinadahlin
PRO
2
330
Transcript
69th Tokyo.R @kilometer BeginneR Session 1 -- Data Import /
Export -- 2018.04.21 at Roppongi
Who!?
Who!? 名前: 三村 @kilometer 職業: ポスドク (こうがくはくし) 専門: 行動神経科学(霊長類) 脳イメージング
医療システム工学 R歴: ~ 10年ぐらい 流行: ラム肉
BeginneR Session
BeginneR
BeginneR Advanced Hoxo_m If I have seen further it is
by standing on the sholders of Giants. -- Sir Isaac Newton, 1676
BeginneR
Before After BeginneR Session BeginneR BeginneR
Input Output Today’s talk ? ? Table data Image data
Other formats Introduction Summary
を、始めたいんだけど。 私もそろそろ ぱそこん できるんでしょ?教えてよ。 ぱそこん いいけど、 で何がしたいの? ぱそこん って何でもできるんでしょ? でも、どうしたらいいか分かんないんだ。
一昔前
を、始めたいんだけど。 私もそろそろ じんこう ちのー できるんでしょ?教えてよ。 いいけど、 で何がしたいの? って何でもできるんでしょ? でも、どうしたらいいか分かんないんだ。 最近
じんこう ちのー じんこう ちのー
を、始めたいんだけど。 私もそろそろ できるんでしょ?教えてよ。 いいけど、 で何がしたいの? って何でもできるんでしょ? でも、どうしたらいいか分かんないんだ。
を、始めたいんだけど。 私もそろそろ できるんでしょ?教えてよ。 いいけど、 で何がしたいの? って何でもできるんでしょ? でも、どうしたらいいか分かんないんだ。
Input Output Do NOT start from here
Input Output Do NOT start from here Whatever …
Input Output Do NOT start from here Whatever … 1
2 3
Input Output Today’s talk ? ?
Integrated Development Environment RStudio https://www.rstudio.com/
Integrated Development Environment RStudio https://www.rstudio.com/
RStudio
Projects RStudio
RStudio > Project 一説には2147483647個存在するとも言われるRStudioの利 点のなかでも、 ・Rなどのソースファイルをタブで並べて表示できる ・そのタブの順番を保持できる ・タブの内容をファイルを保存せずにRStudioを終了して しまっても、編集途中の内容を保持してくれている 等が全国2147483647人のRユーザーのQOLを大いに向上さ
せたのは、おそらく異論がないことと思われます。 34UVEJPͬͯͳΜͩʁ 1SPKFDUͬͯͳΜͩ !XBLVUFLB https://qiita.com/wakuteka/items/9599bb0a8985d98928d7
File > New Project… > New Directory > New Project
hogehoge
hogehoge ~/Documents/R hogehoge.Rproj .Rproj.user Project Root Directory Double click!! .RData
.Rhistory Auto saved project information Open project New!!
~/Documents/R project1 project2 project3 project4
Input Output Today’s talk ? ? Table data Image data
Other formats Summary Introduction
Table format data Table data Image data Other formats Introduction
Summary
x <- read.table("import.txt") Import Table format data object assignment operator
file path function
x <- read.table("import.txt") Import Table format data object assignment operator
file path function
~/Documents/ import.txt Target!! data x <- read.table("~/Documents/data/import.txt") setwd("~/Documents/data/") x <-
read.table("import.txt") 1. set working directory 2. then use relative path Method②: use absolute path Method ① Import Table format data
x <- read.table("~/Documents/data/import.txt") setwd("~/Documents/data/") x <- read.table("import.txt") Method②: use absolute
path Method ①: setwd – relative path # working directory wd <- c("~/Documents/data/") # make full path: bind characters path <- paste0(wd, "import.txt") # import data x <- read.table(path) or
prj ~/Documents/R prj.Rproj import.txt Default working directory (project root) Target!!
x <- read.table("import.txt") can use relative path without setwd
x <- read.table(file) Import Table format data
x <- read.table(file) Import Table format data you
Table format data Comma-separated values (.csv) Tab-separated values (.tsv) Space-SV
Semicolon-SV … Delimiter-separated values
Table format data x = np.genfromtxt("hoge.csv", delimiter=",") x <- read.table("hoge.csv",
sep=",") Optional argument(s)
?read.table Usage read.table(file, header = FALSE, sep = "", quote
= "∖", dec = ".", numerals = c("allow.loss", "warn.loss", "no.loss"), row.names, col.names, as.is = !stringsAsFactors, na.strings = "NA", colClasses = NA, nrows = -1, skip = 0, check.names = TRUE, fill = !blank.lines.skip, strip.white = FALSE, blank.lines.skip = TRUE, comment.char = "#", allowEscapes = FALSE, flush = FALSE, stringsAsFactors = default.stringsAsFactors(), fileEncoding = "", encoding = "unknown", text, skipNul = FALSE) Import Table format data
?read.table Usage read.table(file, header = FALSE, sep = "", quote
= "∖", dec = ".", numerals = c("allow.loss", "warn.loss", "no.loss"), row.names, col.names, as.is = !stringsAsFactors, na.strings = "NA", colClasses = NA, nrows = -1, skip = 0, check.names = TRUE, fill = !blank.lines.skip, strip.white = FALSE, blank.lines.skip = TRUE, comment.char = "#", allowEscapes = FALSE, flush = FALSE, stringsAsFactors = default.stringsAsFactors(), fileEncoding = "", encoding = "unknown", text, skipNul = FALSE) Import Table format data You must specify If not specified, applied this default value Optional argument(s) 引数 "file" がありませんし、省略時既定値もありません If not,
?read.table Usage read.table(file, header = FALSE, sep = "", quote
= "∖", dec = ".", numerals = c("allow.loss", "warn.loss", "no.loss"), row.names, col.names, as.is = !stringsAsFactors, na.strings = "NA", colClasses = NA, nrows = -1, skip = 0, check.names = TRUE, fill = !blank.lines.skip, strip.white = FALSE, blank.lines.skip = TRUE, comment.char = "#", allowEscapes = FALSE, flush = FALSE, stringsAsFactors = default.stringsAsFactors(), fileEncoding = "", encoding = "unknown", text, skipNul = FALSE) Import Table format data
?read.table Usage read.table(file, skip = 0, header = FALSE, nrows
= -1, row.names, fileEncoding = "") Import Table format data
cf. R-Tips: 40. ファイルからデータを読み込む http://cse.naro.affrc.go.jp/takezawa/r-tips/r/40.html > x sex height weight
1 F 158 51 2 F 162 55 3 M 177 72 4 M 173 57 5 M 166 64 Import Table format data
x <- read.table( "import.txt", skip = 1, header = TRUE,
row.names = "data", nrows = 5, fileEncoding = "UTF8") cf. R-Tips: 40. ファイルからデータを読み込む http://cse.naro.affrc.go.jp/takezawa/r-tips/r/40.html Import Table format data
x <- read.table( "import.txt", skip = 1, header = TRUE,
row.names = "data", nrows = 5, fileEncoding = "UTF8") cf. R-Tips: 40. ファイルからデータを読み込む http://cse.naro.affrc.go.jp/takezawa/r-tips/r/40.html Import Table format data
x <- read.table( "import.txt", skip = 1, header = TRUE,
row.names = "data", nrows = 5, fileEncoding = "UTF8") cf. R-Tips: 40. ファイルからデータを読み込む http://cse.naro.affrc.go.jp/takezawa/r-tips/r/40.html Import Table format data
x <- read.table( "import.txt", skip = 1, header = TRUE,
row.names = "data", nrows = 5, fileEncoding = "UTF8") cf. R-Tips: 40. ファイルからデータを読み込む http://cse.naro.affrc.go.jp/takezawa/r-tips/r/40.html Import Table format data
x <- read.table( "import.txt", skip = 1, header = TRUE,
row.names = "data", nrows = 5, fileEncoding = "UTF8") cf. R-Tips: 40. ファイルからデータを読み込む http://cse.naro.affrc.go.jp/takezawa/r-tips/r/40.html Import Table format data # 先頭_行は読み込まない # カラム名の行が存在する # 行名のカラム名/番号を指定 # データ部分の行数
x <- read.table( "import.txt", skip = 1, header = TRUE,
row.names = "data", nrows = 5, fileEncoding = "UTF8") cf. R-Tips: 40. ファイルからデータを読み込む http://cse.naro.affrc.go.jp/takezawa/r-tips/r/40.html Import Table format data # 先頭_行は読み込まない # カラム名の行が存在する # 行名のカラム名/番号を指定 # データ部分の行数
第67回 初心者セッション1 @y__mattu https://github.com/ymattu/TokyoR67 Import Table format data
x <- read.table("import.csv", header = T, sep = "," quote
= "∖", dec = ".") x <- read.csv("import.csv") Import Table format data Wrap
x <- read.table(file) Import Table format data you Wrappers
x <- read.table(file) Import Table format data you
Package … {utils} Package {base} Package
Package Package Package Package Package Package Package Package Package Package
Package Package Package Package Package
packages you
cf. http://rpkg.gepuro.net/ cf. https://cran.r-project.org/web/packages/ at 2018.02.20
Package Default pkgs Package Package Package CRAN Guithub Package Package
Package Package Package Package Package Package install.packages githubinstall
utils::read.table(file) Import Table format data Default installed pkg (optional) Function
data.table::fread(file) Install REQUIRED
Import Table format data List of installed packages
Import Table format data data.table::fread (file) Installation (from CRAN) install.packages("data.table")
Usage library("data.table") fread (file) or
Import Table format data library("data.table") > sessionInfo() ... other attached
packages: [1] data.table_1.10.4-3 Global environment # Attach {data.table}
Import Table format data library("data.table") fread (file, data.table = FALSE)
Fast!!! Flexible!!! Need installation Should specify: data.table =FALSE Automatic!!! Simple!!!
write.table(x, "export.txt") write.csv(x, "export.csv") object file path Export Table format
data Wrapper
Input Output Today’s talk ? ? Table data Image data
Other formats Summary Introduction
Image data Table data Image data Other formats Summary Introduction
Export image data ?
Export image data Use Graphic Device ready graphic device close
graphic device draw graph(s) plotting functions ・High-level ・Low-level ・Interactive Basic Graphics in R http://bcb.dfci.harvard.edu/~aedin/courses/BiocDec2011/2.Plotting.pdf
Export image data Use Graphic Device ready close draw png("hoge.png")
plot(iris) dev.off() High-level plotting function
hogehoge ~/Documents/R hogehoge.Rproj hoge.png New!!
Export image data Graphic Devices in {grDevices} > help(device) pdf
png jpeg tiff bmp ... Write PDF graphics commands to a file PNG bitmap device JPEG bitmap device TIFF bitmap device BMP bitmap device
Export image data Graphic Devices in {grDevices} pdf png jpeg
tiff bmp svg cairo_pdf cairo_ps Scalable vector graphics Cairographics based PDF Cairographics based PostScript
Export plot ready graphic device close graphic device draw graph(s)
Image data processing Import & Export image x <- read***( ) write***(x, ) processing
png::readPNG Import image data tiff::readTIFF jpeg::readJPEG bmp::read.bmp
png::readPNG Import image data tiff::readTIFF jpeg::readJPEG bmp::read.bmp
png::readPNG Import image data tiff::readTIFF jpeg::readJPEG bmp::read.bmp EBImage::readImage magick::image_read imager::load.image
OpenImageR::readImage biOps::readJpeg
png::readPNG Import image data tiff::readTIFF jpeg::readJPEG bmp::read.bmp EBImage::readImage magick::image_read imager::load.image
OpenImageR::readImage biOps::readJpeg
Import image data EBImage::readImage magick::image_read Export image data EBImage::writeImage #
not CRAN pkg magick::image_write # low googlability
Import image data EBImage::readImage magick::image_read Export image data EBImage::writeImage #
not CRAN pkg magick::image_write # low googlability
None
None
None
Salvador Dalí 1904-1989 profile of time wikipedia
http://seekr.jp/
None
None
None
Input Output Today’s talk ? ? Table data Image data
Other formats Summary Introduction
Table data Image data Other formats Other formats Summary Introduction
.xls or .xlsx readxl::read_excel( file, GJMFQBUI sheet = 1) TIFFUOBNFPS/P
.json jsonlite::read_json(file) jsonlite::write_json(file) Wrap from_json(file, simplifyVector =T) Wrap to_json(obj, file,
simplifyVector =T)
tuneR::readMP3(file) .wav or .mp3 tuneR::readWave(file) tuneR::writeWave(object, file)
.sas or .dta or .sav SAS Stata SPSS haven::read_sas("hoge.sas7bdat") haven::read_dta("hoge.dta")
haven::read_sav("hoge.sav")
Summary Table data Image data Other formats Summary Introduction
Input Output Do NOT start from here Whatever … 1
2 3
Data Import / Export ? ?
packages you
Data Import / Export ? ? {readxl} {data.table} {EBImage} {magick}
{jsonlite} {tuneR} {haven} {grDevices} {utils} packages
~/Documents/R project1 project2 project3 project4
Before After BeginneR Session BeginneR BeginneR ?
BeginneR Advanced Hoxo_m If I have seen further it is
by standing on the sholders of Giants. -- Sir Isaac Newton, 1676
Enjoy!! KMT˝
Bar DraDra KMT˝