{"id":198,"date":"2023-11-11T06:32:19","date_gmt":"2023-11-10T21:32:19","guid":{"rendered":"http:\/\/bunseki-data.com\/r-onlinecourse\/?p=198"},"modified":"2023-11-11T06:37:13","modified_gmt":"2023-11-10T21:37:13","slug":"%e3%82%88%e3%81%8f%e3%81%82%e3%82%8b%e3%83%87%e3%83%bc%e3%82%bf%e5%89%8d%e5%87%a6%e7%90%86%e3%81%ae%e8%80%83%e3%81%88%e6%96%b9%e2%80%95%e3%82%a2%e3%83%b3%e3%82%b1%e3%83%bc%e3%83%88%e3%81%ae%e7%a8%ae","status":"publish","type":"post","link":"https:\/\/bunseki-data.com\/r-onlinecourse\/2023\/11\/11\/%e3%82%88%e3%81%8f%e3%81%82%e3%82%8b%e3%83%87%e3%83%bc%e3%82%bf%e5%89%8d%e5%87%a6%e7%90%86%e3%81%ae%e8%80%83%e3%81%88%e6%96%b9%e2%80%95%e3%82%a2%e3%83%b3%e3%82%b1%e3%83%bc%e3%83%88%e3%81%ae%e7%a8%ae\/","title":{"rendered":"\u3088\u304f\u3042\u308b\u30c7\u30fc\u30bf\u524d\u51e6\u7406\u306e\u8003\u3048\u65b9\u2015\u30a2\u30f3\u30b1\u30fc\u30c8\u306e\u7a2e\u985e\u3092\u5217\u540d\u306b\u5909\u63db\u3059\u308b-"},"content":{"rendered":"\n<pre class=\"wp-block-code\"><code>library(tidyverse)\nlibrary(knitr)\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"section_1\">\u3053\u306e\u8a18\u4e8b\u306e\u307e\u3068\u3081(\u3059\u3067\u306b\u8aad\u3093\u3060\u4eba\u5411\u3051)<\/h2>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img decoding=\"async\" width=\"1024\" height=\"576\" src=\"https:\/\/bunseki-data.com\/r-onlinecourse\/wp-content\/uploads\/2023\/11\/typetocol-1024x576.png\" alt=\"\" class=\"wp-image-201\" style=\"width:852px;height:auto\" srcset=\"https:\/\/bunseki-data.com\/r-onlinecourse\/wp-content\/uploads\/2023\/11\/typetocol-1024x576.png 1024w, https:\/\/bunseki-data.com\/r-onlinecourse\/wp-content\/uploads\/2023\/11\/typetocol-300x169.png 300w, https:\/\/bunseki-data.com\/r-onlinecourse\/wp-content\/uploads\/2023\/11\/typetocol-768x432.png 768w, https:\/\/bunseki-data.com\/r-onlinecourse\/wp-content\/uploads\/2023\/11\/typetocol.png 1280w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"section_2\">\u30c6\u30fc\u30de:\u5217\u306e\u30c7\u30fc\u30bf\u3092\u8907\u6570\u306e\u5217\u540d\u306b\u3057\u3066\u3068\u308a\u3060\u3059<\/h2>\n\n\n\n<p>\u30bf\u30a4\u30c8\u30eb\u3001\u30c6\u30fc\u30de\u540d\u3001\u3069\u3046\u3082\u3057\u3063\u304f\u308a\u6765\u306a\u3044\u3067\u3059\u304c\u3001\u4eca\u56de\u306f\u6b21\u306e\u3088\u3046\u306a\u30a2\u30f3\u30b1\u30fc\u30c8\u30c7\u30fc\u30bf\u3067\u3088\u304f\u906d\u9047\u3059\u308b\u30c7\u30fc\u30bf\u5f62\u5f0f\u306b\u3064\u3044\u3066\u306e\u524d\u51e6\u7406\u306e\u8a71\u3067\u3059\u3002\u3053\u306e\u30c7\u30fc\u30bf\u306e\u5f62\u3001Google Forms\u306e\u56de\u7b54\u306a\u3069\u3092\u6271\u3046\u3068\u304d\u306b\u3067\u3066\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u30a2\u30f3\u30b1\u30fc\u30c8\uff1a<\/p>\n\n\n\n<p>\u300c\u6b21\u306e\u81ea\u899a\u75c7\u72b6\u304b\u3089\u4eca\u3042\u308b\u3082\u306e\u3092\u6700\u59275\u3064\u307e\u3067\u9078\u3093\u3067\u304f\u3060\u3055\u3044\u300d<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>symp1<\/li>\n\n\n\n<li>symp2<\/li>\n\n\n\n<li>symp3<\/li>\n\n\n\n<li>symp4<\/li>\n\n\n\n<li>symp5<\/li>\n\n\n\n<li>symp6<\/li>\n\n\n\n<li>symp7<\/li>\n<\/ul>\n\n\n\n<p>\u8a18\u9332\u3055\u308c\u3066\u3044\u308b\u30c7\u30fc\u30bf\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>dat2 %&gt;% head() %&gt;% kable()\n<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>id<\/th><th>selection1<\/th><th>selection2<\/th><th>selection3<\/th><th>selection4<\/th><th>selection5<\/th><\/tr><\/thead><tbody><tr><td>1<\/td><td>symp2<\/td><td>symp3<\/td><td>symp4<\/td><td>symp5<\/td><td>NA<\/td><\/tr><tr><td>2<\/td><td>symp2<\/td><td>symp3<\/td><td>NA<\/td><td>NA<\/td><td>NA<\/td><\/tr><tr><td>3<\/td><td>symp1<\/td><td>symp3<\/td><td>symp4<\/td><td>symp5<\/td><td>NA<\/td><\/tr><tr><td>4<\/td><td>symp2<\/td><td>symp3<\/td><td>symp5<\/td><td>NA<\/td><td>NA<\/td><\/tr><tr><td>5<\/td><td>symp1<\/td><td>symp2<\/td><td>symp3<\/td><td>symp5<\/td><td>NA<\/td><\/tr><tr><td>6<\/td><td>symp1<\/td><td>symp2<\/td><td>symp3<\/td><td>symp4<\/td><td>symp5<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>\u3053\u306e\u5f62\u5f0f\u3001\u56de\u7b54\u8005\u304c\u3001\u4e00\u3064\u9078\u3093\u3060\u3089selection1\u5217\u306b\u9078\u3093\u3060\u9078\u629e\u304c\u8a18\u9332\u3002\u4e8c\u3064\u9078\u3093\u3060\u3089selection1\u5217\u3068selection2\u5217\u306b\u9078\u3093\u3060\u30c7\u30fc\u30bf\u304c\u8a18\u9332\u3055\u308c\u3066\u30fb\u30fb\u30fb<br>\u3068\u3044\u3046\u5f62\u3067\u3001\u6700\u59275\u500b\u307e\u3067\u30c7\u30fc\u30bf\u304c\u8a18\u9332\u3055\u308c\u3066\u30015\u500b\u672a\u6e80\u306e\u9078\u629e\u3067\u3042\u308c\u3070\u8db3\u308a\u306a\u3044\u5206\u304c\u6b20\u640d\u5024\u3068\u3057\u3066\u4fdd\u5b58\u3055\u308c\u308b\u3088\u3046\u306a\u30c7\u30fc\u30bf\u3067\u3059\u3002<\/p>\n\n\n\n<p>\u3053\u306e\u30d6\u30ed\u30b0\u8a18\u4e8b\u3067\u306f\u3001\u3053\u306e\u30c7\u30fc\u30bf\u3092\u3001<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>dat %&gt;% head() %&gt;% kable()\n<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>id<\/th><th>symp1<\/th><th>symp2<\/th><th>symp3<\/th><th>symp4<\/th><th>symp5<\/th><\/tr><\/thead><tbody><tr><td>1<\/td><td>0<\/td><td>1<\/td><td>1<\/td><td>1<\/td><td>1<\/td><\/tr><tr><td>2<\/td><td>0<\/td><td>1<\/td><td>1<\/td><td>0<\/td><td>0<\/td><\/tr><tr><td>3<\/td><td>1<\/td><td>0<\/td><td>1<\/td><td>1<\/td><td>1<\/td><\/tr><tr><td>4<\/td><td>0<\/td><td>1<\/td><td>1<\/td><td>0<\/td><td>1<\/td><\/tr><tr><td>5<\/td><td>1<\/td><td>1<\/td><td>1<\/td><td>0<\/td><td>1<\/td><\/tr><tr><td>6<\/td><td>1<\/td><td>1<\/td><td>1<\/td><td>1<\/td><td>1<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>\u3053\u3093\u306a\u611f\u3058\u3067ID\u6bce\u306b\u3001\u305d\u308c\u305e\u308c\u306e\u75c7\u72b6\uff08symp1~6\uff09\u307e\u3067\u3092\u9078\u3093\u3060\u304b\u305d\u3046\u3067\u306a\u3044\u304b\u306e\u30c7\u30fc\u30bf\u306b\u5909\u63db\u3059\u308b\u65b9\u6cd5\u3092\u8003\u3048\u3066\u3044\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<p>\uff08\u5c1a\u3001dat\u3068dat2\u3092\u4f5c\u6210\u3057\u305f\u30b9\u30af\u30ea\u30d7\u30c8\u306f\u3053\u306e\u8a18\u4e8b\u306b\u4e00\u756a\u6700\u5f8c\u306e\u88dc\u8db3\u90e8\u5206\u306b\u63b2\u8f09\u3057\u3066\u3042\u308a\u307e\u3059\uff09<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"1\">\u624b\u98061: \u7e26\u306b\u4e26\u3079\u308b<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>dat2\n<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\">## # A tibble: 100 \u00d7 6\n##       id selection1 selection2 selection3 selection4 selection5\n##    &lt;int&gt; &lt;chr&gt;      &lt;chr&gt;      &lt;chr&gt;      &lt;chr&gt;      &lt;chr&gt;     \n##  1     1 symp2      symp3      symp4      symp5      &lt;NA&gt;      \n##  2     2 symp2      symp3      &lt;NA&gt;       &lt;NA&gt;       &lt;NA&gt;      \n##  3     3 symp1      symp3      symp4      symp5      &lt;NA&gt;      \n##  4     4 symp2      symp3      symp5      &lt;NA&gt;       &lt;NA&gt;      \n##  5     5 symp1      symp2      symp3      symp5      &lt;NA&gt;      \n##  6     6 symp1      symp2      symp3      symp4      symp5     \n##  7     7 symp1      symp2      symp3      symp5      &lt;NA&gt;      \n##  8     8 symp2      symp3      symp5      &lt;NA&gt;       &lt;NA&gt;      \n##  9     9 symp1      symp5      &lt;NA&gt;       &lt;NA&gt;       &lt;NA&gt;      \n## 10    10 symp2      symp3      symp4      symp5      &lt;NA&gt;      \n## # \u2139 90 more rows\n<\/pre>\n\n\n\n<p>\u307e\u305a\u306f\u3001\u6a2a\u306b\u9577\u3044\u30c7\u30fc\u30bf\u306b\u5bfe\u3057\u3066\u306e\u4f5c\u6226\u306e\u521d\u624b\u3068\u3057\u3066\u306f\u3001\u7e26\u306b\u4e26\u3079\u307e\u3057\u3087\u3046\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>dat2 %&gt;% \n  pivot_longer(cols = -id)\n<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\">## # A tibble: 500 \u00d7 3\n##       id name       value\n##    &lt;int&gt; &lt;chr&gt;      &lt;chr&gt;\n##  1     1 selection1 symp2\n##  2     1 selection2 symp3\n##  3     1 selection3 symp4\n##  4     1 selection4 symp5\n##  5     1 selection5 &lt;NA&gt; \n##  6     2 selection1 symp2\n##  7     2 selection2 symp3\n##  8     2 selection3 &lt;NA&gt; \n##  9     2 selection4 &lt;NA&gt; \n## 10     2 selection5 &lt;NA&gt; \n## # \u2139 490 more rows\n<\/pre>\n\n\n\n<p>\u3053\u3046\u3059\u308b\u3068\u3001id\u3001\u5217\u540d\u3001\u5024\u306e\u9806\u756a\u306b\u3069\u3093\u306a\u306b\u6a2a\u306b\u5e83\u3044\u30c7\u30fc\u30bf\u3067\u3082\u30013\u5217\u306b\u4e26\u3079\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u305d\u306e\u5f8c\u3001value\u306eNA\u306f\u3044\u3089\u306a\u3044\u306e\u3067\u3001\u6d88\u3057\u3066\u3042\u3052\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>dat2 %&gt;% \n  pivot_longer(cols = -id) %&gt;% \n  filter(!is.na(value))\n<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\">## # A tibble: 302 \u00d7 3\n##       id name       value\n##    &lt;int&gt; &lt;chr&gt;      &lt;chr&gt;\n##  1     1 selection1 symp2\n##  2     1 selection2 symp3\n##  3     1 selection3 symp4\n##  4     1 selection4 symp5\n##  5     2 selection1 symp2\n##  6     2 selection2 symp3\n##  7     3 selection1 symp1\n##  8     3 selection2 symp3\n##  9     3 selection3 symp4\n## 10     3 selection4 symp5\n## # \u2139 292 more rows\n<\/pre>\n\n\n\n<p>\u3053\u3053\u3067\u3001\u6a2a\u306b\u5e83\u3052\u3066\u3042\u3052\u308c\u3070\u5b8c\u6210\uff01\u306a\u306e\u3067\u3059\u304c\u3001\u3053\u3053\u3067\u4e00\u5de5\u592b\u3059\u308b\u3053\u3068\u3067\u30010\u30681\u306e\u30c7\u30fc\u30bf\u306b\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u5de5\u592b\u3068\u306f\u3001\u5358\u7d14\u306b<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>dat2 %&gt;% \n  pivot_longer(cols = -id) %&gt;% \n  filter(!is.na(value)) %&gt;% \n  mutate(temp = 1)\n<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\">## # A tibble: 302 \u00d7 4\n##       id name       value  temp\n##    &lt;int&gt; &lt;chr&gt;      &lt;chr&gt; &lt;dbl&gt;\n##  1     1 selection1 symp2     1\n##  2     1 selection2 symp3     1\n##  3     1 selection3 symp4     1\n##  4     1 selection4 symp5     1\n##  5     2 selection1 symp2     1\n##  6     2 selection2 symp3     1\n##  7     3 selection1 symp1     1\n##  8     3 selection2 symp3     1\n##  9     3 selection3 symp4     1\n## 10     3 selection4 symp5     1\n## # \u2139 292 more rows\n<\/pre>\n\n\n\n<p>\u3068\u3001\u3059\u3079\u3066\u306e\u5217\u306b1\u3068\u3044\u3046\u6570\u5b57\u3092\u4e0e\u3048\u308b\u3060\u3051\u3067\u3059\u3002<br>\u3053\u3046\u3059\u308b\u3068\u3001\u3042\u3068\u306f\u3001name\u5217\u306f\u5fc5\u8981\u306a\u304f\u306a\u308b\u306e\u3067\u3001<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>dat2 %&gt;% \n  pivot_longer(cols = -id) %&gt;% \n  filter(!is.na(value)) %&gt;% \n  mutate(temp = 1) %&gt;% \n  select(-name)\n<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\">## # A tibble: 302 \u00d7 3\n##       id value  temp\n##    &lt;int&gt; &lt;chr&gt; &lt;dbl&gt;\n##  1     1 symp2     1\n##  2     1 symp3     1\n##  3     1 symp4     1\n##  4     1 symp5     1\n##  5     2 symp2     1\n##  6     2 symp3     1\n##  7     3 symp1     1\n##  8     3 symp3     1\n##  9     3 symp4     1\n## 10     3 symp5     1\n## # \u2139 292 more rows\n<\/pre>\n\n\n\n<p>\u9664\u53bb\u3057\u3066\u3042\u3052\u3066\u3001\u6a2a\u65b9\u5411\u306b\u4e26\u3079\u3066\u3042\u3052\u308b\u3068\u3001<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>dat2 %&gt;% \n  pivot_longer(cols = -id) %&gt;% \n  filter(!is.na(value)) %&gt;% \n  mutate(temp = 1) %&gt;% \n  select(-name) %&gt;% \n  pivot_wider(id_cols = id, names_from = value, values_from = temp)\n<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\">## # A tibble: 100 \u00d7 6\n##       id symp2 symp3 symp4 symp5 symp1\n##    &lt;int&gt; &lt;dbl&gt; &lt;dbl&gt; &lt;dbl&gt; &lt;dbl&gt; &lt;dbl&gt;\n##  1     1     1     1     1     1    NA\n##  2     2     1     1    NA    NA    NA\n##  3     3    NA     1     1     1     1\n##  4     4     1     1    NA     1    NA\n##  5     5     1     1    NA     1     1\n##  6     6     1     1     1     1     1\n##  7     7     1     1    NA     1     1\n##  8     8     1     1    NA     1    NA\n##  9     9    NA    NA    NA     1     1\n## 10    10     1     1     1     1    NA\n## # \u2139 90 more rows\n<\/pre>\n\n\n\n<p>\u3044\u3044\u611f\u3058\u3067\u3059\u306d\uff1f\u305f\u3060\u3001\u300c\u306a\u3044\u300d\u30c7\u30fc\u30bf\u304cNA\u3068\u306a\u3063\u3066\u3057\u307e\u3063\u3066\u3044\u308b\u306e\u3067\u3001pivot_wider\u306eArgument\u3092\u3044\u3058\u3063\u3066\u3042\u3052\u3066<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>dat2 %&gt;% \n  pivot_longer(cols = -id) %&gt;% \n  filter(!is.na(value)) %&gt;% \n  mutate(temp = 1) %&gt;% \n  select(-name) %&gt;% \n  pivot_wider(id_cols = id, names_from = value, \n              values_from = temp, values_fill = 0)\n<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\">## # A tibble: 100 \u00d7 6\n##       id symp2 symp3 symp4 symp5 symp1\n##    &lt;int&gt; &lt;dbl&gt; &lt;dbl&gt; &lt;dbl&gt; &lt;dbl&gt; &lt;dbl&gt;\n##  1     1     1     1     1     1     0\n##  2     2     1     1     0     0     0\n##  3     3     0     1     1     1     1\n##  4     4     1     1     0     1     0\n##  5     5     1     1     0     1     1\n##  6     6     1     1     1     1     1\n##  7     7     1     1     0     1     1\n##  8     8     1     1     0     1     0\n##  9     9     0     0     0     1     1\n## 10    10     1     1     1     1     0\n## # \u2139 90 more rows\n<\/pre>\n\n\n\n<p>values_fill\u306b\u5024\u30920\u3068\u3057\u3066\u4e0e\u3048\u3066\u3042\u3052\u308b\u3068\u3001\u3053\u3093\u306a\u611f\u3058\u3067\u3059\u3002<\/p>\n\n\n\n<p>\u5f8c\u306f\u3001\u5217\u306e\u578b\u304cdbl\u3068\u306a\u3063\u3066\u3044\u308b\u306e\u3067\u5c11\u3057\u6c17\u6301\u3061\u60aa\u3044\u306e\u3067\u3001<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>dat2 %&gt;% \n  pivot_longer(cols = -id) %&gt;% \n  filter(!is.na(value)) %&gt;% \n  mutate(temp = 1) %&gt;% \n  select(-name) %&gt;% \n  pivot_wider(id_cols = id, names_from = value, \n              values_from = temp, values_fill = 0) %&gt;% \n  mutate(across(cols = -id, .fns = as.integer))\n<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\">## Warning: There was 1 warning in `mutate()`.\n## \u2139 In argument: `across(cols = -id, .fns = as.integer)`.\n## Caused by warning:\n## ! The `...` argument of `across()` is deprecated as of dplyr\n##   1.1.0.\n## Supply arguments directly to `.fns` through an anonymous\n## function instead.\n## \n##   # Previously\n##   across(a:b, mean, na.rm = TRUE)\n## \n##   # Now\n##   across(a:b, \\(x) mean(x, na.rm = TRUE))\n<\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\">## # A tibble: 100 \u00d7 6\n##       id symp2 symp3 symp4 symp5 symp1\n##    &lt;int&gt; &lt;int&gt; &lt;int&gt; &lt;int&gt; &lt;int&gt; &lt;int&gt;\n##  1     1     1     1     1     1     0\n##  2     2     1     1     0     0     0\n##  3     3     0     1     1     1     1\n##  4     4     1     1     0     1     0\n##  5     5     1     1     0     1     1\n##  6     6     1     1     1     1     1\n##  7     7     1     1     0     1     1\n##  8     8     1     1     0     1     0\n##  9     9     0     0     0     1     1\n## 10    10     1     1     1     1     0\n## # \u2139 90 more rows\n<\/pre>\n\n\n\n<p>\u3068\u3057\u3066\u3042\u3052\u308b\u3053\u3068\u3067\u3001\u3059\u3079\u30660\u30681\u306eInteger\u578b\u306e\u30c7\u30fc\u30bf\u3068\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3057\u305f\uff01<\/p>\n\n\n\n<p>\u6700\u7d42\u7684\u306a\u30b9\u30af\u30ea\u30d7\u30c8\u304c8\u884c\u306a\u306e\u3067\u3059\u304c\u3001\u3053\u306e\u30b9\u30af\u30ea\u30d7\u30c8\u3001\u6b21\u306e\u3088\u3046\u306b\u95a2\u6570\u5316\u3057\u3066\u304a\u304f\u3068\u3001<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>convert_selection_to_wider &lt;- function(original_data, id_col){\n  enq_id &lt;- enquo(id_col)\n  \n  return_this &lt;- original_data %&gt;% \n    pivot_longer(cols = -!!enq_id) %&gt;% \n    filter(!is.na(value)) %&gt;% \n    mutate(temp = 1) %&gt;% \n    select(-name) %&gt;% \n    pivot_wider(id_cols = !!enq_id, names_from = value, \n                values_from = temp, values_fill = 0) %&gt;% \n    mutate(across(cols = -!!enq_id, .fns = as.integer))\n  \n  return(return_this)\n}\n<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>dat2\n<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\">## # A tibble: 100 \u00d7 6\n##       id selection1 selection2 selection3 selection4 selection5\n##    &lt;int&gt; &lt;chr&gt;      &lt;chr&gt;      &lt;chr&gt;      &lt;chr&gt;      &lt;chr&gt;     \n##  1     1 symp2      symp3      symp4      symp5      &lt;NA&gt;      \n##  2     2 symp2      symp3      &lt;NA&gt;       &lt;NA&gt;       &lt;NA&gt;      \n##  3     3 symp1      symp3      symp4      symp5      &lt;NA&gt;      \n##  4     4 symp2      symp3      symp5      &lt;NA&gt;       &lt;NA&gt;      \n##  5     5 symp1      symp2      symp3      symp5      &lt;NA&gt;      \n##  6     6 symp1      symp2      symp3      symp4      symp5     \n##  7     7 symp1      symp2      symp3      symp5      &lt;NA&gt;      \n##  8     8 symp2      symp3      symp5      &lt;NA&gt;       &lt;NA&gt;      \n##  9     9 symp1      symp5      &lt;NA&gt;       &lt;NA&gt;       &lt;NA&gt;      \n## 10    10 symp2      symp3      symp4      symp5      &lt;NA&gt;      \n## # \u2139 90 more rows\n<\/pre>\n\n\n\n<p>\u3053\u3093\u306a\u30c7\u30fc\u30bf\u3092<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>dat2 %&gt;% \n  convert_selection_to_wider(id)\n<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\">## # A tibble: 100 \u00d7 6\n##       id symp2 symp3 symp4 symp5 symp1\n##    &lt;int&gt; &lt;int&gt; &lt;int&gt; &lt;int&gt; &lt;int&gt; &lt;int&gt;\n##  1     1     1     1     1     1     0\n##  2     2     1     1     0     0     0\n##  3     3     0     1     1     1     1\n##  4     4     1     1     0     1     0\n##  5     5     1     1     0     1     1\n##  6     6     1     1     1     1     1\n##  7     7     1     1     0     1     1\n##  8     8     1     1     0     1     0\n##  9     9     0     0     0     1     1\n## 10    10     1     1     1     1     0\n## # \u2139 90 more rows\n<\/pre>\n\n\n\n<p>\u3053\u3093\u306a\u611f\u3058\u3067\u5909\u63db\u3059\u308b\u3053\u3068\u304c\u53ef\u80fd\u3067\u3059\u3002<br>\u5909\u63db\u3057\u305f\u3082\u306e\u306f\u3042\u3068\u306fID\u3092\u5229\u7528\u3057\u3066\u3001\u5927\u5143\u306e\u30c7\u30fc\u30bf\u306bJOIN\u95a2\u6570\u3067\u623b\u3057\u3066\u3042\u3052\u308b\u3068\u3001glm\u3084lm\u95a2\u6570\u7b49\u3067\u5206\u6790\u3059\u308b\u518d\u306b\u697d\u306b\u5229\u7528\u3067\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u4ee5\u4e0a\u3001\u7c21\u5358\u306b\u3067\u3059\u304c\u3001\u4ee5\u5916\u3068\u4fbf\u5229\u306a\u30c6\u30af\u30cb\u30c3\u30af\u3092\u3054\u7d39\u4ecb\u3057\u307e\u3057\u305f\u3002<\/p>\n\n\n\n<p>\uff08\u6ce8:\u3082\u3057\u3082\u3063\u3068\u4fbf\u5229\u306a\u65b9\u6cd5\u304c\u3042\u308b\u7b49\u3042\u308a\u307e\u3057\u305f\u3089\u6559\u3048\u3066\u3044\u305f\u3060\u3051\u308c\u3070\u5b09\u3057\u3044\u3067\u3059\uff09<br>Have a happy R life!<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"section_3\">\u88dc\u8db3:<\/h3>\n\n\n\n<p>\u3061\u306a\u307f\u306b\u3001\u4eca\u56de\u4f8b\u3068\u3057\u3066\u5229\u7528\u3057\u305f\u30c7\u30fc\u30bf\u306e\u4f5c\u6210\u306f\u6b21\u306e\u30b9\u30af\u30ea\u30d7\u30c8\u306b\u3088\u308b\u3082\u306e\u3067\u3059\u3002<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-r\" data-lang=\"R\"><code>set.seed(100)\ndat &lt;- tibble(\n  id = 1:100,\n  symp1 = runif(100,0,1) &gt;= 0.4,\n  symp2 = runif(100,0,1) &gt;= 0.3,\n  symp3 = runif(100,0,1) &gt;= 0.2,\n  symp4 = runif(100,0,1) &gt;= 0.8,\n  symp5 = runif(100,0,1) &gt;= 0.3\n) %&gt;% \n  mutate(across(.fns = as.integer))\n  \n\ndat2 &lt;- dat %&gt;% \n  pivot_longer(cols = -id) %&gt;% \n  filter(value == 1) %&gt;% \n  group_by(id) %&gt;% \n  nest() %&gt;% \n  mutate(wide = map(data, ~{\n    tibble(\n      selection1 = .$name[1],\n      selection2 = .$name[2],\n      selection3 = .$name[3],\n      selection4 = .$name[4],\n      selection5 = .$name[5],\n      selection6 = .$name[6],\n      selection7 = .$name[7]\n    )    \n  })) %&gt;% \n  select(-data) %&gt;% \n  unnest(wide) %&gt;% \n  ungroup()\n<\/code><\/pre><\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u3053\u306e\u8a18\u4e8b\u306e\u307e\u3068\u3081(\u3059\u3067\u306b\u8aad\u3093\u3060\u4eba\u5411\u3051) \u30c6\u30fc\u30de:\u5217\u306e\u30c7\u30fc\u30bf\u3092\u8907\u6570\u306e\u5217\u540d\u306b\u3057\u3066\u3068\u308a\u3060\u3059 \u30bf\u30a4\u30c8\u30eb\u3001\u30c6\u30fc\u30de\u540d\u3001\u3069\u3046\u3082\u3057\u3063\u304f\u308a\u6765\u306a\u3044\u3067\u3059\u304c\u3001\u4eca\u56de\u306f\u6b21\u306e\u3088\u3046\u306a\u30a2\u30f3\u30b1\u30fc\u30c8\u30c7\u30fc\u30bf\u3067\u3088\u304f\u906d\u9047\u3059\u308b\u30c7\u30fc\u30bf\u5f62\u5f0f\u306b\u3064\u3044\u3066\u306e\u524d\u51e6\u7406\u306e\u8a71\u3067\u3059\u3002\u3053\u306e\u30c7\u30fc\u30bf\u306e\u5f62\u3001Google Forms\u306e\u56de\u7b54\u306a\u3069\u3092\u6271\u3046\u3068\u304d\u306b\u3067\u3066\u304d\u307e\u3059\u3002 \u30a2\u30f3\u30b1\u30fc\u30c8\uff1a \u300c\u6b21\u306e\u81ea\u899a\u75c7\u72b6\u304b\u3089\u4eca\u3042\u308b\u3082\u306e\u3092\u6700\u59275\u3064\u307e\u3067\u9078\u3093\u3067\u304f\u3060\u3055\u3044\u300d \u8a18\u9332\u3055\u308c\u3066\u3044\u308b\u30c7\u30fc\u30bf\uff1a id selection1 selection2 selection3 selection4 selection5 1 symp2 symp3 symp4 symp5 NA 2 symp2 symp3 NA NA NA 3 symp1 symp3 symp4 symp5 NA 4 symp2 symp3 symp5 NA NA 5 symp1 symp2 symp3 symp5 NA 6 symp1 symp2 symp3 symp4 symp5 \u3053\u306e\u5f62\u5f0f\u3001\u56de\u7b54\u8005\u304c\u3001\u4e00\u3064\u9078\u3093\u3060\u3089selection1\u5217\u306b\u9078\u3093\u3060\u9078\u629e\u304c\u8a18\u9332\u3002\u4e8c\u3064\u9078\u3093\u3060\u3089selection1\u5217\u3068selection2\u5217\u306b\u9078\u3093\u3060\u30c7\u30fc\u30bf\u304c\u8a18\u9332\u3055\u308c\u3066\u30fb\u30fb\u30fb\u3068\u3044\u3046\u5f62\u3067\u3001\u6700\u59275\u500b\u307e\u3067\u30c7\u30fc\u30bf\u304c\u8a18\u9332\u3055\u308c\u3066\u30015\u500b\u672a\u6e80\u306e\u9078\u629e\u3067\u3042\u308c\u3070\u8db3\u308a\u306a\u3044\u5206\u304c\u6b20\u640d\u5024\u3068\u3057\u3066\u4fdd\u5b58\u3055\u308c\u308b\u3088\u3046\u306a\u30c7\u30fc\u30bf\u3067\u3059\u3002 \u3053\u306e\u30d6\u30ed\u30b0\u8a18\u4e8b\u3067\u306f\u3001\u3053\u306e\u30c7\u30fc\u30bf\u3092\u3001 id symp1 symp2 symp3 symp4 symp5 1 0 1 1 1 1 2 0 1 1 0 0 3 1 0 1 1 1 4 0 1 1 0 1 5 1 1 1 0 1 6 1 1 1 1 1 \u3053\u3093\u306a\u611f\u3058\u3067ID\u6bce\u306b\u3001\u305d\u308c\u305e\u308c\u306e\u75c7\u72b6\uff08symp1~6\uff09\u307e\u3067\u3092\u9078\u3093\u3060\u304b\u305d\u3046\u3067\u306a\u3044\u304b\u306e\u30c7\u30fc\u30bf\u306b\u5909\u63db\u3059\u308b\u65b9\u6cd5\u3092\u8003\u3048\u3066\u3044\u304d\u307e\u3059\u3002 \uff08\u5c1a\u3001dat\u3068dat2\u3092\u4f5c\u6210\u3057\u305f\u30b9\u30af\u30ea\u30d7\u30c8\u306f\u3053\u306e\u8a18\u4e8b\u306b\u4e00\u756a\u6700\u5f8c\u306e\u88dc\u8db3\u90e8\u5206\u306b\u63b2\u8f09\u3057\u3066\u3042\u308a\u307e\u3059\uff09 \u624b\u98061: \u7e26\u306b\u4e26\u3079\u308b ## # A tibble: 100 \u00d7 6 ## id selection1 selection2 selection3 selection4 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"swell_btn_cv_data":"","footnotes":""},"categories":[7],"tags":[],"class_list":["post-198","post","type-post","status-publish","format-standard","hentry","category-7"],"_links":{"self":[{"href":"https:\/\/bunseki-data.com\/r-onlinecourse\/wp-json\/wp\/v2\/posts\/198","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/bunseki-data.com\/r-onlinecourse\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/bunseki-data.com\/r-onlinecourse\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/bunseki-data.com\/r-onlinecourse\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/bunseki-data.com\/r-onlinecourse\/wp-json\/wp\/v2\/comments?post=198"}],"version-history":[{"count":2,"href":"https:\/\/bunseki-data.com\/r-onlinecourse\/wp-json\/wp\/v2\/posts\/198\/revisions"}],"predecessor-version":[{"id":202,"href":"https:\/\/bunseki-data.com\/r-onlinecourse\/wp-json\/wp\/v2\/posts\/198\/revisions\/202"}],"wp:attachment":[{"href":"https:\/\/bunseki-data.com\/r-onlinecourse\/wp-json\/wp\/v2\/media?parent=198"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/bunseki-data.com\/r-onlinecourse\/wp-json\/wp\/v2\/categories?post=198"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/bunseki-data.com\/r-onlinecourse\/wp-json\/wp\/v2\/tags?post=198"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}