{"id":180649,"date":"2024-05-08T20:39:32","date_gmt":"2024-05-08T12:39:32","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/180649.html"},"modified":"2024-05-08T20:39:37","modified_gmt":"2024-05-08T12:39:37","slug":"r-%e8%af%ad%e8%a8%80%e5%bf%85%e5%ad%a6%e7%9a%84-10-%e5%a4%a7%e5%8c%85%e6%98%af%e4%bb%80%e4%b9%88","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/180649.html","title":{"rendered":"R \u8bed\u8a00\u5fc5\u5b66\u7684 10 \u5927\u5305\u662f\u4ec0\u4e48"},"content":{"rendered":"<p style=\"text-align:center\"><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/27065955\/a4c5923d-0c99-484e-b7d9-19d25de68999.webp\" alt=\"R \u8bed\u8a00\u5fc5\u5b66\u7684 10 \u5927\u5305\u662f\u4ec0\u4e48\" \/><\/p>\n<p><p>R \u8bed\u8a00\u768410\u5927\u5fc5\u5b66\u5305\u5305\u62ec<strong>ggplot2\u3001dplyr\u3001tidyr\u3001readr\u3001purrr\u3001tibble\u3001stringr\u3001forcats\u3001lubridate\u3001httr<\/strong>\u3002\u5176\u4e2d\uff0c<strong>ggplot2<\/strong> \u662f\u8fdb\u884c\u9ad8\u7ea7\u56fe\u5f62\u5236\u4f5c\u7684\u5173\u952e\u5305\uff0c\u65e0\u8bba\u662f\u6570\u636e\u79d1\u5b66\u5bb6\u8fd8\u662f\u7edf\u8ba1\u5206\u6790\u5e08\uff0c\u90fd\u4f1a\u9891\u7e41\u4f7f\u7528 ggplot2 \u6765\u521b\u5efa\u9ad8\u8d28\u91cf\u7684\u56fe\u8868\u548c\u6570\u636e\u53ef\u89c6\u5316\u3002\u5b83\u57fa\u4e8e\u56fe\u5f62\u8bed\u6cd5\uff0c\u63d0\u4f9b\u4e86\u4e00\u4e2a\u5f3a\u5927\u4e14\u5bcc\u6709\u8868\u73b0\u529b\u7684\u6846\u67b6\u6765\u521b\u5efa\u591a\u5c42\u6b21\u56fe\u5f62\uff0c\u901a\u8fc7\u7b80\u5355\u7684\u547d\u4ee4\u5c31\u80fd\u751f\u6210\u590d\u6742\u7684\u591a\u56fe\u5c42\u56fe\u5f62\uff0c\u5e76\u4e14\u652f\u6301\u5927\u91cf\u7684\u5b9a\u5236\u5316\u9009\u9879\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001GGPLOT2<\/h3>\n<\/p>\n<p><p><strong>ggplot2<\/strong> \u7684\u6838\u5fc3\u601d\u60f3\u662f\u5b83\u6240\u8c13\u7684\u201c\u56fe\u5f62\u8bed\u6cd5\u201d\uff08Grammar of Graphics\uff09\uff0c\u8fd9\u610f\u5473\u7740\u60a8\u53ef\u4ee5\u901a\u8fc7\u4e00\u7cfb\u5217\u6709\u903b\u8f91\u7684\u6b65\u9aa4\u6765\u521b\u5efa\u56fe\u5f62\u3002\u7531\u4e8e\u5176\u591a\u6837\u6027\u548c\u53ef\u6269\u5c55\u6027\uff0cggplot2 \u88ab\u5e7f\u6cdb\u5e94\u7528\u4e8e\u5404\u79cd\u6570\u636e\u53ef\u89c6\u5316\u573a\u666f\u3002<\/p>\n<\/p>\n<ul>\n<li>\u521b\u5efa\u56fe\u5f62\u7684\u57fa\u672c\u6d41\u7a0b\uff1a\u9996\u5148\u6307\u5b9a\u6570\u636e\u96c6\u548c\u53d8\u91cf\u6620\u5c04\u5230\u56fe\u5f62\u7684\u7f8e\u5b66\u5c5e\u6027\u4e0a\uff0c\u7136\u540e\u6dfb\u52a0\u56fe\u5c42\u3001\u56fe\u5f62\u5143\u7d20\u548c\u5750\u6807\u7cfb\u7b49\u65b9\u9762\u7684\u5185\u5bb9\u3002<\/li>\n<li>\u9ad8\u7ea7\u7279\u6027\uff1aggplot2 \u8fd8\u652f\u6301\u7edf\u8ba1\u53d8\u6362\u3001\u9762\u677f\u7ed8\u5236\u3001\u4e3b\u9898\u8bbe\u8ba1\u7b49\u9ad8\u7ea7\u529f\u80fd\uff0c\u5927\u5927\u63d0\u5347\u4e86\u5236\u56fe\u7684\u52a8\u6001\u6027\u548c\u4e2a\u6027\u5316\u53ef\u80fd\u3002<\/li>\n<\/ul>\n<p><h3>\u4e8c\u3001DPLYR<\/h3>\n<\/p>\n<p><p><strong>dplyr<\/strong> \u662f\u4e00\u6b3e\u7528\u4e8e\u6570\u636e\u64cd\u4f5c\u7684\u5305\uff0c\u4e13\u6ce8\u4e8e\u5de5\u5177\u4f18\u5316\u548c\u6570\u636e\u5e27\u64cd\u4f5c\uff0c\u5b83\u4f7f\u5f97\u6570\u636e\u8f6c\u6362\u548c\u6458\u8981\u53d8\u5f97\u975e\u5e38\u5bb9\u6613\u3002<\/p>\n<\/p>\n<ul>\n<li>\u5173\u952e\u7684\u52a8\u8bcd\uff1adplyr \u63d0\u4f9b\u4e86\u4e00\u7ec4\u6613\u4e8e\u7406\u89e3\u7684\u201c\u52a8\u8bcd\u201d\u6765\u8fdb\u884c\u6570\u636e\u64cd\u4f5c\uff0c\u5305\u62ec filter\u3001select\u3001arrange\u3001mutate\u3001summarize \u7b49\u3002<\/li>\n<li>\u6548\u7387\u4e0e\u6613\u7528\u6027\uff1adplyr \u4f18\u5316\u4e86\u8fd9\u4e9b\u64cd\u4f5c\u7684\u6548\u7387\uff0c\u5e76\u4e0e\u7ba1\u9053\u64cd\u4f5c\u7b26 %&gt;% \u642d\u914d\u4f7f\u7528\uff0c\u7b80\u5316\u4e86\u4ee3\u7801\u7684\u7f16\u5199\u8fc7\u7a0b\u3002<\/li>\n<\/ul>\n<p><h3>\u4e09\u3001TIDYR<\/h3>\n<\/p>\n<p><p><strong>tidyr<\/strong> \u7528\u4e8e\u6574\u7406\u6570\u636e\uff0c\u4f7f\u5176\u66f4\u6613\u4e8e\u5206\u6790\u3002\u5b83\u63d0\u4f9b\u4e86\u7b80\u6d01\u7684\u51fd\u6570\uff0c\u4ee5\u5c06\u6570\u636e\u8f6c\u6362\u6210\u6574\u6d01\u5f62\u5f0f\u3002<\/p>\n<\/p>\n<ul>\n<li>\u6574\u6d01\u6570\u636e\u539f\u5219\uff1a\u6bcf\u4e2a\u53d8\u91cf\u5f62\u6210\u4e00\u5217\uff0c\u6bcf\u4e2a\u89c2\u5bdf\u5f62\u6210\u4e00\u884c\uff0c\u6bcf\u79cd\u7c7b\u578b\u7684\u89c2\u6d4b\u5355\u4f4d\u6784\u6210\u4e00\u4e2a\u8868\u683c\u3002<\/li>\n<li>\u6570\u636e\u6574\u7406\u529f\u80fd\uff1a\u4e3b\u8981\u7684\u51fd\u6570\u5305\u62ec gather\u3001spread\u3001separate \u548c unite\uff0c\u8fd9\u4e9b\u90fd\u662f\u5b9e\u73b0\u4ece\u5bbd\u683c\u5f0f\u5230\u957f\u683c\u5f0f\u6216\u53cd\u5411\u64cd\u4f5c\u7684\u5173\u952e\u3002<\/li>\n<\/ul>\n<p><h3>\u56db\u3001READR<\/h3>\n<\/p>\n<p><p><strong>readr<\/strong> \u88ab\u8bbe\u8ba1\u7528\u6765\u9ad8\u6548\u5730\u8bfb\u53d6\u548c\u5199\u5165\u6570\u636e\uff0c\u5c24\u5176\u662f\u5927\u578b\u6587\u672c\u6587\u4ef6\u3002<\/p>\n<\/p>\n<ul>\n<li>\u5feb\u901f\u4e14\u53cb\u597d\uff1areadr \u5305\u80fd\u591f\u6bd4 R \u9ed8\u8ba4\u7684\u6570\u636e\u8bfb\u53d6\u51fd\u6570\uff0c\u5982 read.table \u548c read.csv \u5feb\u5f97\u591a\uff0c\u800c\u4e14\u80fd\u5904\u7406\u5404\u79cd\u95ee\u9898\u3002<\/li>\n<li>\u6613\u4e8e\u4f7f\u7528\u7684\u7c7b\u578b\u5316\u5217\uff1areadr \u81ea\u52a8\u68c0\u6d4b\u5217\u7684\u7c7b\u578b\uff0c\u5e76\u5141\u8bb8\u4f7f\u7528\u66f4\u4e30\u5bcc\u7684\u5217\u7c7b\u578b\uff0c\u5982\u65e5\u671f\u65f6\u95f4\u7b49\u3002<\/li>\n<\/ul>\n<p><h3>\u4e94\u3001PURRR<\/h3>\n<\/p>\n<p><p><strong>purrr<\/strong> \u589e\u5f3a\u4e86 R \u7684\u51fd\u6570\u5f0f\u7f16\u7a0b\u80fd\u529b\uff0c\u5f15\u5165\u4e86\u4e00\u7cfb\u5217\u7684\u5de5\u5177\u6765\u5904\u7406\u51fd\u6570\u548c\u5411\u91cf\u3002<\/p>\n<\/p>\n<ul>\n<li>\u6613\u4e8e\u8fed\u4ee3\uff1a\u63d0\u4f9b\u4e86 map \u51fd\u6570\u65cf\u6765\u66ff\u4ee3 R \u4e2d\u7684 apply \u51fd\u6570\u65cf\uff0c\u8f85\u52a9\u66f4\u52a0\u76f4\u89c2\u5730\u5904\u7406\u5217\u8868\u548c\u5411\u91cf\u3002<\/li>\n<li>\u51fd\u6570\u5f0f\u7f16\u7a0b\u6838\u5fc3\uff1apurrr \u7740\u529b\u4e8e\u63d0\u5347\u5404\u79cd\u51fd\u6570\u64cd\u4f5c\u7684\u6548\u7387\u548c\u7b80\u5316\uff0c\u5b83\u7684\u8bbe\u8ba1\u5f3a\u8c03\u65e0\u526f\u4f5c\u7528\u548c\u51fd\u6570\u7684\u7eaf\u7cb9\u6027\u3002<\/li>\n<\/ul>\n<p><h3>\u516d\u3001TIBBLE<\/h3>\n<\/p>\n<p><p><strong>tibble<\/strong> \u662f\u4e3a\u4e86\u6570\u636e\u79d1\u5b66\u800c\u6539\u8fdb\u7684\u6570\u636e\u5e27\uff0c\u6bd4 R \u7684\u4f20\u7edf\u6570\u636e\u5e27\u66f4\u65b9\u4fbf\u3001\u7b80\u6d01\u3002<\/p>\n<\/p>\n<ul>\n<li>\u589e\u5f3a\u7684\u6570\u636e\u5e27\uff1a\u5b83\u5728\u6253\u5370\u548c\u5b50\u96c6\u5316\u64cd\u4f5c\u4e0a\u63d0\u4f9b\u4e86\u66f4\u76f4\u89c2\u548c\u66f4\u4e30\u5bcc\u7684\u4fe1\u606f\u3002<\/li>\n<li>\u517c\u5bb9 dplyr\uff1atibble \u5b8c\u7f8e\u517c\u5bb9 dplyr \u52a8\u8bcd\uff0c\u4f7f\u5f97\u6570\u636e\u64cd\u4f5c\u6d41\u7a0b\u66f4\u52a0\u987a\u7545\u3002<\/li>\n<\/ul>\n<p><h3>\u4e03\u3001STRINGR<\/h3>\n<\/p>\n<p><p><strong>stringr<\/strong> \u4e13\u6ce8\u4e8e\u73b0\u4ee3\u3001\u4e00\u81f4\u548c\u7b80\u5316\u7684\u5b57\u7b26\u4e32\u5904\u7406\u3002<\/p>\n<\/p>\n<ul>\n<li>\u6b63\u5219\u8868\u8fbe\u5f0f\u4e0e\u5b57\u7b26\u4e32\u5904\u7406\uff1astringr \u63d0\u4f9b\u4e86\u4e00\u5957\u6613\u4e8e\u7406\u89e3\u7684\u51fd\u6570\u6765\u5904\u7406\u6b63\u5219\u8868\u8fbe\u5f0f\u3002<\/li>\n<li>\u5b57\u7b26\u4e32\u64cd\u4f5c\u7684\u7b80\u5316\uff1a\u65e0\u8bba\u662f\u5b57\u7b26\u957f\u5ea6\u3001\u5339\u914d\u3001\u66ff\u6362\u8fd8\u662f\u62c6\u5206\uff0cstringr \u90fd\u80fd\u901a\u8fc7\u7b80\u5355\u7684\u51fd\u6570\u8c03\u7528\u5b8c\u6210\u3002<\/li>\n<\/ul>\n<p><h3>\u516b\u3001FORCATS<\/h3>\n<\/p>\n<p><p><strong>forcats<\/strong> \u7528\u4e8e\u5904\u7406\u56e0\u5b50\u53d8\u91cf\uff0c\u8fd9\u5bf9\u4e8e\u7edf\u8ba1\u5efa\u6a21\u548c\u6570\u636e\u53ef\u89c6\u5316\u6765\u8bf4\u6781\u5176\u91cd\u8981\u3002<\/p>\n<\/p>\n<ul>\n<li>\u56e0\u5b50\u7ea7\u522b\u7684\u7ba1\u7406\uff1a\u63d0\u4f9b\u4e86\u51fd\u6570\u6765\u6539\u53d8\u56e0\u5b50\u7684\u7ea7\u522b\u987a\u5e8f\uff0c\u5408\u5e76\u7ea7\u522b\u6216\u6539\u53d8\u56e0\u5b50\u7684\u7f16\u7801\u3002<\/li>\n<li>\u64cd\u4f5c\u7b80\u5355\u76f4\u89c2\uff1aforcats \u7684\u51fd\u6570\u7b80\u5316\u4e86\u8bb8\u591a\u4e0e\u56e0\u5b50\u76f8\u5173\u7684\u5e38\u89c1\u4efb\u52a1\u3002<\/li>\n<\/ul>\n<p><h3>\u4e5d\u3001LUBRIDATE<\/h3>\n<\/p>\n<p><p><strong>lubridate<\/strong> \u4f7f\u5f97\u5728 R \u4e2d\u5904\u7406\u65e5\u671f\u548c\u65f6\u95f4\u53d8\u5f97\u7b80\u5355\u6613\u884c\u3002<\/p>\n<\/p>\n<ul>\n<li>\u65e5\u671f\u65f6\u95f4\u89e3\u6790\uff1a\u5b83\u63d0\u4f9b\u4e86\u4e00\u7cfb\u5217\u51fd\u6570\u6765\u8f7b\u677e\u89e3\u6790\u548c\u5904\u7406\u65e5\u671f\u65f6\u95f4\u5bf9\u8c61\u3002<\/li>\n<li>\u64cd\u4f5c\u4fbf\u6377\uff1a\u65e0\u8bba\u662f\u65e5\u671f\u7684\u52a0\u51cf\u3001\u6301\u7eed\u65f6\u95f4\u7684\u8ba1\u7b97\uff0c\u8fd8\u662f\u65f6\u533a\u7684\u5904\u7406\uff0clubridate \u90fd\u80fd\u63d0\u4f9b\u5f3a\u5927\u7684\u652f\u6301\u3002<\/li>\n<\/ul>\n<p><h3>\u5341\u3001HTTR<\/h3>\n<\/p>\n<p><p><strong>httr<\/strong> \u7528\u4e8e\u4e0e HTTP \u534f\u8bae\u4ea4\u4e92\uff0c\u975e\u5e38\u9002\u5408\u8fdb\u884c\u7f51\u7edc\u8bf7\u6c42\u548c Web API \u4ea4\u4e92\u3002<\/p>\n<\/p>\n<ul>\n<li>\u7b80\u5316 HTTP \u8bf7\u6c42\uff1a\u5b83\u63d0\u4f9b\u4e86\u7528\u6237\u53cb\u597d\u7684\u51fd\u6570\u6765\u53d1\u9001 GET\u3001POST\u3001PUT \u548c DELETE \u8bf7\u6c42\u3002<\/li>\n<li>\u5904\u7406\u54cd\u5e94\uff1ahttr \u52a9\u60a8\u7b80\u5355\u5730\u5904\u7406\u54cd\u5e94\u5185\u5bb9\uff0c\u5305\u62ec\u72b6\u6001\u7801\u3001\u5185\u5bb9\u63d0\u53d6\u548c\u9519\u8bef\u5904\u7406\u3002<\/li>\n<\/ul>\n<p><p>\u901a\u8fc7\u5b66\u4e60\u548c\u638c\u63e1\u8fd9\u4e9b R \u8bed\u8a00\u5305\uff0c\u60a8\u5c06\u80fd\u591f\u5b8c\u6210\u6570\u636e\u79d1\u5b66\u9886\u57df\u4e2d\u7684\u591a\u6570\u4efb\u52a1\uff0c\u4ece\u6570\u636e\u5bfc\u5165\u3001\u6e05\u6d17\u3001\u8f6c\u6362\u3001\u53ef\u89c6\u5316\u5230\u6a21\u578b\u5206\u6790\uff0c\u90fd\u4f1a\u53d8\u5f97\u6d41\u7545\u548c\u9ad8\u6548\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p><strong>1. \u6709\u54ea\u4e9b\u5fc5\u5b66\u7684R\u8bed\u8a00\u5305\uff1f<\/strong><br \/>\nR\u8bed\u8a00\u7684\u5305\u662f\u4e00\u7cfb\u5217\u5c01\u88c5\u597d\u7684\u51fd\u6570\u548c\u6570\u636e\u96c6\uff0c\u80fd\u591f\u5e2e\u52a9\u5f00\u53d1\u8005\u5b8c\u6210\u7279\u5b9a\u7684\u4efb\u52a1\u3002\u5176\u4e2d\u503c\u5f97\u4e00\u63d0\u7684\u5fc5\u5b66R\u8bed\u8a00\u5305\u5305\u62ec\uff1aggplot2\u3001dplyr\u3001tidyr\u3001data.table\u3001caret\u3001stringr\u3001reshape2\u3001plyr\u3001lubridate\u548crmarkdown\u3002<\/p>\n<p><strong>2. \u4e3a\u4ec0\u4e48ggplot2\u662fR\u8bed\u8a00\u5fc5\u5b66\u7684\u5305\u4e4b\u4e00\uff1f<\/strong><br \/>\nggplot2\u662fR\u8bed\u8a00\u4e2d\u6700\u53d7\u6b22\u8fce\u7684\u6570\u636e\u53ef\u89c6\u5316\u5305\u4e4b\u4e00\u3002\u5b83\u63d0\u4f9b\u4e86\u5f3a\u5927\u7684\u56fe\u5f62\u7ed8\u5236\u529f\u80fd\uff0c\u53ef\u4ee5\u521b\u5efa\u4e13\u4e1a\u3001\u7f8e\u89c2\u3001\u53ef\u5b9a\u5236\u7684\u7edf\u8ba1\u56fe\u8868\u3002\u901a\u8fc7ggplot2\uff0c\u60a8\u53ef\u4ee5\u5feb\u901f\u5730\u521b\u5efa\u6563\u70b9\u56fe\u3001\u7ebf\u56fe\u3001\u67f1\u72b6\u56fe\u3001\u7bb1\u7ebf\u56fe\u7b49\u5404\u79cd\u56fe\u5f62\uff0c\u4f7f\u6570\u636e\u66f4\u52a0\u76f4\u89c2\u6613\u61c2\u3002<\/p>\n<p><strong>3. \u5982\u4f55\u4f7f\u7528dplyr\u5305\u8fdb\u884c\u6570\u636e\u5904\u7406\uff1f<\/strong><br \/>\ndplyr\u5305\u662fR\u8bed\u8a00\u4e2d\u975e\u5e38\u6d41\u884c\u7684\u6570\u636e\u5904\u7406\u5305\u4e4b\u4e00\u3002\u5b83\u63d0\u4f9b\u4e86\u4e00\u4e9b\u7b80\u6d01\u800c\u5f3a\u5927\u7684\u51fd\u6570\uff0c\u53ef\u4ee5\u5e2e\u52a9\u60a8\u5feb\u901f\u5730\u8fdb\u884c\u6570\u636e\u7684\u7b5b\u9009\u3001\u6392\u5e8f\u3001\u6574\u5408\u3001\u53d8\u5f62\u7b49\u64cd\u4f5c\u3002\u4f8b\u5982\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528dplyr\u4e2d\u7684filter\u51fd\u6570\u7b5b\u9009\u7279\u5b9a\u6761\u4ef6\u7684\u6570\u636e\uff0c\u4f7f\u7528select\u51fd\u6570\u9009\u62e9\u611f\u5174\u8da3\u7684\u53d8\u91cf\uff0c\u4f7f\u7528mutate\u51fd\u6570\u65b0\u589e\u6d3e\u751f\u53d8\u91cf\u7b49\u3002dplyr\u5305\u7684\u4f7f\u7528\u7b80\u6d01\u800c\u4f18\u96c5\uff0c\u80fd\u591f\u5927\u5927\u63d0\u9ad8\u6570\u636e\u5904\u7406\u7684\u6548\u7387\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"R \u8bed\u8a00\u768410\u5927\u5fc5\u5b66\u5305\u5305\u62ecggplot2\u3001dplyr\u3001tidyr\u3001readr\u3001purrr\u3001tibble\u3001str [&hellip;]","protected":false},"author":3,"featured_media":180653,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[37],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/180649"}],"collection":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/comments?post=180649"}],"version-history":[{"count":0,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/180649\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/180653"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=180649"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=180649"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=180649"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}