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
490
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
830
TokyoR109.pdf
kilometer
1
440
TokyoR#108_NestedDataHandling
kilometer
0
750
TokyoR#107_R_GeoData
kilometer
0
390
SappoRo.R_roundrobin
kilometer
0
120
TokyoR#104_DataProcessing
kilometer
1
660
TokyoR#103_DataProcessing
kilometer
0
850
TokyoR#102_RMarkdown
kilometer
1
610
TokyoR#101_RegressionAnalysis
kilometer
0
350
Other Decks in Technology
See All in Technology
Oracle Cloud Infrastructureデータベース・クラウド:各バージョンのサポート期間
oracle4engineer
PRO
28
12k
適材適所の技術選定 〜GraphQL・REST API・tRPC〜 / Optimal Technology Selection
kakehashi
1
400
SSMRunbook作成の勘所_20241120
koichiotomo
2
130
The Role of Developer Relations in AI Product Success.
giftojabu1
0
120
複雑なState管理からの脱却
sansantech
PRO
1
140
データプロダクトの定義からはじめる、データコントラクト駆動なデータ基盤
chanyou0311
2
310
Exadata Database Service on Dedicated Infrastructure(ExaDB-D) UI スクリーン・キャプチャ集
oracle4engineer
PRO
2
3.2k
Terraform未経験の御様に対してどの ように導⼊を進めていったか
tkikuchi
2
430
インフラとバックエンドとフロントエンドをくまなく調べて遅いアプリを早くした件
tubone24
1
430
Amazon Personalizeのレコメンドシステム構築、実際何するの?〜大体10分で具体的なイメージをつかむ〜
kniino
1
100
Lexical Analysis
shigashiyama
1
150
【令和最新版】AWS Direct Connectと愉快なGWたちのおさらい
minorun365
PRO
5
750
Featured
See All Featured
Building Better People: How to give real-time feedback that sticks.
wjessup
364
19k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
31
2.7k
Designing Experiences People Love
moore
138
23k
Six Lessons from altMBA
skipperchong
27
3.5k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
159
15k
Designing the Hi-DPI Web
ddemaree
280
34k
Docker and Python
trallard
40
3.1k
[RailsConf 2023] Rails as a piece of cake
palkan
52
4.9k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
47
2.1k
Scaling GitHub
holman
458
140k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
42
9.2k
Building an army of robots
kneath
302
43k
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˝