{"id":471,"date":"2023-07-29T19:32:18","date_gmt":"2023-07-29T19:32:18","guid":{"rendered":"https:\/\/statorials.org\/cn\/r-max-%e5%af%b9%e5%9b%a0%e5%ad%90%e4%b8%8d%e6%98%be%e7%9d%80\/"},"modified":"2023-07-29T19:32:18","modified_gmt":"2023-07-29T19:32:18","slug":"r-max-%e5%af%b9%e5%9b%a0%e5%ad%90%e4%b8%8d%e6%98%be%e7%9d%80","status":"publish","type":"post","link":"https:\/\/statorials.org\/cn\/r-max-%e5%af%b9%e5%9b%a0%e5%ad%90%e4%b8%8d%e6%98%be%e7%9d%80\/","title":{"rendered":"R \u4e2d\u9519\u8bef\u7684\u89e3\u91ca\uff1a\u201cmax\u201d\u5bf9\u4e8e\u56e0\u5b50\u800c\u8a00\u4e0d\u663e\u7740"},"content":{"rendered":"<p><\/p>\n<hr>\n<p><span style=\"color: #000000;\">\u6709\u65f6\uff0c\u60a8\u53ef\u80fd\u4f1a\u5728 R \u4e2d\u9047\u5230\u4ee5\u4e0b\u9519\u8bef\uff1a<\/span><\/p>\n<pre style=\"background-color: #e5e5e5; font-size: 15px;\"> <strong>'max' not meaningful for factors<\/strong><\/pre>\n<p><span style=\"color: #000000;\">\u8fd9\u53ea\u662f\u8868\u660e\u60a8\u6b63\u5728\u5c1d\u8bd5\u83b7\u53d6\u5c5e\u4e8e\u7c7b<strong>\u56e0\u5b50\u7684<\/strong>\u53d8\u91cf\u7684\u201c\u6700\u5927\u503c\u201d\u3002<\/span><\/p>\n<p><span style=\"color: #000000;\">\u4f8b\u5982\uff0c\u5982\u679c\u6211\u4eec\u5c1d\u8bd5\u53d6\u4ee5\u4e0b\u5411\u91cf\u7684\u6700\u5927\u503c\uff0c\u5c31\u4f1a\u751f\u6210\u6b64\u9519\u8bef\uff1a<\/span><\/p>\n<pre style=\"background-color: #e5e5e5; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#create a vector of class <em>vector\n<\/em><\/span>factor_vector &lt;- as.factor(c(1, 7, 12, 14, 15))\n\n<span style=\"color: #008080;\">#attempt to find max value in the vector<\/span>\nmax(factor_vector)\n\n#Error in Summary.factor(1:5, na.rm = FALSE): \n# 'max' not meaningful for factors<\/strong><\/pre>\n<p><span style=\"color: #000000;\">\u6839\u636e\u5b9a\u4e49\uff0c\u56e0\u5b50\u5411\u91cf\u7684\u503c\u5c5e\u4e8e\u540d\u4e49\u7c7b\uff0c\u8fd9\u610f\u5473\u7740\u8fd9\u4e9b\u503c\u6ca1\u6709\u6709\u610f\u4e49\u7684\u987a\u5e8f\u3002\u6240\u4ee5\u6ca1\u6709\u627e\u5230\u201c\u6700\u5927\u503c\u201d\u3002<\/span><\/p>\n<p><span style=\"color: #000000;\">\u67e5\u627e\u56e0\u5b50\u5411\u91cf\u6700\u5927\u503c\u7684\u4e00\u4e2a\u7b80\u5355\u89e3\u51b3\u65b9\u6848\u662f\u5c06\u5176\u7b80\u5355\u5730\u8f6c\u6362\u4e3a\u5b57\u7b26\u5411\u91cf\uff0c\u7136\u540e\u8f6c\u6362\u4e3a\u6570\u5b57\u5411\u91cf\uff1a<\/span><\/p>\n<pre style=\"background-color: #e5e5e5; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#convert factor vector to numeric vector and find the max value<\/span>\nnew_vector &lt;- as.numeric(as.character(factor_vector))\nmax(new_vector)\n\n#[1] 15<\/strong><\/pre>\n<p><span style=\"color: #000000;\">\u5982\u679c\u60a8\u7684\u56e0\u5b50\u5411\u91cf\u4ec5\u5305\u542b\u56e0\u5b50\u540d\u79f0\uff0c\u5219\u5373\u4f7f\u5728\u5c06\u56e0\u5b50\u5411\u91cf\u8f6c\u6362\u4e3a\u6570\u503c\u5411\u91cf\u4e4b\u540e\u4e5f\u4e0d\u53ef\u80fd\u627e\u5230\u6700\u5927\u503c\uff0c\u56e0\u4e3a\u627e\u5230\u56e0\u5b50\u5217\u8868\u7684\u201c\u6700\u5927\u503c\u201d\u662f\u6ca1\u6709\u610f\u4e49\u7684\u3002\u540d\u79f0\u3002<\/span><\/p>\n<pre style=\"background-color: #e5e5e5; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#create factor vector with names of factors<\/span>\nfactor_vector &lt;- as.factor(c(\"first\", \"second\", \"third\"))\n\n<span style=\"color: #008080;\">#attempt to convert factor vector into numeric vector and find max value\n<\/span>new_vector &lt;- as.numeric(as.character(factor_vector))\nmax(new_vector)\n\n#Warning message:\n#NAs introduced by coercion \n#[1] NA<\/strong><\/pre>\n<p><span style=\"color: #000000;\">\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0cR \u53ef\u4ee5\u627e\u5230\u6700\u5927\u6570\u5411\u91cf\u3001\u65e5\u671f\u5411\u91cf\u548c\u5b57\u7b26\u5411\u91cf\uff0c\u800c\u4e0d\u4f1a\u9047\u5230\u95ee\u9898\uff1a<\/span><\/p>\n<pre style=\"background-color: #e5e5e5; font-size: 15px;\"> <strong>numeric_vector &lt;- c(1, 2, 12, 14)\nmax(numeric_vector)\n\n#[1] 14\n\ncharacter_vector &lt;- c(\"a\", \"b\", \"f\")\nmax(character_vector)\n\n#[1] \u201cf\u201d\n\ndate_vector &lt;- as.Date(c(\"2019-01-01\", \"2019-03-05\", \"2019-03-04\"))\nmax(date_vector)\n\n#[1] \"2019-03-05\"\n<\/strong><\/pre>\n<p><span style=\"color: #000000;\">\u56e0\u6b64\uff0c\u5982\u679c\u60a8\u8bd5\u56fe\u627e\u5230\u5411\u91cf\u4e2d\u7684\u6700\u5927\u503c\uff0c\u53ea\u9700\u786e\u4fdd\u60a8\u7684\u5411\u91cf\u4e0d\u662f<strong>Factor<\/strong>\u7c7b\u578b\u3002<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6709\u65f6\uff0c\u60a8\u53ef\u80fd\u4f1a\u5728 R \u4e2d\u9047\u5230\u4ee5\u4e0b\u9519\u8bef\uff1a &#8216;max&#8217; not meaningful for factors \u8fd9\u53ea [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11],"tags":[],"class_list":["post-471","post","type-post","status-publish","format-standard","hentry","category-11"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v21.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>R \u4e2d\u7684\u89e3\u91ca\u9519\u8bef\uff1a\u201cmax\u201d\u5bf9\u4e8e\u56e0\u5b50\u800c\u8a00\u5e76\u4e0d\u91cd\u8981 - Statorials<\/title>\n<meta name=\"description\" content=\"\u672c\u6559\u7a0b\u89e3\u91ca\u5982\u4f55\u89e3\u91ca R \u4e2d\u7684\u4ee5\u4e0b\u9519\u8bef\uff1a\u201cmax\u201d\u5bf9\u4e8e\u56e0\u5b50\u6ca1\u6709\u610f\u4e49\u3002\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/statorials.org\/cn\/r-max-\u5bf9\u56e0\u5b50\u4e0d\u663e\u7740\/\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"R \u4e2d\u7684\u89e3\u91ca\u9519\u8bef\uff1a\u201cmax\u201d\u5bf9\u4e8e\u56e0\u5b50\u800c\u8a00\u5e76\u4e0d\u91cd\u8981 - Statorials\" \/>\n<meta property=\"og:description\" content=\"\u672c\u6559\u7a0b\u89e3\u91ca\u5982\u4f55\u89e3\u91ca R \u4e2d\u7684\u4ee5\u4e0b\u9519\u8bef\uff1a\u201cmax\u201d\u5bf9\u4e8e\u56e0\u5b50\u6ca1\u6709\u610f\u4e49\u3002\" \/>\n<meta property=\"og:url\" content=\"https:\/\/statorials.org\/cn\/r-max-\u5bf9\u56e0\u5b50\u4e0d\u663e\u7740\/\" \/>\n<meta property=\"og:site_name\" content=\"Statorials\" \/>\n<meta property=\"article:published_time\" content=\"2023-07-29T19:32:18+00:00\" \/>\n<meta name=\"author\" content=\"\u672c\u6770\u660e\u00b7\u5b89\u5fb7\u68ee\u535a\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"\u672c\u6770\u660e\u00b7\u5b89\u5fb7\u68ee\u535a\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/statorials.org\/cn\/r-max-%e5%af%b9%e5%9b%a0%e5%ad%90%e4%b8%8d%e6%98%be%e7%9d%80\/\",\"url\":\"https:\/\/statorials.org\/cn\/r-max-%e5%af%b9%e5%9b%a0%e5%ad%90%e4%b8%8d%e6%98%be%e7%9d%80\/\",\"name\":\"R \u4e2d\u7684\u89e3\u91ca\u9519\u8bef\uff1a\u201cmax\u201d\u5bf9\u4e8e\u56e0\u5b50\u800c\u8a00\u5e76\u4e0d\u91cd\u8981 - Statorials\",\"isPartOf\":{\"@id\":\"https:\/\/statorials.org\/cn\/#website\"},\"datePublished\":\"2023-07-29T19:32:18+00:00\",\"dateModified\":\"2023-07-29T19:32:18+00:00\",\"author\":{\"@id\":\"https:\/\/statorials.org\/cn\/#\/schema\/person\/124e4e5b7c9f8dc0f1f95cc8c1db3261\"},\"description\":\"\u672c\u6559\u7a0b\u89e3\u91ca\u5982\u4f55\u89e3\u91ca R \u4e2d\u7684\u4ee5\u4e0b\u9519\u8bef\uff1a\u201cmax\u201d\u5bf9\u4e8e\u56e0\u5b50\u6ca1\u6709\u610f\u4e49\u3002\",\"breadcrumb\":{\"@id\":\"https:\/\/statorials.org\/cn\/r-max-%e5%af%b9%e5%9b%a0%e5%ad%90%e4%b8%8d%e6%98%be%e7%9d%80\/#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/statorials.org\/cn\/r-max-%e5%af%b9%e5%9b%a0%e5%ad%90%e4%b8%8d%e6%98%be%e7%9d%80\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/statorials.org\/cn\/r-max-%e5%af%b9%e5%9b%a0%e5%ad%90%e4%b8%8d%e6%98%be%e7%9d%80\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u5bb6\",\"item\":\"https:\/\/statorials.org\/cn\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"R \u4e2d\u9519\u8bef\u7684\u89e3\u91ca\uff1a\u201cmax\u201d\u5bf9\u4e8e\u56e0\u5b50\u800c\u8a00\u4e0d\u663e\u7740\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/statorials.org\/cn\/#website\",\"url\":\"https:\/\/statorials.org\/cn\/\",\"name\":\"Statorials\",\"description\":\"\u60a8\u7684\u7edf\u8ba1\u7d20\u517b\u6307\u5357\uff01\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/statorials.org\/cn\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/statorials.org\/cn\/#\/schema\/person\/124e4e5b7c9f8dc0f1f95cc8c1db3261\",\"name\":\"\u672c\u6770\u660e\u00b7\u5b89\u5fb7\u68ee\u535a\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/statorials.org\/cn\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/statorials.org\/cn\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg\",\"contentUrl\":\"https:\/\/statorials.org\/cn\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg\",\"caption\":\"\u672c\u6770\u660e\u00b7\u5b89\u5fb7\u68ee\u535a\"},\"description\":\"\u5927\u5bb6\u597d\uff0c\u6211\u662f\u672c\u6770\u660e\uff0c\u4e00\u4f4d\u9000\u4f11\u7684\u7edf\u8ba1\u5b66\u6559\u6388\uff0c\u540e\u6765\u6210\u4e3a Statorials \u7684\u70ed\u5fc3\u6559\u5e08\u3002 \u51ed\u501f\u5728\u7edf\u8ba1\u9886\u57df\u7684\u4e30\u5bcc\u7ecf\u9a8c\u548c\u4e13\u4e1a\u77e5\u8bc6\uff0c\u6211\u6e34\u671b\u5206\u4eab\u6211\u7684\u77e5\u8bc6\uff0c\u901a\u8fc7 Statorials \u589e\u5f3a\u5b66\u751f\u7684\u80fd\u529b\u3002\u4e86\u89e3\u66f4\u591a\",\"sameAs\":[\"https:\/\/statorials.org\/cn\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"R \u4e2d\u7684\u89e3\u91ca\u9519\u8bef\uff1a\u201cmax\u201d\u5bf9\u4e8e\u56e0\u5b50\u800c\u8a00\u5e76\u4e0d\u91cd\u8981 - Statorials","description":"\u672c\u6559\u7a0b\u89e3\u91ca\u5982\u4f55\u89e3\u91ca R \u4e2d\u7684\u4ee5\u4e0b\u9519\u8bef\uff1a\u201cmax\u201d\u5bf9\u4e8e\u56e0\u5b50\u6ca1\u6709\u610f\u4e49\u3002","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/statorials.org\/cn\/r-max-\u5bf9\u56e0\u5b50\u4e0d\u663e\u7740\/","og_locale":"zh_CN","og_type":"article","og_title":"R \u4e2d\u7684\u89e3\u91ca\u9519\u8bef\uff1a\u201cmax\u201d\u5bf9\u4e8e\u56e0\u5b50\u800c\u8a00\u5e76\u4e0d\u91cd\u8981 - Statorials","og_description":"\u672c\u6559\u7a0b\u89e3\u91ca\u5982\u4f55\u89e3\u91ca R \u4e2d\u7684\u4ee5\u4e0b\u9519\u8bef\uff1a\u201cmax\u201d\u5bf9\u4e8e\u56e0\u5b50\u6ca1\u6709\u610f\u4e49\u3002","og_url":"https:\/\/statorials.org\/cn\/r-max-\u5bf9\u56e0\u5b50\u4e0d\u663e\u7740\/","og_site_name":"Statorials","article_published_time":"2023-07-29T19:32:18+00:00","author":"\u672c\u6770\u660e\u00b7\u5b89\u5fb7\u68ee\u535a","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"\u672c\u6770\u660e\u00b7\u5b89\u5fb7\u68ee\u535a","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"1 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/statorials.org\/cn\/r-max-%e5%af%b9%e5%9b%a0%e5%ad%90%e4%b8%8d%e6%98%be%e7%9d%80\/","url":"https:\/\/statorials.org\/cn\/r-max-%e5%af%b9%e5%9b%a0%e5%ad%90%e4%b8%8d%e6%98%be%e7%9d%80\/","name":"R \u4e2d\u7684\u89e3\u91ca\u9519\u8bef\uff1a\u201cmax\u201d\u5bf9\u4e8e\u56e0\u5b50\u800c\u8a00\u5e76\u4e0d\u91cd\u8981 - Statorials","isPartOf":{"@id":"https:\/\/statorials.org\/cn\/#website"},"datePublished":"2023-07-29T19:32:18+00:00","dateModified":"2023-07-29T19:32:18+00:00","author":{"@id":"https:\/\/statorials.org\/cn\/#\/schema\/person\/124e4e5b7c9f8dc0f1f95cc8c1db3261"},"description":"\u672c\u6559\u7a0b\u89e3\u91ca\u5982\u4f55\u89e3\u91ca R \u4e2d\u7684\u4ee5\u4e0b\u9519\u8bef\uff1a\u201cmax\u201d\u5bf9\u4e8e\u56e0\u5b50\u6ca1\u6709\u610f\u4e49\u3002","breadcrumb":{"@id":"https:\/\/statorials.org\/cn\/r-max-%e5%af%b9%e5%9b%a0%e5%ad%90%e4%b8%8d%e6%98%be%e7%9d%80\/#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/statorials.org\/cn\/r-max-%e5%af%b9%e5%9b%a0%e5%ad%90%e4%b8%8d%e6%98%be%e7%9d%80\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/statorials.org\/cn\/r-max-%e5%af%b9%e5%9b%a0%e5%ad%90%e4%b8%8d%e6%98%be%e7%9d%80\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u5bb6","item":"https:\/\/statorials.org\/cn\/"},{"@type":"ListItem","position":2,"name":"R \u4e2d\u9519\u8bef\u7684\u89e3\u91ca\uff1a\u201cmax\u201d\u5bf9\u4e8e\u56e0\u5b50\u800c\u8a00\u4e0d\u663e\u7740"}]},{"@type":"WebSite","@id":"https:\/\/statorials.org\/cn\/#website","url":"https:\/\/statorials.org\/cn\/","name":"Statorials","description":"\u60a8\u7684\u7edf\u8ba1\u7d20\u517b\u6307\u5357\uff01","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/statorials.org\/cn\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/statorials.org\/cn\/#\/schema\/person\/124e4e5b7c9f8dc0f1f95cc8c1db3261","name":"\u672c\u6770\u660e\u00b7\u5b89\u5fb7\u68ee\u535a","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/statorials.org\/cn\/#\/schema\/person\/image\/","url":"https:\/\/statorials.org\/cn\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg","contentUrl":"https:\/\/statorials.org\/cn\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg","caption":"\u672c\u6770\u660e\u00b7\u5b89\u5fb7\u68ee\u535a"},"description":"\u5927\u5bb6\u597d\uff0c\u6211\u662f\u672c\u6770\u660e\uff0c\u4e00\u4f4d\u9000\u4f11\u7684\u7edf\u8ba1\u5b66\u6559\u6388\uff0c\u540e\u6765\u6210\u4e3a Statorials \u7684\u70ed\u5fc3\u6559\u5e08\u3002 \u51ed\u501f\u5728\u7edf\u8ba1\u9886\u57df\u7684\u4e30\u5bcc\u7ecf\u9a8c\u548c\u4e13\u4e1a\u77e5\u8bc6\uff0c\u6211\u6e34\u671b\u5206\u4eab\u6211\u7684\u77e5\u8bc6\uff0c\u901a\u8fc7 Statorials \u589e\u5f3a\u5b66\u751f\u7684\u80fd\u529b\u3002\u4e86\u89e3\u66f4\u591a","sameAs":["https:\/\/statorials.org\/cn"]}]}},"yoast_meta":{"yoast_wpseo_title":"","yoast_wpseo_metadesc":"","yoast_wpseo_canonical":""},"_links":{"self":[{"href":"https:\/\/statorials.org\/cn\/wp-json\/wp\/v2\/posts\/471","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/statorials.org\/cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/statorials.org\/cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/statorials.org\/cn\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/statorials.org\/cn\/wp-json\/wp\/v2\/comments?post=471"}],"version-history":[{"count":0,"href":"https:\/\/statorials.org\/cn\/wp-json\/wp\/v2\/posts\/471\/revisions"}],"wp:attachment":[{"href":"https:\/\/statorials.org\/cn\/wp-json\/wp\/v2\/media?parent=471"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/statorials.org\/cn\/wp-json\/wp\/v2\/categories?post=471"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/statorials.org\/cn\/wp-json\/wp\/v2\/tags?post=471"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}