{"id":1879,"date":"2023-07-24T15:08:42","date_gmt":"2023-07-24T15:08:42","guid":{"rendered":"https:\/\/statorials.org\/cn\/r-%e7%bc%ba%e5%a4%b1%e5%80%bc%e6%88%96-true-false-%e5%bf%85%e8%a6%81\/"},"modified":"2023-07-24T15:08:42","modified_gmt":"2023-07-24T15:08:42","slug":"r-%e7%bc%ba%e5%a4%b1%e5%80%bc%e6%88%96-true-false-%e5%bf%85%e8%a6%81","status":"publish","type":"post","link":"https:\/\/statorials.org\/cn\/r-%e7%bc%ba%e5%a4%b1%e5%80%bc%e6%88%96-true-false-%e5%bf%85%e8%a6%81\/","title":{"rendered":"\u5982\u4f55\u4fee\u590d r\uff1a\u9700\u8981 true\/false \u7684\u7f3a\u5931\u503c"},"content":{"rendered":"<p><\/p>\n<hr>\n<p><span style=\"color: #000000;\">\u5728 R \u4e2d\u60a8\u53ef\u80fd\u9047\u5230\u7684\u9519\u8bef\u662f\uff1a<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong>Error in if (x[i] == NA) {: missing value where TRUE\/FALSE needed\n<\/strong><\/pre>\n<p><span style=\"color: #000000;\">\u5f53\u60a8\u4f7f\u7528\u8bed\u6cd5<strong>x == NA<\/strong>\u5c06 R \u4e2d<strong>if<\/strong>\u8bed\u53e5\u4e2d\u7684\u503c\u4e0e NA \u8fdb\u884c\u6bd4\u8f83\u65f6\uff0c\u4f1a\u53d1\u751f\u6b64\u9519\u8bef\u3002<\/span><\/p>\n<p> <span style=\"color: #000000;\"><strong>if<\/strong>\u8bed\u53e5\u9700\u8981 TRUE \u6216 FALSE \u503c\uff0c\u56e0\u6b64\u60a8\u5e94\u8be5\u4f7f\u7528<strong>is.na(x)<\/strong>\u6765\u4ee3\u66ff\uff0c\u56e0\u4e3a\u8be5\u51fd\u6570\u59cb\u7ec8\u8fd4\u56de TRUE \u6216 FALSE\u3002<\/span><\/p>\n<h3><span style=\"color: #000000;\"><strong>\u5982\u4f55\u91cd\u73b0\u9519\u8bef<\/strong><\/span><\/h3>\n<p><span style=\"color: #000000;\">\u5047\u8bbe\u6211\u4eec\u5c1d\u8bd5\u8fed\u4ee3 R \u4e2d\u5411\u91cf\u4e2d\u7684\u503c\u5217\u8868\uff0c\u5e76\u5728\u6bcf\u6b21\u5411\u91cf\u4e2d\u5b58\u5728 NA \u503c\u65f6\u6253\u5370\u5355\u8bcd\u201cmissing\u201d\uff1a<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#define vector with some missing values\n<\/span>x &lt;- c(2, NA, 5, 6, NA, 15, 19)\n\n<span style=\"color: #008080;\">#loop through vector and print \"missing\" each time an NA value is encountered\n<\/span><span style=\"color: #008000;\">for<\/span> (i <span style=\"color: #008000;\">in<\/span> 1:length(x)) {\n \n <span style=\"color: #008000;\">if<\/span> (x[i] == NA) {\n    print(' <span style=\"color: #ff0000;\">Missing<\/span> ')\n  }\n}\n\nError in if (x[i] == NA) {: missing value where TRUE\/FALSE needed\n<\/strong><\/pre>\n<p><span style=\"color: #000000;\">\u6211\u4eec\u6536\u5230\u9519\u8bef\uff0c\u56e0\u4e3a\u6211\u4eec\u4f7f\u7528\u4e86\u8bed\u6cd5<strong>x[i] == NA<\/strong> \u3002<\/span><\/p>\n<h3><span style=\"color: #000000;\"><strong>\u5982\u4f55\u4fee\u590d\u9519\u8bef<\/strong><\/span><\/h3>\n<p><span style=\"color: #000000;\">\u6211\u4eec\u9700\u8981\u5c06\u8bed\u6cd5\u66f4\u6539\u4e3a<strong>is.na(x)\uff0c<\/strong>\u5982\u4e0b\u6240\u793a\uff1a<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#define vector with some missing values\n<\/span>x &lt;- c(2, NA, 5, 6, NA, 15, 19)\n\n<span style=\"color: #008080;\">#loop through vector and print \"missing\" each time an NA value is encountered\n<\/span><span style=\"color: #008000;\">for<\/span> (i <span style=\"color: #008000;\">in<\/span> 1:length(x)) {\n \n <span style=\"color: #008000;\">if<\/span> (is. <span style=\"color: #3366ff;\">na<\/span> (x[i])) {\n    print(' <span style=\"color: #ff0000;\">Missing<\/span> ')\n  }\n}\n\n[1] \u201cMissing\u201d\n[1] \u201cMissing\u201d\n<\/strong><\/pre>\n<p><span style=\"color: #000000;\">\u8bf7\u6ce8\u610f\uff0c\u6bcf\u5f53\u6211\u4eec\u5728\u5411\u91cf\u4e2d\u9047\u5230 NA \u503c\u65f6\uff0c\u6211\u4eec\u4e0d\u4f1a\u6536\u5230\u9519\u8bef\uff0c\u5e76\u4e14\u53ef\u4ee5\u6253\u5370\u201c\u7f3a\u5931\u201d\u4e00\u8bcd\u3002<\/span><\/p>\n<h3><span style=\"color: #000000;\"><strong>\u5176\u4ed6\u8d44\u6e90<\/strong><\/span><\/h3>\n<p><span style=\"color: #000000;\">\u4ee5\u4e0b\u6559\u7a0b\u89e3\u91ca\u4e86\u5982\u4f55\u4fee\u590d R \u4e2d\u7684\u5176\u4ed6\u5e38\u89c1\u9519\u8bef\uff1a<\/span><\/p>\n<p><a href=\"https:\/\/statorials.org\/cn\/nas-\u901a\u8fc7\u5f3a\u5236\u5f15\u5165-r\/\" target=\"_blank\" rel=\"noopener\">\u5982\u4f55\u4fee\u590d\uff1a\u5f3a\u5236\u5f15\u5165\u7684 NA<\/a><br \/> <a href=\"https:\/\/statorials.org\/cn\/r-\u77e9\u9635\u4e0a\u7684\u7d22\u5f15\u6570\u91cf\u4e0d\u6b63\u786e\/\" target=\"_blank\" rel=\"noopener\">\u5982\u4f55\u4fee\u590d\uff1a\u77e9\u9635\u4e0a\u7684\u7d22\u5f15\u6570\u91cf\u4e0d\u6b63\u786e<\/a><br \/><a href=\"https:\/\/statorials.org\/cn\/r-\u8981\u66ff\u6362\u7684\u9879\u76ee\u6570\u91cf\u4e0d\u662f\u66ff\u6362\u957f\u5ea6\u7684\u500d\u6570\/\" target=\"_blank\" rel=\"noopener\">\u5982\u4f55\u4fee\u590d\uff1a\u66f4\u6362\u7684\u7269\u54c1\u6570\u91cf\u4e0d\u662f\u66f4\u6362\u957f\u5ea6\u7684\u500d\u6570<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728 R \u4e2d\u60a8\u53ef\u80fd\u9047\u5230\u7684\u9519\u8bef\u662f\uff1a Error in if (x[i] == NA) {: missing val [&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-1879","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>\u5982\u4f55\u4fee\u590d R\uff1a\u9700\u8981 true\/false \u7684\u7f3a\u5931\u503c<\/title>\n<meta name=\"description\" content=\"\u672c\u6559\u7a0b\u4ecb\u7ecd\u5982\u4f55\u89e3\u51b3 R \u4e2d\u7684\u4ee5\u4e0b\u9519\u8bef\uff1a\u9700\u8981 true\/false \u65f6\u7f3a\u5c11\u503c\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-\u7f3a\u5931\u503c\u6216-true-false-\u5fc5\u8981\/\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u5982\u4f55\u4fee\u590d R\uff1a\u9700\u8981 true\/false \u7684\u7f3a\u5931\u503c\" \/>\n<meta property=\"og:description\" content=\"\u672c\u6559\u7a0b\u4ecb\u7ecd\u5982\u4f55\u89e3\u51b3 R \u4e2d\u7684\u4ee5\u4e0b\u9519\u8bef\uff1a\u9700\u8981 true\/false \u65f6\u7f3a\u5c11\u503c\u3002\" \/>\n<meta property=\"og:url\" content=\"https:\/\/statorials.org\/cn\/r-\u7f3a\u5931\u503c\u6216-true-false-\u5fc5\u8981\/\" \/>\n<meta property=\"og:site_name\" content=\"Statorials\" \/>\n<meta property=\"article:published_time\" content=\"2023-07-24T15:08:42+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-%e7%bc%ba%e5%a4%b1%e5%80%bc%e6%88%96-true-false-%e5%bf%85%e8%a6%81\/\",\"url\":\"https:\/\/statorials.org\/cn\/r-%e7%bc%ba%e5%a4%b1%e5%80%bc%e6%88%96-true-false-%e5%bf%85%e8%a6%81\/\",\"name\":\"\u5982\u4f55\u4fee\u590d R\uff1a\u9700\u8981 true\/false \u7684\u7f3a\u5931\u503c\",\"isPartOf\":{\"@id\":\"https:\/\/statorials.org\/cn\/#website\"},\"datePublished\":\"2023-07-24T15:08:42+00:00\",\"dateModified\":\"2023-07-24T15:08:42+00:00\",\"author\":{\"@id\":\"https:\/\/statorials.org\/cn\/#\/schema\/person\/124e4e5b7c9f8dc0f1f95cc8c1db3261\"},\"description\":\"\u672c\u6559\u7a0b\u4ecb\u7ecd\u5982\u4f55\u89e3\u51b3 R \u4e2d\u7684\u4ee5\u4e0b\u9519\u8bef\uff1a\u9700\u8981 true\/false \u65f6\u7f3a\u5c11\u503c\u3002\",\"breadcrumb\":{\"@id\":\"https:\/\/statorials.org\/cn\/r-%e7%bc%ba%e5%a4%b1%e5%80%bc%e6%88%96-true-false-%e5%bf%85%e8%a6%81\/#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/statorials.org\/cn\/r-%e7%bc%ba%e5%a4%b1%e5%80%bc%e6%88%96-true-false-%e5%bf%85%e8%a6%81\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/statorials.org\/cn\/r-%e7%bc%ba%e5%a4%b1%e5%80%bc%e6%88%96-true-false-%e5%bf%85%e8%a6%81\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u5bb6\",\"item\":\"https:\/\/statorials.org\/cn\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u5982\u4f55\u4fee\u590d r\uff1a\u9700\u8981 true\/false \u7684\u7f3a\u5931\u503c\"}]},{\"@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":"\u5982\u4f55\u4fee\u590d R\uff1a\u9700\u8981 true\/false \u7684\u7f3a\u5931\u503c","description":"\u672c\u6559\u7a0b\u4ecb\u7ecd\u5982\u4f55\u89e3\u51b3 R \u4e2d\u7684\u4ee5\u4e0b\u9519\u8bef\uff1a\u9700\u8981 true\/false \u65f6\u7f3a\u5c11\u503c\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-\u7f3a\u5931\u503c\u6216-true-false-\u5fc5\u8981\/","og_locale":"zh_CN","og_type":"article","og_title":"\u5982\u4f55\u4fee\u590d R\uff1a\u9700\u8981 true\/false \u7684\u7f3a\u5931\u503c","og_description":"\u672c\u6559\u7a0b\u4ecb\u7ecd\u5982\u4f55\u89e3\u51b3 R \u4e2d\u7684\u4ee5\u4e0b\u9519\u8bef\uff1a\u9700\u8981 true\/false \u65f6\u7f3a\u5c11\u503c\u3002","og_url":"https:\/\/statorials.org\/cn\/r-\u7f3a\u5931\u503c\u6216-true-false-\u5fc5\u8981\/","og_site_name":"Statorials","article_published_time":"2023-07-24T15:08:42+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-%e7%bc%ba%e5%a4%b1%e5%80%bc%e6%88%96-true-false-%e5%bf%85%e8%a6%81\/","url":"https:\/\/statorials.org\/cn\/r-%e7%bc%ba%e5%a4%b1%e5%80%bc%e6%88%96-true-false-%e5%bf%85%e8%a6%81\/","name":"\u5982\u4f55\u4fee\u590d R\uff1a\u9700\u8981 true\/false \u7684\u7f3a\u5931\u503c","isPartOf":{"@id":"https:\/\/statorials.org\/cn\/#website"},"datePublished":"2023-07-24T15:08:42+00:00","dateModified":"2023-07-24T15:08:42+00:00","author":{"@id":"https:\/\/statorials.org\/cn\/#\/schema\/person\/124e4e5b7c9f8dc0f1f95cc8c1db3261"},"description":"\u672c\u6559\u7a0b\u4ecb\u7ecd\u5982\u4f55\u89e3\u51b3 R \u4e2d\u7684\u4ee5\u4e0b\u9519\u8bef\uff1a\u9700\u8981 true\/false \u65f6\u7f3a\u5c11\u503c\u3002","breadcrumb":{"@id":"https:\/\/statorials.org\/cn\/r-%e7%bc%ba%e5%a4%b1%e5%80%bc%e6%88%96-true-false-%e5%bf%85%e8%a6%81\/#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/statorials.org\/cn\/r-%e7%bc%ba%e5%a4%b1%e5%80%bc%e6%88%96-true-false-%e5%bf%85%e8%a6%81\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/statorials.org\/cn\/r-%e7%bc%ba%e5%a4%b1%e5%80%bc%e6%88%96-true-false-%e5%bf%85%e8%a6%81\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u5bb6","item":"https:\/\/statorials.org\/cn\/"},{"@type":"ListItem","position":2,"name":"\u5982\u4f55\u4fee\u590d r\uff1a\u9700\u8981 true\/false \u7684\u7f3a\u5931\u503c"}]},{"@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\/1879","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=1879"}],"version-history":[{"count":0,"href":"https:\/\/statorials.org\/cn\/wp-json\/wp\/v2\/posts\/1879\/revisions"}],"wp:attachment":[{"href":"https:\/\/statorials.org\/cn\/wp-json\/wp\/v2\/media?parent=1879"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/statorials.org\/cn\/wp-json\/wp\/v2\/categories?post=1879"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/statorials.org\/cn\/wp-json\/wp\/v2\/tags?post=1879"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}