Upgrade to Pro — share decks privately, control downloads, hide ads and more …

BeginnerSession1_69th_TokyoR

 BeginnerSession1_69th_TokyoR

第69回TokyoR初心者セッション1の資料です。

kilometer

April 21, 2018
Tweet

More Decks by kilometer

Other Decks in Technology

Transcript

  1. BeginneR Advanced Hoxo_m If I have seen further it is

    by standing on the sholders of Giants. -- Sir Isaac Newton, 1676
  2. Input Output Today’s talk ? ? Table data Image data

    Other formats Introduction Summary
  3. Input Output Today’s talk ? ? Table data Image data

    Other formats Summary Introduction
  4. ~/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
  5. 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
  6. prj ~/Documents/R prj.Rproj import.txt Default working directory (project root) Target!!

    x <- read.table("import.txt") can use relative path without setwd
  7. ?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
  8. ?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,
  9. ?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
  10. ?read.table Usage read.table(file, skip = 0, header = FALSE, nrows

    = -1, row.names, fileEncoding = "") Import Table format data
  11. 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
  12. 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
  13. 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
  14. 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
  15. 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 # 先頭_行は読み込まない # カラム名の行が存在する # 行名のカラム名/番号を指定 # データ部分の行数
  16. 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 # 先頭_行は読み込まない # カラム名の行が存在する # 行名のカラム名/番号を指定 # データ部分の行数
  17. x <- read.table("import.csv", header = T, sep = "," quote

    = "∖", dec = ".") x <- read.csv("import.csv") Import Table format data Wrap
  18. Package Default pkgs Package Package Package CRAN Guithub Package Package

    Package Package Package Package Package Package install.packages githubinstall
  19. Import Table format data library("data.table") > sessionInfo() ... other attached

    packages: [1] data.table_1.10.4-3 Global environment # Attach {data.table}
  20. Import Table format data library("data.table") fread (file, data.table = FALSE)

    Fast!!! Flexible!!! Need installation Should specify: data.table =FALSE Automatic!!! Simple!!!
  21. Input Output Today’s talk ? ? Table data Image data

    Other formats Summary Introduction
  22. 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
  23. Export image data Use Graphic Device ready close draw png("hoge.png")

    plot(iris) dev.off() High-level plotting function
  24. 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
  25. 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
  26. Export plot ready graphic device close graphic device draw graph(s)

    Image data processing Import & Export image x <- read***( ) write***(x, ) processing
  27. Input Output Today’s talk ? ? Table data Image data

    Other formats Summary Introduction
  28. Data Import / Export ? ? {readxl} {data.table} {EBImage} {magick}

    {jsonlite} {tuneR} {haven} {grDevices} {utils} packages
  29. BeginneR Advanced Hoxo_m If I have seen further it is

    by standing on the sholders of Giants. -- Sir Isaac Newton, 1676