SlideShare une entreprise Scribd logo
1  sur  49
Télécharger pour lire hors ligne
R
    Tsukuba.R #9 (2011/11/12)
                    @a_bicky
• Takeshi Arabiki                         1

    ‣ Twitter: @a_bicky
    ‣        : id:a_bicky

•
                              R

•
                http://d.hatena.ne.jp/a_bicky/
• Takeshi Arabiki                          1

    ‣ Twitter: @a_bicky
    ‣        : id:a_bicky

•
                              R        SciPy



•
                http://d.hatena.ne.jp/a_bicky/
Osaka.R #4                                     Tokyo.R #16




http://www.slideshare.net/abicky/twitterr   http://www.slideshare.net/abicky/r-9034336
•
•             R                    8   ,9

•
•
•
•

    http://www.amazon.co.jp/gp/product/4431712186
reshape2
> install.packages("reshape2")
> library(reshape2)
> head(tips) #
  total_bill tip     sex smoker   day     time size
1      16.99 1.01 Female     No   Sun   Dinner    2
2      10.34 1.66   Male     No   Sun   Dinner    3
3      21.01 3.50   Male     No   Sun   Dinner    3
4      23.68 3.31   Male     No   Sun   Dinner    2
5      24.59 3.61 Female     No   Sun   Dinner    4
6      25.29 4.71   Male     No   Sun   Dinner    4
tips

  total_bill:
  tip:
  sex:          Male, Female
  smoker:                             Yes, No
  day:          Thur, Fri, Sat, Sun
  time:             Lunch, Dinner
  size:
