{"id":380,"date":"2023-03-13T07:15:10","date_gmt":"2023-03-13T07:15:10","guid":{"rendered":"https:\/\/yunshangtulv.com.cn\/?p=380"},"modified":"2023-03-13T07:15:10","modified_gmt":"2023-03-13T07:15:10","slug":"r_%e5%b8%b8%e7%94%a8%e6%95%b0%e6%8d%ae%e7%b1%bb%e5%9e%8b","status":"publish","type":"post","link":"https:\/\/yunshangtulv.com.cn\/?p=380","title":{"rendered":"R_\u5e38\u7528\u6570\u636e\u7c7b\u578b"},"content":{"rendered":"<h2>\u5e38\u7528\u7684\u6570\u636e\u7c7b\u578b<\/h2>\n<h3>\u6570\u503c\u578b\uff08Numeric\uff09\uff1a<\/h3>\n<p>\u5305\u62ec\u6240\u6709\u5b9e\u6570\uff0c\u53ef\u4ee5\u4f7f\u7528 as.numeric() \u6216 as.double() \u51fd\u6570\u5c06\u5176\u4ed6\u7c7b\u578b\u8f6c\u6362\u4e3a\u6570\u503c\u578b\u3002<\/p>\n<pre class=\"corepress-code-pre\"><code>a &lt;- 3\r\nb &lt;- 2.5\r\nc &lt;- as.numeric(\"1.5\")\r\nd &lt;- as.double(TRUE)<\/code><\/pre>\n<p>&nbsp;<\/p>\n<h3>\u6574\u6570\u578b\uff08Integer\uff09\uff1a<\/h3>\n<p>\u5305\u62ec\u6240\u6709\u6574\u6570\uff0c\u53ef\u4ee5\u4f7f\u7528 as.integer() \u51fd\u6570\u5c06\u5176\u4ed6\u7c7b\u578b\u8f6c\u6362\u4e3a\u6574\u6570\u578b\u3002<\/p>\n<pre class=\"corepress-code-pre\"><code>a &lt;- 5L\r\nb &lt;- as.integer(\"3\")\r\nc &lt;- as.integer(FALSE)<\/code><\/pre>\n<p>&nbsp;<\/p>\n<h3>\u5b57\u7b26\u578b\uff08Character\uff09\uff1a<\/h3>\n<p>\u5305\u62ec\u6240\u6709\u5b57\u7b26\uff0c\u53ef\u4ee5\u4f7f\u7528\u5355\u5f15\u53f7\u6216\u53cc\u5f15\u53f7\u62ec\u8d77\u6765\uff0c\u4e5f\u53ef\u4ee5\u4f7f\u7528 as.character() \u51fd\u6570\u5c06\u5176\u4ed6\u7c7b\u578b\u8f6c\u6362\u4e3a\u5b57\u7b26\u578b\u3002<\/p>\n<pre class=\"corepress-code-pre\"><code>a &lt;- \"Hello, world!\"\r\nb &lt;- 'R programming'\r\nc &lt;- as.character(123)\r\nd &lt;- as.character(3.14)<\/code><\/pre>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<h3>\u903b\u8f91\u578b\uff08Logical\uff09\uff1a<\/h3>\n<p>\u5305\u62ec TRUE \u548c FALSE \u4e24\u4e2a\u503c\uff0c\u53ef\u4ee5\u4f7f\u7528 as.logical() \u51fd\u6570\u5c06\u5176\u4ed6\u7c7b\u578b\u8f6c\u6362\u4e3a\u903b\u8f91\u578b\u3002<\/p>\n<pre class=\"corepress-code-pre\"><code>a &lt;- TRUE\r\nb &lt;- FALSE\r\nc &lt;- as.logical(1)\r\nd &lt;- as.logical(\"FALSE\")<\/code><\/pre>\n<p>&nbsp;<\/p>\n<h3>\u56e0\u5b50\u578b\uff08Factor\uff09\uff1a<\/h3>\n<p>\u7528\u4e8e\u8868\u793a\u5206\u7c7b\u6570\u636e\uff0c\u53ef\u4ee5\u4f7f\u7528 factor() \u51fd\u6570\u5c06\u5b57\u7b26\u578b\u6216\u6574\u6570\u578b\u8f6c\u6362\u4e3a\u56e0\u5b50\u578b\u3002<\/p>\n<pre class=\"corepress-code-pre\"><code>a &lt;- factor(c(\"red\", \"green\", \"blue\"))\r\nb &lt;- factor(c(2, 1, 3), levels = c(1, 2, 3), labels = c(\"low\", \"medium\", \"high\"))<\/code><\/pre>\n<p>&nbsp;<\/p>\n<h3>\u5217\u8868\u578b\uff08List\uff09\uff1a<\/h3>\n<p>\u5305\u62ec\u591a\u4e2a\u5143\u7d20\uff0c\u6bcf\u4e2a\u5143\u7d20\u53ef\u4ee5\u662f\u4e0d\u540c\u7684\u6570\u636e\u7c7b\u578b\uff0c\u53ef\u4ee5\u4f7f\u7528 list() \u51fd\u6570\u521b\u5efa\u5217\u8868\u578b\u5bf9\u8c61\u3002<\/p>\n<pre class=\"corepress-code-pre\"><code>a &lt;- list(\"apple\", 3.14, TRUE, c(1, 2, 3))\r\nb &lt;- list(name = \"John\", age = 25, gender = \"male\")<\/code><\/pre>\n<p>&nbsp;<\/p>\n<h3>\u6570\u7ec4\u578b\uff08Array\uff09\uff1a<\/h3>\n<p>\u662f\u4e00\u79cd\u591a\u7ef4\u7684\u6570\u503c\u578b\u6570\u636e\u7ed3\u6784\uff0c\u53ef\u4ee5\u4f7f\u7528 array() \u51fd\u6570\u521b\u5efa\u6570\u7ec4\u578b\u5bf9\u8c61\u3002<\/p>\n<pre class=\"corepress-code-pre\"><code>a &lt;- array(1:12, dim = c(3, 4))\r\nb &lt;- array(1:24, dim = c(2, 3, 4))<\/code><\/pre>\n<p>&nbsp;<\/p>\n<h3>\u77e9\u9635\u578b\uff08Matrix\uff09\uff1a<\/h3>\n<p>\u662f\u4e00\u79cd\u7279\u6b8a\u7684\u6570\u7ec4\u578b\uff0c\u53ea\u5305\u542b\u4e24\u4e2a\u7ef4\u5ea6\uff08\u884c\u548c\u5217\uff09\uff0c\u53ef\u4ee5\u4f7f\u7528 matrix() \u51fd\u6570\u521b\u5efa\u77e9\u9635\u578b\u5bf9\u8c61\u3002<\/p>\n<pre class=\"corepress-code-pre\"><code>a &lt;- matrix(1:9, nrow = 3, ncol = 3)\r\nb &lt;- matrix(letters[1:6], nrow = 2, ncol = 3, byrow = TRUE)<\/code><\/pre>\n<p>\u8fd9\u4e9b\u662f\u5e38\u7528\u7684 R \u6570\u636e\u7c7b\u578b\u53ca\u5176\u5b9e\u4f8b\u3002\u4e86\u89e3\u4e0d\u540c\u7684\u6570\u636e\u7c7b\u578b\u53ef\u4ee5\u5e2e\u52a9\u4f60\u66f4\u597d\u5730\u64cd\u4f5c\u548c\u5904\u7406\u6570\u636e\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5e38\u7528\u7684\u6570\u636e\u7c7b\u578b \u6570\u503c\u578b\uff08Numeric\uff09\uff1a \u5305\u62ec\u6240\u6709\u5b9e\u6570\uff0c\u53ef\u4ee5\u4f7f\u7528 as.numeric() \u6216 as.dou [&hellip;]<\/p>\n","protected":false},"author":111,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-380","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/yunshangtulv.com.cn\/index.php?rest_route=\/wp\/v2\/posts\/380","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/yunshangtulv.com.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/yunshangtulv.com.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/yunshangtulv.com.cn\/index.php?rest_route=\/wp\/v2\/users\/111"}],"replies":[{"embeddable":true,"href":"https:\/\/yunshangtulv.com.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=380"}],"version-history":[{"count":0,"href":"https:\/\/yunshangtulv.com.cn\/index.php?rest_route=\/wp\/v2\/posts\/380\/revisions"}],"wp:attachment":[{"href":"https:\/\/yunshangtulv.com.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=380"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/yunshangtulv.com.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=380"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/yunshangtulv.com.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=380"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}