{"id":834,"date":"2019-01-24T12:23:35","date_gmt":"2019-01-24T03:23:35","guid":{"rendered":"http:\/\/141.164.34.82\/?p=834"},"modified":"2022-02-03T18:05:18","modified_gmt":"2022-02-03T09:05:18","slug":"dplyr-00-magrittr","status":"publish","type":"post","link":"http:\/\/ds.sumeun.org\/?p=834","title":{"rendered":"\ud328\ud0a4\uc9c0 dplyr 00: magrittr"},"content":{"rendered":"<h1><code>dplyr<\/code> \ud328\ud0a4\uc9c0\ub97c \ud65c\uc6a9\ud55c \ub370\uc774\ud130 \uac00\uacf5 1: <code>magrittr<\/code>\uc758 \ud30c\uc774\ud504 \uc5f0\uc0b0\uc790<\/h1>\n<ul>\n<li><code>dplyr<\/code> \ud328\ud0a4\uc9c0\uc758 \ud568\uc218\uacfc <code>magrittr<\/code> \ud328\ud0a4\uc9c0\uc758 <code>%&gt;%<\/code> \uc5f0\uc0b0\uc744 \ud568\uaed8 \ud65c\uc6a9\ud558\uba74 \ub370\uc774\ud130 \uac00\uacf5\uc774 \uac04\ub2e8\ud558\uace0 \uc774\ud574\ud558\uae30 \uc27d\ub2e4. \uc5ec\uae30\uc11c\ub294 <strong>\ud30c\uc774\ud504 \uc5f0\uc0b0<\/strong>\uc774\ub77c\uace0 \ubd88\ub9ac\ub294 <code>%&gt;%<\/code>\uc5d0 \ub300\ud574\uc11c \uc54c\uc544\ubcf8\ub2e4.<\/li>\n<li><code>dplyr<\/code> \ud328\ud0a4\uc9c0\ub97c \ud65c\uc6a9\ud55c \ub370\uc774\ud130 \uc0ac\uc804\ucc98\ub9ac\uc758 \ubaa9\ucc28\ub294 \ub2e4\uc74c\uacfc \uac19\ub2e4.\n<ul>\n<li><code>magrittr<\/code>\uc758 <code>%&gt;%<\/code><\/li>\n<li><code>dplyr<\/code>\uc744 \uc0ac\uc6a9\ud55c \ubd80\ubd84 \ucc38\uc870<\/li>\n<li><code>dplyr<\/code>\uc744 \uc0ac\uc6a9\ud55c \uc218\uc815<\/li>\n<li><code>dplyr<\/code>\uc758 \uadf8 \ubc16\uc758 \ud3b8\uc758 \uae30\ub2a5<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h3><code>magrittr<\/code> \ud328\ud0a4\uc9c0\uc758 \ud30c\uc774\ud504<\/h3>\n<ul>\n<li>\ud558\ub098\uc758 \ub300\uc0c1\uc5d0 \uc5ec\ub7ec \ud568\uc218\ub97c \uc5f0\uc18d\uc801\uc73c\ub85c \uc801\uc6a9\ud558\ub294 \uacbd\uc6b0, \uad04\ud638\uac00 \uc5f0\uc18d\uc801\uc73c\ub85c \uc911\ucca9\ub418\uc5b4 \uac00\ub3c5\uc131\uc774 \ub5a8\uc5b4\uc9c4\ub2e4. \uc608\ub97c \ub4e4\uc5b4 <code>diamond<\/code>\uc5d0 <code>head<\/code>\uc640 <code>dim<\/code> \ud568\uc218\ub97c \uc801\uc6a9\ud55c\ub2e4\uba74, \ub2e4\uc74c\uacfc \uac19\ub2e4.<\/li>\n<\/ul>\n<pre><code class=\"r\">data(diamonds , package='ggplot2')\r\ndim(head(diamonds , n=4)) \r\n<\/code><\/pre>\n<pre>## [1]  4 10\r\n<\/pre>\n<ul>\n<li><code>magrittr<\/code> \ud328\ud0a4\uc9c0\uc758 <code>%&gt;%<\/code>\uacfc <code>.<\/code>\ub97c \ud65c\uc6a9\ud558\uba74 \ubcf5\uc7a1\ud558\uac8c \uc911\ucca9\ub41c \uad04\ud638\ub97c \uc4f8 \ud544\uc694\uac00 \uc5c6\ub2e4.<\/li>\n<\/ul>\n<pre><code class=\"r\">library(magrittr) \r\ndiamonds %&gt;% head(., n=4) %&gt;% dim(.) \r\n<\/code><\/pre>\n<pre>## [1]  4 10\r\n<\/pre>\n<ul>\n<li><code>.<\/code> \uc740 <code>%&gt;%<\/code> \uc774\uc804\uc758 \uacb0\uacfc\ub97c \ub098\ud0c0\ub0b8\ub2e4. \ub530\ub77c\uc11c \uccab \ubc88\uc9f8 <code>.<\/code> \uc740 <code>diamonds<\/code>\ub97c \ub450\ubc88\uc9f8 <code>.<\/code>\ub294 <code>head(diamonds, n=4)<\/code>\uc758 \uacb0\uacfc\ub97c \ub098\ud0c0\ub0b8\ub2e4. \ub9cc\uc57d <code>.<\/code>\uc774 \ud568\uc218\uc758 \uccab \ubc88\uc9f8 \uc778\uc790\ub85c \uc4f0\uc77c \uacbd\uc6b0\uc5d0\ub294 \ub2e4\uc74c\uacfc \uac19\uc774 \uc0dd\ub7b5\ud560 \uc218 \uc788\ub2e4. <code>head(., n=4)<\/code>\uc640 <code>dim(.)<\/code>\uc758 <code>.<\/code>\ub97c \ubaa8\ub450 \uc0dd\ub7b5\ud558\uc600\ub2e4.<\/li>\n<\/ul>\n<pre><code class=\"r\">diamonds %&gt;% head(n=4) %&gt;% dim() \r\n<\/code><\/pre>\n<pre>## [1]  4 10\r\n<\/pre>\n<p>\uadf8\ub9ac\uace0 <code>dim()<\/code>\ucc98\ub7fc \uc778\uc790\uac00 <code>.<\/code>\ubfd0\uc778 \uacbd\uc6b0\uc5d0\ub294 \uad04\ud638\uae4c\uc9c0 \uc0dd\ub7b5\ud560 \uc218 \uc788\ub2e4.<\/p>\n<pre><code class=\"r\">diamonds %&gt;% head(n=4) %&gt;% dim \r\n<\/code><\/pre>\n<pre>## [1]  4 10\r\n<\/pre>\n<ul>\n<li>\ub2e4\ub978 \uc608\ub97c \ub4e4\uc5b4\ubcf4\uc790. (\uc774\ub7f0 \uac83\ub3c4 \uac00\ub2a5\ud558\ub2e4!)<\/li>\n<\/ul>\n<pre><code class=\"r\">diamonds %&gt;% .$price %&gt;% .[1:10]\r\n<\/code><\/pre>\n<pre>##  [1] 326 326 327 334 335 336 336 337 337 338\r\n<\/pre>\n<pre><code class=\"r\">diamonds %&gt;% .[[\"price\"]] %&gt;% .[1:10]\r\n<\/code><\/pre>\n<pre>##  [1] 326 326 327 334 335 336 336 337 337 338\r\n<\/pre>\n<ul>\n<li>\uc704\uc5d0\uc11c \ub2e4\ub8ec <code>diamonds<\/code> \ub370\uc774\ud130\ub294 \ub370\uc774\ud130 \ud504\ub808\uc784\uc73c\ub85c \ubcf4\uc774\uc9c0\ub9cc \uc0ac\uc2e4 <code>tibble<\/code>(\ud2f0\ube14)\uc774\ub77c\ub294 \ub370\uc774\ud130 \ud615\uc2dd\uc774\ub2e4. \uc774\ub97c \ud655\uc778\ud558\uae30 \uc704\ud574 <code>class<\/code> \ud568\uc218\ub97c \uc0ac\uc6a9\ud560 \uc218\ub3c4 \uc788\uace0, <code>tibble<\/code>\uc774\ub098 <code>dplyr<\/code> \ud328\ud0a4\uc9c0\ub97c \ubd88\uc5b4\ub4e4\uc778 \ud6c4 <code>diamonds<\/code>\ub97c \ub2e4\uc2dc \ud655\uc778\ud574 \ubcfc \uc218\ub3c4 \uc788\ub2e4.<\/li>\n<\/ul>\n<pre><code class=\"r\">class(diamonds) \r\n<\/code><\/pre>\n<pre>## [1] \"tbl_df\"     \"tbl\"        \"data.frame\"\r\n<\/pre>\n<pre><code class=\"r\">library(dplyr) \r\ndiamonds \r\n<\/code><\/pre>\n<pre>## # A tibble: 53,940 x 10\r\n##    carat cut       color clarity depth table price     x     y     z\r\n##    &lt;dbl&gt; &lt;ord&gt;     &lt;ord&gt; &lt;ord&gt;   &lt;dbl&gt; &lt;dbl&gt; &lt;int&gt; &lt;dbl&gt; &lt;dbl&gt; &lt;dbl&gt;\r\n##  1 0.23  Ideal     E     SI2      61.5    55   326  3.95  3.98  2.43\r\n##  2 0.21  Premium   E     SI1      59.8    61   326  3.89  3.84  2.31\r\n##  3 0.23  Good      E     VS1      56.9    65   327  4.05  4.07  2.31\r\n##  4 0.290 Premium   I     VS2      62.4    58   334  4.2   4.23  2.63\r\n##  5 0.31  Good      J     SI2      63.3    58   335  4.34  4.35  2.75\r\n##  6 0.24  Very Good J     VVS2     62.8    57   336  3.94  3.96  2.48\r\n##  7 0.24  Very Good I     VVS1     62.3    57   336  3.95  3.98  2.47\r\n##  8 0.26  Very Good H     SI1      61.9    55   337  4.07  4.11  2.53\r\n##  9 0.22  Fair      E     VS2      65.1    61   337  3.87  3.78  2.49\r\n## 10 0.23  Very Good H     VS1      59.4    61   338  4     4.05  2.39\r\n## # ... with 53,930 more rows\r\n<\/pre>\n<ul>\n<li><code>class<\/code> \ud568\uc218\uc758 \uacb0\uacfc\ub294 <code>diamonds<\/code>\uac00 \ub370\uc774\ud130\ud504\ub808\uc784(<code>data.frame<\/code>) \uacfc \ud638\ud658\ub418\ub294 \ud2f0\ube14(<code>tibble<\/code>, <code>tbl_df<\/code>) \ud615\uc2dd\uc784\uc744 \uc54c\ub824\uc900\ub2e4. \ud2f0\ube14\uc740 \ub370\uc774\ud130\ub97c \uc880 \ub354 \uae54\ub054\ud558\uac8c \ud45c\uc2dc\ud55c\ub2e4. <code>carat, cut, ...<\/code>\uc740 \uc5f4\uc774\ub984, <code>&lt;dbl&gt;, &lt;ord&gt;, ...<\/code>\uc740 \uac01 \uc5f4\uc758 \ub370\uc774\ud130 \ud615\uc2dd\uc744 \ub098\ud0c0\ub0b4\uba70, \ud654\uba74\uc758 \uac00\ub85c, \uc138\ub85c \ub108\ube44\ub97c \ub118\uc5b4\uac00\ub294 \ud589\uacfc \uc5f4\uc740 \uc0dd\ub7b5\ub41c\ub2e4. (\ub9cc\uc57d \ucd9c\ub825\ub418\ub294 \ud589\uc758 \uc218\uc640 \uc5f4\uc758 \uc218\ub97c \uc815\ud558\uace0 \uc2f6\ub2e4\uba74 <code>print(diamonds, n=, width=)<\/code>\uc744 \ud65c\uc6a9\ud55c\ub2e4.)<\/li>\n<li>\uc67c\ucabd \uac00\uc7a5\uc790\ub9ac\uc758 <code>1, 2, ...<\/code>\ub294 \ud589\uc758 \uc21c\uc11c\ub97c \ubcf4\uc5ec\uc900\ub2e4. \ub9c8\uc9c0\ub9c9\uc73c\ub85c <code>... with 53,930 more rows<\/code>\ub294 \ud654\uba74\uc5d0 \ud45c\uc2dc\ub418\uc9c0 \uc54a\uc740 \uc5f4\uc758 \uc218\ub97c \ub098\ud0c0\ub0b8\ub2e4.<\/li>\n<li>\ud2f0\ube14\uc740 \ub370\uc774\ud130 \ud504\ub808\uc784\uacfc \ub2ec\ub9ac \uc5f4 \uc774\ub984\uc758 \uc77c\ubd80\ub97c \uc0ac\uc6a9\ud558\uc5ec \uc5f4\uc744 \ucc38\uc870\ud560 \uc218 \uc5c6\ub2e4(\ub2e4\ub978 \ub9d0\ub85c partial matching\uc774 \ubd88\uac00\ub2a5\ud558\ub2e4). \ub2e4\uc74c\uc758 \ucf54\ub4dc\ub97c \ubcf4\uc790. <code>diaTB<\/code>, <code>diaDF<\/code>\ub294 \ub3d9\uc77c\ud55c \uc790\ub8cc\ub97c \ud2f0\ube14\uacfc \ub370\uc774\ud130 \ud504\ub808\uc784 \ud615\uc2dd\uc73c\ub85c \uc800\uc7a5\ud558\uace0 \uc788\ub2e4. <code>price<\/code>\uc5f4\uc744 \ubd80\ubd84 \uc774\ub984 <code>pri<\/code>\uc744 \uc368\uc11c \ucc38\uc870\ud558\ub824\uace0 \ud558\uace0 \uc788\ub2e4. <code>diaDF$pri<\/code>\ub294 \uac00\ub2a5\ud558\uc9c0\ub9cc <code>diaTB$pri<\/code>\ub294 \ubd88\uac00\ub2a5\ud558\ub2e4.<\/li>\n<\/ul>\n<pre><code class=\"r\">diaTB &lt;- as_tibble(diamonds[1:10, ]) \r\ndiaDF &lt;- as.data.frame(diamonds[1:10, ]) \r\n\r\ndiaDF$pri \r\n<\/code><\/pre>\n<pre>##  [1] 326 326 327 334 335 336 336 337 337 338\r\n<\/pre>\n<pre><code class=\"r\">diaDF[, 'pri'] \r\n<\/code><\/pre>\n<pre>## Error in `[.data.frame`(diaDF, , \"pri\"): undefined columns selected\r\n<\/pre>\n<pre><code class=\"r\">diaTB$pri \r\n<\/code><\/pre>\n<pre>## Warning: Unknown or uninitialised column: 'pri'.\r\n<\/pre>\n<pre>## NULL\r\n<\/pre>\n<pre><code class=\"r\">diaTB[, 'pri']\r\n<\/code><\/pre>\n<pre>## Error: Can't find column `pri` in `.data`.\r\n<\/pre>\n<ul>\n<li>\uadf8 \ubc16\uc5d0\ub3c4 \ud2f0\ube14\uc740 \uc0dd\uc131\uc2dc \ubb38\uc790\uc5f4\uc744 \ubc94\uc8fc\ud615(<code>factor<\/code>)\uc73c\ub85c \ubc14\uafb8\uc9c0 \uc54a\ub294\ub2e4\ub294 \ucc28\uc774\uac00 \uc788\ub2e4.<\/li>\n<\/ul>\n<pre><code class=\"r\">df &lt;- data.frame(a = c('Kim','Lee','Park'))\r\ntb &lt;- tibble(a = c('Kim','Lee','Park'))\r\n\r\nclass(df$a)\r\n<\/code><\/pre>\n<pre>## [1] \"factor\"\r\n<\/pre>\n<pre><code class=\"r\">class(tb$a)\r\n<\/code><\/pre>\n<pre>## [1] \"character\"\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>dplyr \ud328\ud0a4\uc9c0\ub97c \ud65c\uc6a9\ud55c \ub370\uc774\ud130 \uac00\uacf5 1: magrittr\uc758 \ud30c\uc774\ud504 \uc5f0\uc0b0\uc790 dplyr \ud328\ud0a4\uc9c0\uc758 \ud568\uc218\uacfc magrittr \ud328\ud0a4\uc9c0\uc758 %&gt;% \uc5f0\uc0b0\uc744 \ud568\uaed8 \ud65c\uc6a9\ud558\uba74 \ub370\uc774\ud130 \uac00\uacf5\uc774 \uac04\ub2e8\ud558\uace0 \uc774\ud574\ud558\uae30 \uc27d\ub2e4. \uc5ec\uae30\uc11c\ub294 \ud30c\uc774\ud504 \uc5f0\uc0b0\uc774\ub77c\uace0 \ubd88\ub9ac\ub294 %&gt;%\uc5d0 \ub300\ud574\uc11c \uc54c\uc544\ubcf8\ub2e4. dplyr \ud328\ud0a4\uc9c0\ub97c \ud65c\uc6a9\ud55c \ub370\uc774\ud130 \uc0ac\uc804\ucc98\ub9ac\uc758 \ubaa9\ucc28\ub294 \ub2e4\uc74c\uacfc \uac19\ub2e4. magrittr\uc758 %&gt;% dplyr\uc744 \uc0ac\uc6a9\ud55c \ubd80\ubd84 \ucc38\uc870 dplyr\uc744 \uc0ac\uc6a9\ud55c \uc218\uc815 dplyr\uc758 \uadf8 \ubc16\uc758 \ud3b8\uc758 \uae30\ub2a5 magrittr \ud328\ud0a4\uc9c0\uc758 \ud30c\uc774\ud504 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":2499,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[78,28],"tags":[71,70,72],"jetpack_featured_media_url":"http:\/\/ds.sumeun.org\/wp-content\/uploads\/2019\/01\/plate-g916e12a7b_640.jpg","_links":{"self":[{"href":"http:\/\/ds.sumeun.org\/index.php?rest_route=\/wp\/v2\/posts\/834"}],"collection":[{"href":"http:\/\/ds.sumeun.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/ds.sumeun.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/ds.sumeun.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/ds.sumeun.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=834"}],"version-history":[{"count":3,"href":"http:\/\/ds.sumeun.org\/index.php?rest_route=\/wp\/v2\/posts\/834\/revisions"}],"predecessor-version":[{"id":2500,"href":"http:\/\/ds.sumeun.org\/index.php?rest_route=\/wp\/v2\/posts\/834\/revisions\/2500"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/ds.sumeun.org\/index.php?rest_route=\/wp\/v2\/media\/2499"}],"wp:attachment":[{"href":"http:\/\/ds.sumeun.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=834"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/ds.sumeun.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=834"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/ds.sumeun.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=834"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}