•
•
    •   subset
    •   cbind, [, $, [[
    •   transform, within
•
    •   subset
    •   cbind, [, $, [[
    •   transform, within
•
•                           order
•
> class(tips)
[1] "data.frame"
> mode(tips)     # data.frame list
[1] "list"
> head(tips[["total_bill"]])    # list
[1] 16.99 10.34 21.01 23.68 24.59 25.29
> head(tips$total_bill)         #
[1] 16.99 10.34 21.01 23.68 24.59 25.29
> head(tips["total_bill"])      #       data.frame
  total_bill
1      16.99
2      10.34
3      21.01
4      23.68
5      24.59
6      25.29
> head(tips[c("total_bill", "tip")]) #
  total_bill tip
1      16.99 1.01
2      10.34 1.66
3      21.01 3.50
4      23.68 3.31
5      24.59 3.61
6      25.29 4.71
> head(tips[[c("total_bill", "tip")]]) #
Error in .subset2(x, i, exact = exact) : subscript out of bounds
> tips[[c(1, 2)]] # tips[[1]][[2]]
[1] 10.34
> tips[1:2, 1:2]    #
  total_bill tip
1      16.99 1.01
2      10.34 1.66
> tips[1:2, c("total_bill", "tip")]   #
  total_bill tip
1      16.99 1.01
2      10.34 1.66
> head(tips[-(1:2), -(1:2)])    #
     sex smoker day   time size
3   Male     No Sun Dinner    3
4   Male     No Sun Dinner    2
5 Female     No Sun Dinner    4
6   Male     No Sun Dinner    4
7   Male     No Sun Dinner    2
8   Male     No Sun Dinner    4
subset


> args(subset.data.frame)
function (x, subset, select, drop = FALSE, ...)
NULL
> (tips.vip <- subset(tips, total_bill > 30 & size == 2))
     total_bill tip sex smoker day     time size
84        32.68 5.00 Male   Yes Thur Lunch      2
174       31.85 3.18 Male   Yes Sun Dinner      2
176       32.90 3.11 Male   Yes Sun Dinner      2
180       34.63 3.55 Male   Yes Sun Dinner      2
185       40.55 3.00 Male   Yes Sun Dinner      2
238       32.83 1.17 Male   Yes Sat Dinner      2
> levels(tips.vip$smoker) #
[1] "No" "Yes"
> levels(droplevels(tips.vip)$smoker)   #
[1] "Yes"
cbind, [, $, [[


> head(cbind(tips, type = ifelse(tips$tip < 2, "         ", "   ")), 3)
  total_bill tip     sex smoker day   time size     type
1      16.99 1.01 Female     No Sun Dinner    2
2      10.34 1.66   Male     No Sun Dinner      3
3      21.01 3.50   Male     No Sun Dinner      3
> tips$type <- ifelse(tips$tip < 2, "    ", "       ")
> head(tips, 3)
  total_bill tip     sex smoker day   time size     type
1      16.99 1.01 Female     No Sun Dinner    2
2      10.34 1.66   Male     No Sun Dinner      3
3      21.01 3.50   Male     No Sun Dinner      3
> data(tips)   #
transform, within

> args(transform.data.frame)
function (`_data`, ...)
NULL
> head(transform(tips, type = ifelse(tips$tip < 2, "         ", "   ")), 3)
  total_bill tip     sex smoker day   time size       type
1      16.99 1.01 Female     No Sun Dinner    2
2      10.34 1.66   Male     No Sun Dinner        3
3      21.01 3.50   Male     No Sun Dinner        3
> args(within.data.frame)
function (data, expr, ...)
NULL
> head(within(tips, { type <- c() # within
+                     type[tip < 2] <- "      "
+                     type[tip >= 2] <- "    " }), 3)
  total_bill tip     sex smoker day   time size       type
1      16.99 1.01 Female     No Sun Dinner    2
2      10.34 1.66   Male     No Sun Dinner        3
3      21.01 3.50   Male     No Sun Dinner        3
subset

> # subset
> head(subset(tips, select   = c(tip, sex, smoker)), 1)
   tip    sex smoker
1 1.01 Female     No
> head(subset(tips, select   = 2:4), 1)
   tip    sex smoker
1 1.01 Female     No
> head(subset(tips, select   = -c(total_bill, size, time, day)), 1)
   tip    sex smoker
1 1.01 Female     No
> head(subset(tips, select   = -c(1, 5:7)), 1)
   tip    sex smoker
1 1.01 Female     No
> head(subset(tips, select   = c(tip:smoker)), 1)
   tip    sex smoker
1 1.01 Female     No
> head(subset(tips, select   = -c(total_bill, day:size)), 1)
   tip    sex smoker
1 1.01 Female     No
[, $, [[

> # NULL
> tips$size <- NULL
> head(tips, 3)
  total_bill tip      sex smoker day   time
1      16.99 1.01 Female      No Sun Dinner
2      10.34 1.66    Male     No Sun Dinner
3      21.01 3.50    Male     No Sun Dinner
> tips[["time"]] <- NULL
> head(tips, 3)
  total_bill tip      sex smoker day
1      16.99 1.01 Female      No Sun
2      10.34 1.66    Male     No Sun
3      21.01 3.50    Male     No Sun
> tips["day"] <- NULL; tips[1] <- NULL
> head(tips, 3)
   tip    sex smoker
1 1.01 Female     No
2 1.66   Male     No
3 3.50   Male     No
> data(tips)
transform, within


> # NULL
> head(transform(tips, total_bill = NULL, size = NULL, time = NULL, day =
NULL), 3)
   tip     sex smoker
1 1.01 Female      No
2 1.66    Male     No
3 3.50    Male     No
> # rm
> head(within(tips, rm(total_bill, size, time, day)), 3)
   tip     sex smoker
1 1.01 Female      No
2 1.66    Male     No
3 3.50    Male     No
> head(transform(tips, tip = 10), 3)
  total_bill tip    sex smoker day   time size
1      16.99 10 Female      No Sun Dinner    2
2      10.34 10    Male     No Sun Dinner    3
3      21.01 10    Male     No Sun Dinner    3
> head(within(tips, tip <- 10), 3)
  total_bill tip    sex smoker day   time size
1      16.99 10 Female      No Sun Dinner    2
2      10.34 10    Male     No Sun Dinner    3
3      21.01 10    Male     No Sun Dinner    3
> tips$tip <- 10
> head(tips, 3)
  total_bill tip    sex smoker day   time size
1      16.99 10 Female      No Sun Dinner    2
2      10.34 10    Male     No Sun Dinner    3
3      21.01 10    Male     No Sun Dinner    3
> data(tips)
order


> head(tips[order(tips$sex), ], 4) #
    total_bill tip      sex smoker day    time size
1        16.99 1.01 Female      No Sun Dinner     2
5        24.59 3.61 Female      No Sun Dinner     4
12       35.26 5.00 Female      No Sun Dinner     4
15       14.83 3.02 Female      No Sun Dinner     2
> head(tips[order(tips$sex, decreasing = TRUE), ], 4)   #
   total_bill tip sex smoker day       time size
2       10.34 1.66 Male      No Sun Dinner     3
3       21.01 3.50 Male      No Sun Dinner     3
4       23.68 3.31 Male      No Sun Dinner     2
6       25.29 4.71 Male      No Sun Dinner     4
> head(tips[order(tips$sex, tips$tip), ], 4) #
     total_bill tip      sex smoker day     time size
68         3.07 1.00 Female     Yes Sat Dinner      1
93         5.75 1.00 Female     Yes Fri Dinner      2
112        7.25 1.00 Female      No Sat Dinner      1
1         16.99 1.01 Female      No Sun Dinner      2
data.frame


> (tip <- data.frame(date = sample(seq(as.Date("2011-11-09"), by = "day", len = 4)),
+                   total_bill = sample(1:4 * 10),
+                   tip = sample(1:4)))
        date total_bill tip
1 2011-11-10         30   4
2 2011-11-12         40   2
3 2011-11-11         10   1
4 2011-11-09         20   3
> #
> tip <- tip[order(tip$date), ]
> transform(tip, total_bill = cumsum(total_bill), tip = cumsum(tip))
        date total_bill tip
4 2011-11-09         20   3
1 2011-11-10         50   7
3 2011-11-11         60   8
2 2011-11-12        100 10
> head(tips[c("tip", "total_bill", "sex", "size", "time", "day", "smoker")])
  tip total_bill    sex size   time day smoker
1 10       16.99 Female    2 Dinner Sun     No
2 10       10.34   Male    3 Dinner Sun     No
3 10       21.01   Male    3 Dinner Sun     No
4 10       23.68   Male    2 Dinner Sun     No
5 10       24.59 Female    4 Dinner Sun     No
6 10       25.29   Male    4 Dinner Sun     No
•
•   table
•   xtabs
•           aggregate
•           by
> args(colSums)
function (x, na.rm = FALSE, dims = 1L)
NULL
> colSums(subset(tips, select = c(total_bill, tip)), na.rm = TRUE)
total_bill         tip
   4827.77      731.58
> args(colMeans)
function (x, na.rm = FALSE, dims = 1L)
NULL
> colMeans(subset(tips, select = c(total_bill, tip)), na.rm = TRUE)
total_bill         tip
 19.785943   2.998279
> # apply                colSums
> apply(subset(tips, select = c(total_bill, tip)), 2, sum, na.rm = TRUE)
total_bill         tip
   4827.77      731.58
table

> args(table)
function (..., exclude = if    (useNA == "no") c(NA, NaN), useNA = c("no",
     "ifany", "always"), dnn   = list.names(...), deparse.level = 1)
NULL
> table(subset(tips, select    = c(sex, smoker)))
         smoker
sex       No Yes
  Female 54 33
  Male    97 60
>    # 4
> table(subset(tips, select    = c(sex, smoker, day, size)))
, , day = Fri, size = 1

        smoker
sex      No Yes
  Female 0     0
  Male    0    1
table

> args(addmargins)
function (A, margin = seq_along(dim(A)), FUN = sum, quiet = FALSE)
NULL
> #
> addmargins(table(subset(tips, select = c(sex, smoker))))
        smoker
sex       No Yes Sum
  Female 54 33 87
  Male    97 60 157
  Sum    151 93 244
> #
> args(prop.table)
function (x, margin = NULL)
NULL
> prop.table(table(subset(tips, select = c(sex, smoker))))
        smoker
sex             No       Yes
  Female 0.2213115 0.1352459
  Male   0.3975410 0.2459016
xtabs

> args(xtabs)
function (formula = ~., data = parent.frame(), subset, sparse = FALSE,
     na.action, exclude = c(NA, NaN), drop.unused.levels = FALSE)
NULL
> #
> xtabs(~ sex + smoker, tips)
         smoker
sex       No Yes
  Female 54 33
  Male    97 60
> #
> xtabs(cbind(total_bill, tip) ~ sex + smoker, tips)
, , = total_bill

        smoker
sex           No     Yes
  Female 977.68 593.27
  Male   1919.75 1337.07
aggregate

> args(aggregate.data.frame)
function (x, by, FUN, ..., simplify = TRUE)
NULL
> # FUN              1
> aggregate(tips[c("total_bill", "tip")], tips[c("sex", "day")], sum)
      sex day total_bill     tip
1 Female Fri      127.31 25.03
2    Male Fri     198.57 26.93
3 Female Sat      551.05 78.45
4    Male Sat    1227.35 181.95
5 Female Sun      357.70 60.61
6    Male Sun    1269.46 186.78
7 Female Thur     534.89 82.42
8    Male Thur    561.44 89.41
> # formula
> aggregate(cbind(total_bill, tip) ~ sex + day, tips, sum)
      sex day total_bill     tip
1 Female Fri      127.31 25.03
by

> args(by)
function (data, INDICES, FUN, ..., simplify = TRUE)
NULL
> # aggregate          FUN               OK
> (ret <- by(tips[c("total_bill", "tip")], tips[c("sex", "day")], range))
sex: Female
day: Fri
[1] 1.00 22.75
------------------------------------------------------------
sex: Male
day: Fri
[1] 1.50 40.17


> # data.frame
> cbind(expand.grid(dimnames(ret)), do.call(rbind, ret))
     sex day     1     2
1 Female Fri 1.00 22.75
2   Male Fri 1.50 40.17
•           reshape
•   merge
reshape

> args(reshape)
function (data, varying = NULL, v.names = NULL, timevar = "time",
     idvar = "id", ids = 1L:NROW(data), times = seq_along(varying[[1L]]),
     drop = NULL, direction, new.row.names = NULL, sep = ".",
     split = if (sep == "") {
          list(regexp = "[A-Za-z][0-9]", include = TRUE)
     } else {
          list(regexp = sep, include = FALSE, fixed = TRUE)
     })
NULL
> head(reshape(tips, idvar = c("sex", "smoker", "time", "size"),
+                timevar = "day", drop = "total_bill", direction = "wide"))
        sex smoker   time size tip.Sun tip.Sat tip.Thur tip.Fri
1 Female        No Dinner    2    1.01    2.75        3     3.25
2     Male      No Dinner    3    1.66    3.35       NA       NA
4     Male      No Dinner    2    3.31    4.08       NA     3.50
5 Female        No Dinner    4    3.61    2.45       NA       NA
6     Male      No Dinner    4    4.71    7.58       NA       NA
17 Female       No Dinner    3    1.67    3.07       NA       NA
reshape


> # idvar    timevar
> (a <- data.frame(a = c(1:3, 1), b = c(1:3, 1), c = 1:4))
  a b c
1 1 1 1
2 2 2 2
3 3 3 3
4 1 1 4
> reshape(a, idvar = "a", timevar = "b", direction = "wide")
  a c.1 c.2 c.3
1 1   1 NA NA
2 2 NA    2 NA
3 3 NA NA     3
merge

> #
> (user.type <- data.frame(sex = rep(c("Male", "Female"), each = 2),
+                           smoker = c("Yes", "No"),
+                           type = LETTERS[1:4]))
      sex smoker type
1    Male    Yes    A
2    Male     No    B
3 Female     Yes    C
4 Female      No    D
> args(merge.data.frame)
function (x, y, by = intersect(names(x), names(y)), by.x = by,
     by.y = by, all = FALSE, all.x = all, all.y = all, sort = TRUE,
     suffixes = c(".x", ".y"), incomparables = NULL, ...)
NULL
> merge(tips, user.type, by = c("sex", "smoker"), sort = FALSE)[54:55, ]
       sex smoker total_bill tip day     time size type
54 Female      No      10.65 1.50 Thur Lunch      2   D
55    Male     No      10.27 1.71 Sun Dinner      2   B
•
•   R
•   reshape2
•   melt
•   cast
•
Excel
R

> acast(melt(tips, id.var = c("sex", "smoker", "day"), measure.var = "tip"),
+        sex + smoker ~ day, sum, margins = TRUE)
                Fri    Sat    Sun   Thur (all)
Female_No      6.25 35.42 46.61 61.49 149.77
Female_Yes    18.78 43.03 14.00 18.93 94.74
Female_(all) 25.03 78.45 60.61 80.42 244.51
Male_No        5.00 104.21 133.96 58.83 302.00
Male_Yes      21.93 77.74 52.82 30.58 183.07
Male_(all)    26.93 181.95 186.78 89.41 485.07
(all)_(all) 51.96 260.40 247.39 169.83 729.58




                                                       reshape2
reshape2

  melt                                    cast

 melt
 id
> head(tipsm <- melt(tips, measure.vars = c("total_bill", "tip")))
     sex smoker day    time size   variable value
1 Female     No Sun Dinner     2 total_bill 16.99
2   Male     No Sun Dinner     3 total_bill 10.34
3   Male     No Sun Dinner     3 total_bill 21.01
4   Male     No Sun Dinner     2 total_bill 23.68
5 Female     No Sun Dinner     4 total_bill 24.59
6   Male     No Sun Dinner     4 total_bill 25.29
> levels(tipsm$variable)
[1] "total_bill" "tip"
melt
> args(melt.data.frame)
function (data, id.vars, measure.vars, variable_name = "variable",
     na.rm = !preserve.na, preserve.na = TRUE, ...)
NULL
> #                  factor     id
> head(melt(tips), 1)
Using sex, smoker, day, time as id variables
      sex smoker day   time   variable value
1 Female      No Sun Dinner total_bill 16.99
> # id     measure
> head(melt(tips, id.vars = c("sex", "smoker", "day", "time", "size")), 1)
      sex smoker day   time size   variable value
1 Female      No Sun Dinner    2 total_bill 16.99
> # id      measure
> head(melt(tips, id.vars = c("sex", "smoker", "day", "time", "size"),
+                  measure.vars = "tip"), 1)
      sex smoker day   time size variable value
1 Female      No Sun Dinner    2      tip 1.01
cast
formula                                    fun.aggregate
 > args(acast) #         array                       acast
 function (data, formula, fun.aggregate    = NULL, ..., margins = NULL,
      subset = NULL, fill = NULL, drop =   TRUE, value_var = guess_value(data))
 NULL
 > args(dcast) #         data.frame                          dcast
 function (data, formula, fun.aggregate    = NULL, ..., margins = NULL,
      subset = NULL, fill = NULL, drop =   TRUE, value_var = guess_value(data))
 NULL


     formula
 ...
 .
 acast     hoge ~ fuga ~ piyo
 ※dcast     1                              hoge ~ fuga + piyo
> tipsm <- melt(tips, measure.vars = c("total_bill", "tip"))
> acast(tipsm, sex ~ smoker, length)
         No Yes
Female 108 64
Male    194 120
> #
> acast(tipsm, smoker ~ sex, length)
     Female Male
No      108 194
Yes      64 120
> #
> acast(tipsm, sex ~ smoker, length, margins = TRUE)
         No Yes (all)
Female 108 64     172
Male    194 120   314
(all) 302 184     486
> # size
> acast(tipsm, smoker ~ sex + size, length)
    Female_1 Female_2 Female_3 Female_4 Female_5 Female_6 Male_1 Male_2
Male_3
No         4       66       18       14        2        4      0    114
34
Yes        2       48       10        4        0        0      2     82
14
    Male_4 Male_5 Male_6
No      38      4      4
Yes     18      4      0
> # 3
> acast(tipsm, smoker ~ sex ~ size, length)
, , 1

    Female Male
No       4    0
Yes      2    2
> #             sum
> acast(tipsm, sex ~ day, sum)
           Fri   Sat      Sun    Thur
Female 152.34 629.5 418.31 617.31 total_bill       tip
Male   225.50 1409.3 1456.24 650.85
> # total_bill      tip             sum
> acast(tipsm, sex + variable ~ day, sum)
                      Fri      Sat      Sun  Thur
Female_total_bill 127.31 551.05 357.70 534.89
Female_tip          25.03    78.45    60.61 82.42
Male_total_bill   198.57 1227.35 1269.46 561.44
Male_tip            26.93 181.95 186.78 89.41
> #             tip      sum
> acast(tipsm, sex ~ day, sum, subset = .(variable == "tip"))
         Fri    Sat     Sun Thur
Female 25.03 78.45 60.61 82.42
Male   26.93 181.95 186.78 89.41
reshape2   aggregate table   xtabs
Rデータフレーム自由自在

Contenu connexe

Tendances

{tidygraph}と{ggraph}によるモダンなネットワーク分析
{tidygraph}と{ggraph}によるモダンなネットワーク分析{tidygraph}と{ggraph}によるモダンなネットワーク分析
{tidygraph}と{ggraph}によるモダンなネットワーク分析Takashi Kitano
 
Tokyo r12 - R言語による回帰分析入門
Tokyo r12 - R言語による回帰分析入門Tokyo r12 - R言語による回帰分析入門
Tokyo r12 - R言語による回帰分析入門Yohei Sato
 
R6パッケージの紹介―機能と実装
R6パッケージの紹介―機能と実装R6パッケージの紹介―機能と実装
R6パッケージの紹介―機能と実装__nakamichi__
 
Visual Studio CodeでRを使う
Visual Studio CodeでRを使うVisual Studio CodeでRを使う
Visual Studio CodeでRを使うAtsushi Hayakawa
 
型プロバイダー開発ハンズオン.pptx
型プロバイダー開発ハンズオン.pptx型プロバイダー開発ハンズオン.pptx
型プロバイダー開発ハンズオン.pptxssuserb6e6d5
 
組合せ最適化を体系的に知ってPythonで実行してみよう PyCon 2015
組合せ最適化を体系的に知ってPythonで実行してみよう PyCon 2015組合せ最適化を体系的に知ってPythonで実行してみよう PyCon 2015
組合せ最適化を体系的に知ってPythonで実行してみよう PyCon 2015SaitoTsutomu
 
RとSQLiteで気軽にデータベース作成
RとSQLiteで気軽にデータベース作成RとSQLiteで気軽にデータベース作成
RとSQLiteで気軽にデータベース作成弘毅 露崎
 
Rのオブジェクト
RのオブジェクトRのオブジェクト
RのオブジェクトItoshi Nikaido
 
SappoRoR#11 LT: Exploring the Potential of Survey Tools Using Generative AI
SappoRoR#11 LT: Exploring the Potential of Survey Tools Using Generative AISappoRoR#11 LT: Exploring the Potential of Survey Tools Using Generative AI
SappoRoR#11 LT: Exploring the Potential of Survey Tools Using Generative AIyasuhiro ishida
 
DiagrammeRと仲良くなった話ーグラフィカルモデルのためのDiagrammeR速習ー
DiagrammeRと仲良くなった話ーグラフィカルモデルのためのDiagrammeR速習ーDiagrammeRと仲良くなった話ーグラフィカルモデルのためのDiagrammeR速習ー
DiagrammeRと仲良くなった話ーグラフィカルモデルのためのDiagrammeR速習ーTakashi Yamane
 
データサイエンスワールドからC++を眺めてみる
データサイエンスワールドからC++を眺めてみるデータサイエンスワールドからC++を眺めてみる
データサイエンスワールドからC++を眺めてみるShintaro Fukushima
 
R による文書分類入門
R による文書分類入門R による文書分類入門
R による文書分類入門Takeshi Arabiki
 
[R勉強会][データマイニング] R言語による時系列分析
[R勉強会][データマイニング] R言語による時系列分析[R勉強会][データマイニング] R言語による時系列分析
[R勉強会][データマイニング] R言語による時系列分析Koichi Hamada
 
Tokyo r #37 Rubin's Rule
Tokyo r #37 Rubin's RuleTokyo r #37 Rubin's Rule
Tokyo r #37 Rubin's RuleHiroki Matsui
 
パターン認識 第10章 決定木
パターン認識 第10章 決定木 パターン認識 第10章 決定木
パターン認識 第10章 決定木 Miyoshi Yuya
 
R Markdownによるドキュメント生成と バージョン管理入門
R Markdownによるドキュメント生成と バージョン管理入門R Markdownによるドキュメント生成と バージョン管理入門
R Markdownによるドキュメント生成と バージョン管理入門nocchi_airport
 

Tendances (20)

{tidygraph}と{ggraph}によるモダンなネットワーク分析
{tidygraph}と{ggraph}によるモダンなネットワーク分析{tidygraph}と{ggraph}によるモダンなネットワーク分析
{tidygraph}と{ggraph}によるモダンなネットワーク分析
 
Tokyo r12 - R言語による回帰分析入門
Tokyo r12 - R言語による回帰分析入門Tokyo r12 - R言語による回帰分析入門
Tokyo r12 - R言語による回帰分析入門
 
R6パッケージの紹介―機能と実装
R6パッケージの紹介―機能と実装R6パッケージの紹介―機能と実装
R6パッケージの紹介―機能と実装
 
Rの高速化
Rの高速化Rの高速化
Rの高速化
 
Map
MapMap
Map
 
Visual Studio CodeでRを使う
Visual Studio CodeでRを使うVisual Studio CodeでRを使う
Visual Studio CodeでRを使う
 
型プロバイダー開発ハンズオン.pptx
型プロバイダー開発ハンズオン.pptx型プロバイダー開発ハンズオン.pptx
型プロバイダー開発ハンズオン.pptx
 
組合せ最適化を体系的に知ってPythonで実行してみよう PyCon 2015
組合せ最適化を体系的に知ってPythonで実行してみよう PyCon 2015組合せ最適化を体系的に知ってPythonで実行してみよう PyCon 2015
組合せ最適化を体系的に知ってPythonで実行してみよう PyCon 2015
 
RとSQLiteで気軽にデータベース作成
RとSQLiteで気軽にデータベース作成RとSQLiteで気軽にデータベース作成
RとSQLiteで気軽にデータベース作成
 
Rのオブジェクト
RのオブジェクトRのオブジェクト
Rのオブジェクト
 
SappoRoR#11 LT: Exploring the Potential of Survey Tools Using Generative AI
SappoRoR#11 LT: Exploring the Potential of Survey Tools Using Generative AISappoRoR#11 LT: Exploring the Potential of Survey Tools Using Generative AI
SappoRoR#11 LT: Exploring the Potential of Survey Tools Using Generative AI
 
DiagrammeRと仲良くなった話ーグラフィカルモデルのためのDiagrammeR速習ー
DiagrammeRと仲良くなった話ーグラフィカルモデルのためのDiagrammeR速習ーDiagrammeRと仲良くなった話ーグラフィカルモデルのためのDiagrammeR速習ー
DiagrammeRと仲良くなった話ーグラフィカルモデルのためのDiagrammeR速習ー
 
データサイエンスワールドからC++を眺めてみる
データサイエンスワールドからC++を眺めてみるデータサイエンスワールドからC++を眺めてみる
データサイエンスワールドからC++を眺めてみる
 
R による文書分類入門
R による文書分類入門R による文書分類入門
R による文書分類入門
 
全域木いろいろ
全域木いろいろ全域木いろいろ
全域木いろいろ
 
明日使えないすごいビット演算
明日使えないすごいビット演算明日使えないすごいビット演算
明日使えないすごいビット演算
 
[R勉強会][データマイニング] R言語による時系列分析
[R勉強会][データマイニング] R言語による時系列分析[R勉強会][データマイニング] R言語による時系列分析
[R勉強会][データマイニング] R言語による時系列分析
 
Tokyo r #37 Rubin's Rule
Tokyo r #37 Rubin's RuleTokyo r #37 Rubin's Rule
Tokyo r #37 Rubin's Rule
 
パターン認識 第10章 決定木
パターン認識 第10章 決定木 パターン認識 第10章 決定木
パターン認識 第10章 決定木
 
R Markdownによるドキュメント生成と バージョン管理入門
R Markdownによるドキュメント生成と バージョン管理入門R Markdownによるドキュメント生成と バージョン管理入門
R Markdownによるドキュメント生成と バージョン管理入門
 

En vedette

VLDB2013 Session 1 Emerging Hardware
VLDB2013 Session 1 Emerging HardwareVLDB2013 Session 1 Emerging Hardware
VLDB2013 Session 1 Emerging HardwareTakuma Wakamori
 
ICDE2014 Session 14 Data Warehousing
ICDE2014 Session 14 Data WarehousingICDE2014 Session 14 Data Warehousing
ICDE2014 Session 14 Data WarehousingTakuma Wakamori
 
ICDE2015 Research 3: Distributed Storage and Processing
ICDE2015 Research 3: Distributed Storage and ProcessingICDE2015 Research 3: Distributed Storage and Processing
ICDE2015 Research 3: Distributed Storage and ProcessingTakuma Wakamori
 
データ・ビジュアライゼーション&ストーリーテリングを学ぶ!ハンズオンセミナー
データ・ビジュアライゼーション&ストーリーテリングを学ぶ!ハンズオンセミナーデータ・ビジュアライゼーション&ストーリーテリングを学ぶ!ハンズオンセミナー
データ・ビジュアライゼーション&ストーリーテリングを学ぶ!ハンズオンセミナーData Visualization Japan
 
統計を始める方へ①_データ環境Rの基本的なプログラミング|データアーティスト
統計を始める方へ①_データ環境Rの基本的なプログラミング|データアーティスト統計を始める方へ①_データ環境Rの基本的なプログラミング|データアーティスト
統計を始める方へ①_データ環境Rの基本的なプログラミング|データアーティストSatoru Yamamoto
 
AI(人工知能)インフォグラフィックス【時間をかけずにすぐわかる】
AI(人工知能)インフォグラフィックス【時間をかけずにすぐわかる】AI(人工知能)インフォグラフィックス【時間をかけずにすぐわかる】
AI(人工知能)インフォグラフィックス【時間をかけずにすぐわかる】Satoru Yamamoto
 
巨大な表を高速に扱うData.table について
巨大な表を高速に扱うData.table について巨大な表を高速に扱うData.table について
巨大な表を高速に扱うData.table についてHaruka Ozaki
 
遅延価値観数と階層ベイズを用いた男心をくすぐる女の戦略.R
遅延価値観数と階層ベイズを用いた男心をくすぐる女の戦略.R遅延価値観数と階層ベイズを用いた男心をくすぐる女の戦略.R
遅延価値観数と階層ベイズを用いた男心をくすぐる女の戦略.RMrUnadon
 
Rの導入とRStudio事始め(改訂版)
Rの導入とRStudio事始め(改訂版)Rの導入とRStudio事始め(改訂版)
Rの導入とRStudio事始め(改訂版)Takashi Yamane
 
30分でわかる『R』によるデータ分析|データアーティスト
30分でわかる『R』によるデータ分析|データアーティスト30分でわかる『R』によるデータ分析|データアーティスト
30分でわかる『R』によるデータ分析|データアーティストSatoru Yamamoto
 
Newman アルゴリズムによるソーシャルグラフのクラスタリング
Newman アルゴリズムによるソーシャルグラフのクラスタリングNewman アルゴリズムによるソーシャルグラフのクラスタリング
Newman アルゴリズムによるソーシャルグラフのクラスタリングAtsushi KOMIYA
 

En vedette (13)

VLDB2013 Session 1 Emerging Hardware
VLDB2013 Session 1 Emerging HardwareVLDB2013 Session 1 Emerging Hardware
VLDB2013 Session 1 Emerging Hardware
 
ICDE2014 Session 14 Data Warehousing
ICDE2014 Session 14 Data WarehousingICDE2014 Session 14 Data Warehousing
ICDE2014 Session 14 Data Warehousing
 
ICDE2015 Research 3: Distributed Storage and Processing
ICDE2015 Research 3: Distributed Storage and ProcessingICDE2015 Research 3: Distributed Storage and Processing
ICDE2015 Research 3: Distributed Storage and Processing
 
データ・ビジュアライゼーション&ストーリーテリングを学ぶ!ハンズオンセミナー
データ・ビジュアライゼーション&ストーリーテリングを学ぶ!ハンズオンセミナーデータ・ビジュアライゼーション&ストーリーテリングを学ぶ!ハンズオンセミナー
データ・ビジュアライゼーション&ストーリーテリングを学ぶ!ハンズオンセミナー
 
統計を始める方へ①_データ環境Rの基本的なプログラミング|データアーティスト
統計を始める方へ①_データ環境Rの基本的なプログラミング|データアーティスト統計を始める方へ①_データ環境Rの基本的なプログラミング|データアーティスト
統計を始める方へ①_データ環境Rの基本的なプログラミング|データアーティスト
 
AI(人工知能)インフォグラフィックス【時間をかけずにすぐわかる】
AI(人工知能)インフォグラフィックス【時間をかけずにすぐわかる】AI(人工知能)インフォグラフィックス【時間をかけずにすぐわかる】
AI(人工知能)インフォグラフィックス【時間をかけずにすぐわかる】
 
Rstudio事始め
Rstudio事始めRstudio事始め
Rstudio事始め
 
巨大な表を高速に扱うData.table について
巨大な表を高速に扱うData.table について巨大な表を高速に扱うData.table について
巨大な表を高速に扱うData.table について
 
遅延価値観数と階層ベイズを用いた男心をくすぐる女の戦略.R
遅延価値観数と階層ベイズを用いた男心をくすぐる女の戦略.R遅延価値観数と階層ベイズを用いた男心をくすぐる女の戦略.R
遅延価値観数と階層ベイズを用いた男心をくすぐる女の戦略.R
 
Rの導入とRStudio事始め(改訂版)
Rの導入とRStudio事始め(改訂版)Rの導入とRStudio事始め(改訂版)
Rの導入とRStudio事始め(改訂版)
 
30分でわかる『R』によるデータ分析|データアーティスト
30分でわかる『R』によるデータ分析|データアーティスト30分でわかる『R』によるデータ分析|データアーティスト
30分でわかる『R』によるデータ分析|データアーティスト
 
Newman アルゴリズムによるソーシャルグラフのクラスタリング
Newman アルゴリズムによるソーシャルグラフのクラスタリングNewman アルゴリズムによるソーシャルグラフのクラスタリング
Newman アルゴリズムによるソーシャルグラフのクラスタリング
 
はじめての「R」
はじめての「R」はじめての「R」
はじめての「R」
 

Plus de Takeshi Arabiki

クックパッド特売情報 における自然言語処理 〜固有表現抽出を利用した検索システム〜
クックパッド特売情報 における自然言語処理 〜固有表現抽出を利用した検索システム〜クックパッド特売情報 における自然言語処理 〜固有表現抽出を利用した検索システム〜
クックパッド特売情報 における自然言語処理 〜固有表現抽出を利用した検索システム〜Takeshi Arabiki
 
Introduction to Japanese Morphological Analysis
Introduction to Japanese Morphological AnalysisIntroduction to Japanese Morphological Analysis
Introduction to Japanese Morphological AnalysisTakeshi Arabiki
 
Rのデータ構造とメモリ管理
Rのデータ構造とメモリ管理Rのデータ構造とメモリ管理
Rのデータ構造とメモリ管理Takeshi Arabiki
 
HTML5 Canvas で学ぶアフィン変換
HTML5 Canvas で学ぶアフィン変換HTML5 Canvas で学ぶアフィン変換
HTML5 Canvas で学ぶアフィン変換Takeshi Arabiki
 
Introduction to Favmemo for Immature Engineers
Introduction to Favmemo for Immature EngineersIntroduction to Favmemo for Immature Engineers
Introduction to Favmemo for Immature EngineersTakeshi Arabiki
 
Rのスコープとフレームと環境と
Rのスコープとフレームと環境とRのスコープとフレームと環境と
Rのスコープとフレームと環境とTakeshi Arabiki
 
twitteRで快適Rライフ!
twitteRで快適Rライフ!twitteRで快適Rライフ!
twitteRで快適Rライフ!Takeshi Arabiki
 
RではじめるTwitter解析
RではじめるTwitter解析RではじめるTwitter解析
RではじめるTwitter解析Takeshi Arabiki
 
R版Getopt::Longを作ってみた
R版Getopt::Longを作ってみたR版Getopt::Longを作ってみた
R版Getopt::Longを作ってみたTakeshi Arabiki
 
文字列カーネルによる辞書なしツイート分類 〜文字列カーネル入門〜
文字列カーネルによる辞書なしツイート分類 〜文字列カーネル入門〜文字列カーネルによる辞書なしツイート分類 〜文字列カーネル入門〜
文字列カーネルによる辞書なしツイート分類 〜文字列カーネル入門〜Takeshi Arabiki
 
Rデバッグあれこれ
RデバッグあれこれRデバッグあれこれ
RデバッグあれこれTakeshi Arabiki
 
はじめてのまっぷりでゅ〜す
はじめてのまっぷりでゅ〜すはじめてのまっぷりでゅ〜す
はじめてのまっぷりでゅ〜すTakeshi Arabiki
 
TwitterのデータをRであれこれ
TwitterのデータをRであれこれTwitterのデータをRであれこれ
TwitterのデータをRであれこれTakeshi Arabiki
 
Twitterのデータを取得する準備
Twitterのデータを取得する準備Twitterのデータを取得する準備
Twitterのデータを取得する準備Takeshi Arabiki
 

Plus de Takeshi Arabiki (16)

開発の心得
開発の心得開発の心得
開発の心得
 
クックパッド特売情報 における自然言語処理 〜固有表現抽出を利用した検索システム〜
クックパッド特売情報 における自然言語処理 〜固有表現抽出を利用した検索システム〜クックパッド特売情報 における自然言語処理 〜固有表現抽出を利用した検索システム〜
クックパッド特売情報 における自然言語処理 〜固有表現抽出を利用した検索システム〜
 
Introduction to Japanese Morphological Analysis
Introduction to Japanese Morphological AnalysisIntroduction to Japanese Morphological Analysis
Introduction to Japanese Morphological Analysis
 
Rのデータ構造とメモリ管理
Rのデータ構造とメモリ管理Rのデータ構造とメモリ管理
Rのデータ構造とメモリ管理
 
HTML5 Canvas で学ぶアフィン変換
HTML5 Canvas で学ぶアフィン変換HTML5 Canvas で学ぶアフィン変換
HTML5 Canvas で学ぶアフィン変換
 
Introduction to Favmemo for Immature Engineers
Introduction to Favmemo for Immature EngineersIntroduction to Favmemo for Immature Engineers
Introduction to Favmemo for Immature Engineers
 
Rのスコープとフレームと環境と
Rのスコープとフレームと環境とRのスコープとフレームと環境と
Rのスコープとフレームと環境と
 
twitteRで快適Rライフ!
twitteRで快適Rライフ!twitteRで快適Rライフ!
twitteRで快適Rライフ!
 
RではじめるTwitter解析
RではじめるTwitter解析RではじめるTwitter解析
RではじめるTwitter解析
 
R版Getopt::Longを作ってみた
R版Getopt::Longを作ってみたR版Getopt::Longを作ってみた
R版Getopt::Longを作ってみた
 
HMM, MEMM, CRF メモ
HMM, MEMM, CRF メモHMM, MEMM, CRF メモ
HMM, MEMM, CRF メモ
 
文字列カーネルによる辞書なしツイート分類 〜文字列カーネル入門〜
文字列カーネルによる辞書なしツイート分類 〜文字列カーネル入門〜文字列カーネルによる辞書なしツイート分類 〜文字列カーネル入門〜
文字列カーネルによる辞書なしツイート分類 〜文字列カーネル入門〜
 
Rデバッグあれこれ
RデバッグあれこれRデバッグあれこれ
Rデバッグあれこれ
 
はじめてのまっぷりでゅ〜す
はじめてのまっぷりでゅ〜すはじめてのまっぷりでゅ〜す
はじめてのまっぷりでゅ〜す
 
TwitterのデータをRであれこれ
TwitterのデータをRであれこれTwitterのデータをRであれこれ
TwitterのデータをRであれこれ
 
Twitterのデータを取得する準備
Twitterのデータを取得する準備Twitterのデータを取得する準備
Twitterのデータを取得する準備
 

Dernier

HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesBoston Institute of Analytics
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfhans926745
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilV3cube
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 

Dernier (20)

HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 

Rデータフレーム自由自在

  • 1. R Tsukuba.R #9 (2011/11/12) @a_bicky
  • 2. • Takeshi Arabiki 1 ‣ Twitter: @a_bicky ‣ : id:a_bicky • R • http://d.hatena.ne.jp/a_bicky/
  • 3. • Takeshi Arabiki 1 ‣ Twitter: @a_bicky ‣ : id:a_bicky • R SciPy • http://d.hatena.ne.jp/a_bicky/
  • 4. Osaka.R #4 Tokyo.R #16 http://www.slideshare.net/abicky/twitterr http://www.slideshare.net/abicky/r-9034336
  • 5. • • R 8 ,9 • • • • http://www.amazon.co.jp/gp/product/4431712186
  • 6.
  • 7. reshape2 > install.packages("reshape2") > library(reshape2) > head(tips) # total_bill tip sex smoker day time size 1 16.99 1.01 Female No Sun Dinner 2 2 10.34 1.66 Male No Sun Dinner 3 3 21.01 3.50 Male No Sun Dinner 3 4 23.68 3.31 Male No Sun Dinner 2 5 24.59 3.61 Female No Sun Dinner 4 6 25.29 4.71 Male No Sun Dinner 4
  • 8. tips total_bill: tip: sex: Male, Female smoker: Yes, No day: Thur, Fri, Sat, Sun time: Lunch, Dinner size:
  • 9.
  • 10. • • • subset • cbind, [, $, [[ • transform, within • • subset • cbind, [, $, [[ • transform, within • • order •
  • 11. > class(tips) [1] "data.frame" > mode(tips) # data.frame list [1] "list" > head(tips[["total_bill"]]) # list [1] 16.99 10.34 21.01 23.68 24.59 25.29 > head(tips$total_bill) # [1] 16.99 10.34 21.01 23.68 24.59 25.29 > head(tips["total_bill"]) # data.frame total_bill 1 16.99 2 10.34 3 21.01 4 23.68 5 24.59 6 25.29
  • 12. > head(tips[c("total_bill", "tip")]) # total_bill tip 1 16.99 1.01 2 10.34 1.66 3 21.01 3.50 4 23.68 3.31 5 24.59 3.61 6 25.29 4.71 > head(tips[[c("total_bill", "tip")]]) # Error in .subset2(x, i, exact = exact) : subscript out of bounds > tips[[c(1, 2)]] # tips[[1]][[2]] [1] 10.34
  • 13. > tips[1:2, 1:2] # total_bill tip 1 16.99 1.01 2 10.34 1.66 > tips[1:2, c("total_bill", "tip")] # total_bill tip 1 16.99 1.01 2 10.34 1.66 > head(tips[-(1:2), -(1:2)]) # sex smoker day time size 3 Male No Sun Dinner 3 4 Male No Sun Dinner 2 5 Female No Sun Dinner 4 6 Male No Sun Dinner 4 7 Male No Sun Dinner 2 8 Male No Sun Dinner 4
  • 14. subset > args(subset.data.frame) function (x, subset, select, drop = FALSE, ...) NULL > (tips.vip <- subset(tips, total_bill > 30 & size == 2)) total_bill tip sex smoker day time size 84 32.68 5.00 Male Yes Thur Lunch 2 174 31.85 3.18 Male Yes Sun Dinner 2 176 32.90 3.11 Male Yes Sun Dinner 2 180 34.63 3.55 Male Yes Sun Dinner 2 185 40.55 3.00 Male Yes Sun Dinner 2 238 32.83 1.17 Male Yes Sat Dinner 2 > levels(tips.vip$smoker) # [1] "No" "Yes" > levels(droplevels(tips.vip)$smoker) # [1] "Yes"
  • 15. cbind, [, $, [[ > head(cbind(tips, type = ifelse(tips$tip < 2, " ", " ")), 3) total_bill tip sex smoker day time size type 1 16.99 1.01 Female No Sun Dinner 2 2 10.34 1.66 Male No Sun Dinner 3 3 21.01 3.50 Male No Sun Dinner 3 > tips$type <- ifelse(tips$tip < 2, " ", " ") > head(tips, 3) total_bill tip sex smoker day time size type 1 16.99 1.01 Female No Sun Dinner 2 2 10.34 1.66 Male No Sun Dinner 3 3 21.01 3.50 Male No Sun Dinner 3 > data(tips) #
  • 16. transform, within > args(transform.data.frame) function (`_data`, ...) NULL > head(transform(tips, type = ifelse(tips$tip < 2, " ", " ")), 3) total_bill tip sex smoker day time size type 1 16.99 1.01 Female No Sun Dinner 2 2 10.34 1.66 Male No Sun Dinner 3 3 21.01 3.50 Male No Sun Dinner 3 > args(within.data.frame) function (data, expr, ...) NULL > head(within(tips, { type <- c() # within + type[tip < 2] <- " " + type[tip >= 2] <- " " }), 3) total_bill tip sex smoker day time size type 1 16.99 1.01 Female No Sun Dinner 2 2 10.34 1.66 Male No Sun Dinner 3 3 21.01 3.50 Male No Sun Dinner 3
  • 17. subset > # subset > head(subset(tips, select = c(tip, sex, smoker)), 1) tip sex smoker 1 1.01 Female No > head(subset(tips, select = 2:4), 1) tip sex smoker 1 1.01 Female No > head(subset(tips, select = -c(total_bill, size, time, day)), 1) tip sex smoker 1 1.01 Female No > head(subset(tips, select = -c(1, 5:7)), 1) tip sex smoker 1 1.01 Female No > head(subset(tips, select = c(tip:smoker)), 1) tip sex smoker 1 1.01 Female No > head(subset(tips, select = -c(total_bill, day:size)), 1) tip sex smoker 1 1.01 Female No
  • 18. [, $, [[ > # NULL > tips$size <- NULL > head(tips, 3) total_bill tip sex smoker day time 1 16.99 1.01 Female No Sun Dinner 2 10.34 1.66 Male No Sun Dinner 3 21.01 3.50 Male No Sun Dinner > tips[["time"]] <- NULL > head(tips, 3) total_bill tip sex smoker day 1 16.99 1.01 Female No Sun 2 10.34 1.66 Male No Sun 3 21.01 3.50 Male No Sun > tips["day"] <- NULL; tips[1] <- NULL > head(tips, 3) tip sex smoker 1 1.01 Female No 2 1.66 Male No 3 3.50 Male No > data(tips)
  • 19. transform, within > # NULL > head(transform(tips, total_bill = NULL, size = NULL, time = NULL, day = NULL), 3) tip sex smoker 1 1.01 Female No 2 1.66 Male No 3 3.50 Male No > # rm > head(within(tips, rm(total_bill, size, time, day)), 3) tip sex smoker 1 1.01 Female No 2 1.66 Male No 3 3.50 Male No
  • 20. > head(transform(tips, tip = 10), 3) total_bill tip sex smoker day time size 1 16.99 10 Female No Sun Dinner 2 2 10.34 10 Male No Sun Dinner 3 3 21.01 10 Male No Sun Dinner 3 > head(within(tips, tip <- 10), 3) total_bill tip sex smoker day time size 1 16.99 10 Female No Sun Dinner 2 2 10.34 10 Male No Sun Dinner 3 3 21.01 10 Male No Sun Dinner 3 > tips$tip <- 10 > head(tips, 3) total_bill tip sex smoker day time size 1 16.99 10 Female No Sun Dinner 2 2 10.34 10 Male No Sun Dinner 3 3 21.01 10 Male No Sun Dinner 3 > data(tips)
  • 21. order > head(tips[order(tips$sex), ], 4) # total_bill tip sex smoker day time size 1 16.99 1.01 Female No Sun Dinner 2 5 24.59 3.61 Female No Sun Dinner 4 12 35.26 5.00 Female No Sun Dinner 4 15 14.83 3.02 Female No Sun Dinner 2 > head(tips[order(tips$sex, decreasing = TRUE), ], 4) # total_bill tip sex smoker day time size 2 10.34 1.66 Male No Sun Dinner 3 3 21.01 3.50 Male No Sun Dinner 3 4 23.68 3.31 Male No Sun Dinner 2 6 25.29 4.71 Male No Sun Dinner 4 > head(tips[order(tips$sex, tips$tip), ], 4) # total_bill tip sex smoker day time size 68 3.07 1.00 Female Yes Sat Dinner 1 93 5.75 1.00 Female Yes Fri Dinner 2 112 7.25 1.00 Female No Sat Dinner 1 1 16.99 1.01 Female No Sun Dinner 2
  • 22. data.frame > (tip <- data.frame(date = sample(seq(as.Date("2011-11-09"), by = "day", len = 4)), + total_bill = sample(1:4 * 10), + tip = sample(1:4))) date total_bill tip 1 2011-11-10 30 4 2 2011-11-12 40 2 3 2011-11-11 10 1 4 2011-11-09 20 3 > # > tip <- tip[order(tip$date), ] > transform(tip, total_bill = cumsum(total_bill), tip = cumsum(tip)) date total_bill tip 4 2011-11-09 20 3 1 2011-11-10 50 7 3 2011-11-11 60 8 2 2011-11-12 100 10
  • 23. > head(tips[c("tip", "total_bill", "sex", "size", "time", "day", "smoker")]) tip total_bill sex size time day smoker 1 10 16.99 Female 2 Dinner Sun No 2 10 10.34 Male 3 Dinner Sun No 3 10 21.01 Male 3 Dinner Sun No 4 10 23.68 Male 2 Dinner Sun No 5 10 24.59 Female 4 Dinner Sun No 6 10 25.29 Male 4 Dinner Sun No
  • 24.
  • 25. • • table • xtabs • aggregate • by
  • 26. > args(colSums) function (x, na.rm = FALSE, dims = 1L) NULL > colSums(subset(tips, select = c(total_bill, tip)), na.rm = TRUE) total_bill tip 4827.77 731.58 > args(colMeans) function (x, na.rm = FALSE, dims = 1L) NULL > colMeans(subset(tips, select = c(total_bill, tip)), na.rm = TRUE) total_bill tip 19.785943 2.998279 > # apply colSums > apply(subset(tips, select = c(total_bill, tip)), 2, sum, na.rm = TRUE) total_bill tip 4827.77 731.58
  • 27. table > args(table) function (..., exclude = if (useNA == "no") c(NA, NaN), useNA = c("no", "ifany", "always"), dnn = list.names(...), deparse.level = 1) NULL > table(subset(tips, select = c(sex, smoker))) smoker sex No Yes Female 54 33 Male 97 60 > # 4 > table(subset(tips, select = c(sex, smoker, day, size))) , , day = Fri, size = 1 smoker sex No Yes Female 0 0 Male 0 1
  • 28. table > args(addmargins) function (A, margin = seq_along(dim(A)), FUN = sum, quiet = FALSE) NULL > # > addmargins(table(subset(tips, select = c(sex, smoker)))) smoker sex No Yes Sum Female 54 33 87 Male 97 60 157 Sum 151 93 244 > # > args(prop.table) function (x, margin = NULL) NULL > prop.table(table(subset(tips, select = c(sex, smoker)))) smoker sex No Yes Female 0.2213115 0.1352459 Male 0.3975410 0.2459016
  • 29. xtabs > args(xtabs) function (formula = ~., data = parent.frame(), subset, sparse = FALSE, na.action, exclude = c(NA, NaN), drop.unused.levels = FALSE) NULL > # > xtabs(~ sex + smoker, tips) smoker sex No Yes Female 54 33 Male 97 60 > # > xtabs(cbind(total_bill, tip) ~ sex + smoker, tips) , , = total_bill smoker sex No Yes Female 977.68 593.27 Male 1919.75 1337.07
  • 30. aggregate > args(aggregate.data.frame) function (x, by, FUN, ..., simplify = TRUE) NULL > # FUN 1 > aggregate(tips[c("total_bill", "tip")], tips[c("sex", "day")], sum) sex day total_bill tip 1 Female Fri 127.31 25.03 2 Male Fri 198.57 26.93 3 Female Sat 551.05 78.45 4 Male Sat 1227.35 181.95 5 Female Sun 357.70 60.61 6 Male Sun 1269.46 186.78 7 Female Thur 534.89 82.42 8 Male Thur 561.44 89.41 > # formula > aggregate(cbind(total_bill, tip) ~ sex + day, tips, sum) sex day total_bill tip 1 Female Fri 127.31 25.03
  • 31. by > args(by) function (data, INDICES, FUN, ..., simplify = TRUE) NULL > # aggregate FUN OK > (ret <- by(tips[c("total_bill", "tip")], tips[c("sex", "day")], range)) sex: Female day: Fri [1] 1.00 22.75 ------------------------------------------------------------ sex: Male day: Fri [1] 1.50 40.17 > # data.frame > cbind(expand.grid(dimnames(ret)), do.call(rbind, ret)) sex day 1 2 1 Female Fri 1.00 22.75 2 Male Fri 1.50 40.17
  • 32.
  • 33. reshape • merge
  • 34. reshape > args(reshape) function (data, varying = NULL, v.names = NULL, timevar = "time", idvar = "id", ids = 1L:NROW(data), times = seq_along(varying[[1L]]), drop = NULL, direction, new.row.names = NULL, sep = ".", split = if (sep == "") { list(regexp = "[A-Za-z][0-9]", include = TRUE) } else { list(regexp = sep, include = FALSE, fixed = TRUE) }) NULL > head(reshape(tips, idvar = c("sex", "smoker", "time", "size"), + timevar = "day", drop = "total_bill", direction = "wide")) sex smoker time size tip.Sun tip.Sat tip.Thur tip.Fri 1 Female No Dinner 2 1.01 2.75 3 3.25 2 Male No Dinner 3 1.66 3.35 NA NA 4 Male No Dinner 2 3.31 4.08 NA 3.50 5 Female No Dinner 4 3.61 2.45 NA NA 6 Male No Dinner 4 4.71 7.58 NA NA 17 Female No Dinner 3 1.67 3.07 NA NA
  • 35. reshape > # idvar timevar > (a <- data.frame(a = c(1:3, 1), b = c(1:3, 1), c = 1:4)) a b c 1 1 1 1 2 2 2 2 3 3 3 3 4 1 1 4 > reshape(a, idvar = "a", timevar = "b", direction = "wide") a c.1 c.2 c.3 1 1 1 NA NA 2 2 NA 2 NA 3 3 NA NA 3
  • 36. merge > # > (user.type <- data.frame(sex = rep(c("Male", "Female"), each = 2), + smoker = c("Yes", "No"), + type = LETTERS[1:4])) sex smoker type 1 Male Yes A 2 Male No B 3 Female Yes C 4 Female No D > args(merge.data.frame) function (x, y, by = intersect(names(x), names(y)), by.x = by, by.y = by, all = FALSE, all.x = all, all.y = all, sort = TRUE, suffixes = c(".x", ".y"), incomparables = NULL, ...) NULL > merge(tips, user.type, by = c("sex", "smoker"), sort = FALSE)[54:55, ] sex smoker total_bill tip day time size type 54 Female No 10.65 1.50 Thur Lunch 2 D 55 Male No 10.27 1.71 Sun Dinner 2 B
  • 37.
  • 38. • • R • reshape2 • melt • cast •
  • 39. Excel
  • 40. R > acast(melt(tips, id.var = c("sex", "smoker", "day"), measure.var = "tip"), + sex + smoker ~ day, sum, margins = TRUE) Fri Sat Sun Thur (all) Female_No 6.25 35.42 46.61 61.49 149.77 Female_Yes 18.78 43.03 14.00 18.93 94.74 Female_(all) 25.03 78.45 60.61 80.42 244.51 Male_No 5.00 104.21 133.96 58.83 302.00 Male_Yes 21.93 77.74 52.82 30.58 183.07 Male_(all) 26.93 181.95 186.78 89.41 485.07 (all)_(all) 51.96 260.40 247.39 169.83 729.58 reshape2
  • 41. reshape2 melt cast melt id > head(tipsm <- melt(tips, measure.vars = c("total_bill", "tip"))) sex smoker day time size variable value 1 Female No Sun Dinner 2 total_bill 16.99 2 Male No Sun Dinner 3 total_bill 10.34 3 Male No Sun Dinner 3 total_bill 21.01 4 Male No Sun Dinner 2 total_bill 23.68 5 Female No Sun Dinner 4 total_bill 24.59 6 Male No Sun Dinner 4 total_bill 25.29 > levels(tipsm$variable) [1] "total_bill" "tip"
  • 42. melt > args(melt.data.frame) function (data, id.vars, measure.vars, variable_name = "variable", na.rm = !preserve.na, preserve.na = TRUE, ...) NULL > # factor id > head(melt(tips), 1) Using sex, smoker, day, time as id variables sex smoker day time variable value 1 Female No Sun Dinner total_bill 16.99 > # id measure > head(melt(tips, id.vars = c("sex", "smoker", "day", "time", "size")), 1) sex smoker day time size variable value 1 Female No Sun Dinner 2 total_bill 16.99 > # id measure > head(melt(tips, id.vars = c("sex", "smoker", "day", "time", "size"), + measure.vars = "tip"), 1) sex smoker day time size variable value 1 Female No Sun Dinner 2 tip 1.01
  • 43. cast formula fun.aggregate > args(acast) # array acast function (data, formula, fun.aggregate = NULL, ..., margins = NULL, subset = NULL, fill = NULL, drop = TRUE, value_var = guess_value(data)) NULL > args(dcast) # data.frame dcast function (data, formula, fun.aggregate = NULL, ..., margins = NULL, subset = NULL, fill = NULL, drop = TRUE, value_var = guess_value(data)) NULL formula ... . acast hoge ~ fuga ~ piyo ※dcast 1 hoge ~ fuga + piyo
  • 44. > tipsm <- melt(tips, measure.vars = c("total_bill", "tip")) > acast(tipsm, sex ~ smoker, length) No Yes Female 108 64 Male 194 120 > # > acast(tipsm, smoker ~ sex, length) Female Male No 108 194 Yes 64 120 > # > acast(tipsm, sex ~ smoker, length, margins = TRUE) No Yes (all) Female 108 64 172 Male 194 120 314 (all) 302 184 486
  • 45. > # size > acast(tipsm, smoker ~ sex + size, length) Female_1 Female_2 Female_3 Female_4 Female_5 Female_6 Male_1 Male_2 Male_3 No 4 66 18 14 2 4 0 114 34 Yes 2 48 10 4 0 0 2 82 14 Male_4 Male_5 Male_6 No 38 4 4 Yes 18 4 0 > # 3 > acast(tipsm, smoker ~ sex ~ size, length) , , 1 Female Male No 4 0 Yes 2 2
  • 46. > # sum > acast(tipsm, sex ~ day, sum) Fri Sat Sun Thur Female 152.34 629.5 418.31 617.31 total_bill tip Male 225.50 1409.3 1456.24 650.85 > # total_bill tip sum > acast(tipsm, sex + variable ~ day, sum) Fri Sat Sun Thur Female_total_bill 127.31 551.05 357.70 534.89 Female_tip 25.03 78.45 60.61 82.42 Male_total_bill 198.57 1227.35 1269.46 561.44 Male_tip 26.93 181.95 186.78 89.41 > # tip sum > acast(tipsm, sex ~ day, sum, subset = .(variable == "tip")) Fri Sat Sun Thur Female 25.03 78.45 60.61 82.42 Male 26.93 181.95 186.78 89.41
  • 47.
  • 48. reshape2 aggregate table xtabs