Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
BeginnerSession1_69th_TokyoR
Search
kilometer
April 21, 2018
Technology
1
510
BeginnerSession1_69th_TokyoR
第69回TokyoR初心者セッション1の資料です。
kilometer
April 21, 2018
Tweet
Share
More Decks by kilometer
See All by kilometer
TokyoR#111_ANOVA
kilometer
2
920
TokyoR109.pdf
kilometer
1
510
TokyoR#108_NestedDataHandling
kilometer
0
880
TokyoR#107_R_GeoData
kilometer
0
470
SappoRo.R_roundrobin
kilometer
0
160
TokyoR#104_DataProcessing
kilometer
1
730
TokyoR#103_DataProcessing
kilometer
0
930
TokyoR#102_RMarkdown
kilometer
1
690
TokyoR#101_RegressionAnalysis
kilometer
0
520
Other Decks in Technology
See All in Technology
ラスベガスの歩き方 2025年版(re:Invent 事前勉強会)
junjikoide
0
790
datadog-incident-management-intro
tetsuya28
0
110
AWSが好きすぎて、41歳でエンジニアになり、AAIを経由してAWSパートナー企業に入った話
yama3133
2
220
.NET 10のBlazorの期待の新機能
htkym
0
170
今から間に合う re:Invent 準備グッズと現地の地図、その他ラスベガスを周る際の Tips/reinvent-preparation-guide
emiki
1
220
累計5000万DLサービスの裏側 – LINEマンガのKotlinで挑む大規模 Server-side ETLの最適化
ldf_tech
0
120
アノテーション作業書作成のGood Practice
cierpa0905
PRO
1
350
Oracle Database@Google Cloud:サービス概要のご紹介
oracle4engineer
PRO
0
410
Raycast AI APIを使ってちょっと便利なAI拡張機能を作ってみた
kawamataryo
0
230
様々なファイルシステム
sat
PRO
0
280
AWS re:Invent 2025事前勉強会資料 / AWS re:Invent 2025 pre study meetup
kinunori
0
990
JAWS UG AI/ML #32 Amazon BedrockモデルのライフサイクルとEOL対応/How Amazon Bedrock Model Lifecycle Works
quiver
1
570
Featured
See All Featured
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
4.1k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
116
20k
Principles of Awesome APIs and How to Build Them.
keavy
127
17k
Designing for humans not robots
tammielis
254
26k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
34
2.3k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
140
34k
KATA
mclloyd
PRO
32
15k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
10
900
RailsConf 2023
tenderlove
30
1.3k
StorybookのUI Testing Handbookを読んだ
zakiyama
31
6.3k
Agile that works and the tools we love
rasmusluckow
331
21k
Large-scale JavaScript Application Architecture
addyosmani
514
110k
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˝