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
940
TokyoR109.pdf
kilometer
1
520
TokyoR#108_NestedDataHandling
kilometer
0
890
TokyoR#107_R_GeoData
kilometer
0
480
SappoRo.R_roundrobin
kilometer
0
170
TokyoR#104_DataProcessing
kilometer
1
740
TokyoR#103_DataProcessing
kilometer
0
960
TokyoR#102_RMarkdown
kilometer
1
700
TokyoR#101_RegressionAnalysis
kilometer
0
530
Other Decks in Technology
See All in Technology
20251219 OpenIDファウンデーション・ジャパン紹介 / OpenID Foundation Japan Intro
oidfj
0
520
通勤手当申請チェックエージェント開発のリアル
whisaiyo
3
490
20251203_AIxIoTビジネス共創ラボ_第4回勉強会_BP山崎.pdf
iotcomjpadmin
0
140
20251218_AIを活用した開発生産性向上の全社的な取り組みの進め方について / How to proceed with company-wide initiatives to improve development productivity using AI
yayoi_dd
0
720
Authlete で実装する MCP OAuth 認可サーバー #CIMD の実装を添えて
watahani
0
200
ペアーズにおけるAIエージェント 基盤とText to SQLツールの紹介
hisamouna
2
1.7k
AI with TiDD
shiraji
1
300
Claude Codeを使った情報整理術
knishioka
12
9.2k
Identity Management for Agentic AI 解説
fujie
0
490
Microsoft Agent Frameworkの可観測性
tomokusaba
1
120
Oracle Database@AWS:サービス概要のご紹介
oracle4engineer
PRO
2
420
[Data & AI Summit '25 Fall] AIでデータ活用を進化させる!Google Cloudで作るデータ活用の未来
kirimaru
0
4k
Featured
See All Featured
Being A Developer After 40
akosma
91
590k
Discover your Explorer Soul
emna__ayadi
2
1k
Accessibility Awareness
sabderemane
0
24
Technical Leadership for Architectural Decision Making
baasie
0
190
Rails Girls Zürich Keynote
gr2m
95
14k
Building an army of robots
kneath
306
46k
Applied NLP in the Age of Generative AI
inesmontani
PRO
3
2k
Exploring the relationship between traditional SERPs and Gen AI search
raygrieselhuber
PRO
2
3.5k
Statistics for Hackers
jakevdp
799
230k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
122
21k
職位にかかわらず全員がリーダーシップを発揮するチーム作り / Building a team where everyone can demonstrate leadership regardless of position
madoxten
51
47k
Measuring Dark Social's Impact On Conversion and Attribution
stephenakadiri
0
97
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˝