{"id":497,"date":"2020-02-07T23:00:48","date_gmt":"2020-02-07T14:00:48","guid":{"rendered":"https:\/\/obgyn.jp\/?p=497"},"modified":"2022-03-13T19:56:09","modified_gmt":"2022-03-13T10:56:09","slug":"r-pivot-table","status":"publish","type":"post","link":"https:\/\/obgyn.jp\/?p=497","title":{"rendered":"R \u306b\u3088\u308b\u30af\u30ed\u30b9\u96c6\u8a08\u8868"},"content":{"rendered":"\n<p><a href=\"https:\/\/stat.ethz.ch\/R-manual\/R-devel\/library\/base\/html\/tapply.html\" rel=\"noopener noreferrer\" target=\"_blank\">taplly()<\/a> \u30b3\u30de\u30f3\u30c9\u3001<a href=\"https:\/\/stat.ethz.ch\/R-manual\/R-devel\/library\/base\/html\/table.html\" rel=\"noopener noreferrer\" target=\"_blank\">table()<\/a> \u30b3\u30de\u30f3\u30c9\u3092\u4f7f\u3044\u3001\u30af\u30ed\u30b9\u96c6\u8a08\u8868\u3092\u4f5c\u6210\u3059\u308b\u3002<\/p>\n\n\n\n<p>\u901a\u5e38\u306f Excel \u7b49\u3067\u4f5c\u6210\u3057\u305f CSV \u30d5\u30a1\u30a4\u30eb\u3092 R \u306b\u8aad\u307f\u8fbc\u3093\u3067\u5206\u6790\u3059\u308b\u3002\u3057\u304b\u3057\u3001\u3053\u3053\u3067\u306f\u4fbf\u5b9c\u7684\u306b\u4ee5\u4e0b\u306e\u7c21\u5358\u306a\u30c7\u30fc\u30bf\u30d5\u30ec\u30fc\u30e0\u3092\u4f5c\u6210\u3057\u3001data \u3068\u3044\u3046\u5909\u6570\u306b\u683c\u7d0d\u3057\u3066\u304a\u304f\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"r\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">data = data.frame(\u8853\u8005 = c(\"\u592a\u90ce\",\"\u82b1\u5b50\",\"\u592a\u90ce\",\"\u82b1\u5b50\",\"\u592a\u90ce\",\"\u82b1\u5b50\"), \u624b\u8853\u65b9\u6cd5 = c(\"\u5185\u8996\u93e1\",\"\u958b\u8179\",\"\u958b\u8179\",\"\u5185\u8996\u93e1\",\"\u5185\u8996\u93e1\",\"\u5185\u8996\u93e1\"), \u624b\u8853\u6642\u9593 = c(60,50,100,90,30,40), \u51fa\u8840\u91cf = c(15,25,35,55,45,25))<\/pre>\n\n\n\n<p>data \u306e\u5185\u5bb9\u3092\u78ba\u8a8d\u3059\u308b\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"r\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">data<\/pre>\n\n\n\n<p>\u8853\u8005\u3068\u624b\u8853\u65b9\u6cd5\u3067\u3001\u624b\u8853\u6642\u9593\u306e\u5e73\u5747\u3084\u3001\u51fa\u8840\u91cf\u306e\u5408\u8a08\u304c\u3069\u3046\u7570\u306a\u308b\u304b\u3092\u96c6\u8a08\u3059\u308b\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"r\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">tapply(data$\u624b\u8853\u6642\u9593, list(data$\u8853\u8005, data$\u624b\u8853\u65b9\u6cd5), mean) #\u624b\u8853\u6642\u9593\u306e\u5e73\u5747\ntapply(data$\u51fa\u8840\u91cf, list(data$\u8853\u8005, data$\u624b\u8853\u65b9\u6cd5), sum) #\u51fa\u8840\u91cf\u306e\u5408\u8a08<\/pre>\n\n\n\n<p>\u4ef6\u6570\u3092\u307f\u308b\u3060\u3051\u306e\u901a\u5e38\u306e\u30af\u30ed\u30b9\u96c6\u8a08\u306f <a href=\"https:\/\/stat.ethz.ch\/R-manual\/R-devel\/library\/base\/html\/table.html\" rel=\"noopener noreferrer\" target=\"_blank\">table()<\/a> \u30b3\u30de\u30f3\u30c9\u3092\u4f7f\u3063\u3066\u884c\u3046\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"r\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">table(data$\u8853\u8005, data$\u624b\u8853\u65b9\u6cd5)<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>taplly() \u30b3\u30de\u30f3\u30c9\u3001table() \u30b3\u30de\u30f3\u30c9\u3092\u4f7f\u3044\u3001\u30af\u30ed\u30b9\u96c6\u8a08\u8868\u3092\u4f5c\u6210\u3059\u308b\u3002 \u901a\u5e38\u306f Excel \u7b49\u3067\u4f5c\u6210\u3057\u305f CSV \u30d5\u30a1\u30a4\u30eb\u3092 R \u306b\u8aad\u307f\u8fbc\u3093\u3067\u5206\u6790\u3059\u308b\u3002\u3057\u304b\u3057\u3001\u3053\u3053\u3067\u306f\u4fbf\u5b9c\u7684\u306b\u4ee5\u4e0b\u306e\u7c21\u5358\u306a\u30c7\u30fc\u30bf\u30d5\u30ec\u30fc\u30e0\u3092\u4f5c &hellip; <a href=\"https:\/\/obgyn.jp\/?p=497\" class=\"more-link\">\u7d9a\u304d\u3092\u8aad\u3080 <span class=\"screen-reader-text\">R \u306b\u3088\u308b\u30af\u30ed\u30b9\u96c6\u8a08\u8868<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[37],"class_list":["post-497","post","type-post","status-publish","format-standard","hentry","category-data-science","tag-r"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/obgyn.jp\/index.php?rest_route=\/wp\/v2\/posts\/497","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/obgyn.jp\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/obgyn.jp\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/obgyn.jp\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/obgyn.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=497"}],"version-history":[{"count":7,"href":"https:\/\/obgyn.jp\/index.php?rest_route=\/wp\/v2\/posts\/497\/revisions"}],"predecessor-version":[{"id":1049,"href":"https:\/\/obgyn.jp\/index.php?rest_route=\/wp\/v2\/posts\/497\/revisions\/1049"}],"wp:attachment":[{"href":"https:\/\/obgyn.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=497"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/obgyn.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=497"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/obgyn.jp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=497"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}