{"id":383,"date":"2023-03-15T03:29:34","date_gmt":"2023-03-15T03:29:34","guid":{"rendered":"https:\/\/yunshangtulv.com.cn\/?p=383"},"modified":"2023-03-15T03:29:34","modified_gmt":"2023-03-15T03:29:34","slug":"%e5%88%97%e8%a1%a8%e8%af%a6%e8%a7%a3%e5%8f%8a%e5%ba%94%e7%94%a8%e4%b8%be%e4%be%8b","status":"publish","type":"post","link":"https:\/\/yunshangtulv.com.cn\/?p=383","title":{"rendered":"\u5217\u8868\u8be6\u89e3\u53ca\u5e94\u7528\u4e3e\u4f8b"},"content":{"rendered":"<p>R\u8bed\u8a00\u4e2d\u7684\u5217\u8868\uff08list\uff09\u662f\u4e00\u79cd\u6570\u636e\u7ed3\u6784\uff0c\u5b83\u53ef\u4ee5\u5305\u542b\u591a\u4e2a\u4e0d\u540c\u7c7b\u578b\u7684\u5143\u7d20\uff0c\u4f8b\u5982\u5411\u91cf\u3001\u77e9\u9635\u3001\u6570\u636e\u6846\u7b49\u3002\u4e0e\u5411\u91cf\u4e0d\u540c\uff0c\u5217\u8868\u4e2d\u7684\u5143\u7d20\u53ef\u4ee5\u662f\u4e0d\u540c\u7c7b\u578b\u7684\u6570\u636e\u3002\u5217\u8868\u53ef\u4ee5\u7528\u6765\u5b58\u50a8\u548c\u7ec4\u7ec7\u590d\u6742\u7684\u6570\u636e\u7ed3\u6784\uff0c\u4f7f\u6570\u636e\u7684\u5904\u7406\u548c\u5206\u6790\u66f4\u52a0\u65b9\u4fbf\u3002<\/p>\n<p>\u5728R\u8bed\u8a00\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528<code>list()<\/code>\u51fd\u6570\u521b\u5efa\u4e00\u4e2a\u5217\u8868\u3002\u4e0b\u9762\u662f\u4e00\u4e2a\u521b\u5efa\u5217\u8868\u7684\u4f8b\u5b50\uff1a<\/p>\n<div class=\"bg-black mb-4 rounded-md\">\n<div class=\"p-4 overflow-y-auto\"><code class=\"!whitespace-pre hljs language-R\"><span class=\"hljs-comment\"># \u521b\u5efa\u5217\u8868<\/span><br \/>\nmylist <span class=\"hljs-operator\">&lt;-<\/span> <span class=\"hljs-built_in\">list<\/span><span class=\"hljs-punctuation\">(<\/span>name<span class=\"hljs-operator\">=<\/span><span class=\"hljs-string\">\"John\"<\/span><span class=\"hljs-punctuation\">,<\/span> age<span class=\"hljs-operator\">=<\/span><span class=\"hljs-number\">25<\/span><span class=\"hljs-punctuation\">,<\/span> grades<span class=\"hljs-operator\">=<\/span><span class=\"hljs-built_in\">c<\/span><span class=\"hljs-punctuation\">(<\/span><span class=\"hljs-number\">80<\/span><span class=\"hljs-punctuation\">,<\/span> <span class=\"hljs-number\">90<\/span><span class=\"hljs-punctuation\">,<\/span> <span class=\"hljs-number\">85<\/span><span class=\"hljs-punctuation\">)<\/span><span class=\"hljs-punctuation\">)<\/span><br \/>\nprint<span class=\"hljs-punctuation\">(<\/span>mylist<span class=\"hljs-punctuation\">)<\/span><br \/>\n<\/code><\/div>\n<\/div>\n<p>\u8f93\u51fa\u7ed3\u679c\uff1a<\/p>\n<div class=\"bg-black mb-4 rounded-md\">\n<div class=\"p-4 overflow-y-auto\"><code class=\"!whitespace-pre hljs language-bash\"><span class=\"hljs-variable\">$name<\/span><br \/>\n[1] <span class=\"hljs-string\">\"John\"<\/span><\/p>\n<p><span class=\"hljs-variable\">$age<\/span><br \/>\n[1] 25<\/p>\n<p><span class=\"hljs-variable\">$grades<\/span><br \/>\n[1] 80 90 85<br \/>\n<\/code><\/div>\n<\/div>\n<p>\u4e0a\u9762\u7684\u4f8b\u5b50\u4e2d\uff0c\u6211\u4eec\u521b\u5efa\u4e86\u4e00\u4e2a\u5305\u542b\u4e09\u4e2a\u5143\u7d20\u7684\u5217\u8868\uff0c\u5176\u4e2d\u7b2c\u4e00\u4e2a\u5143\u7d20\u662f\u4e00\u4e2a\u5b57\u7b26\u7c7b\u578b\u7684\u540d\u79f0\uff0c\u7b2c\u4e8c\u4e2a\u5143\u7d20\u662f\u4e00\u4e2a\u6570\u5b57\u7c7b\u578b\u7684\u5e74\u9f84\uff0c\u7b2c\u4e09\u4e2a\u5143\u7d20\u662f\u4e00\u4e2a\u6570\u503c\u578b\u5411\u91cf\u7c7b\u578b\u7684\u5206\u6570\u5217\u8868\u3002\u5217\u8868\u7684\u6bcf\u4e2a\u5143\u7d20\u90fd\u6709\u4e00\u4e2a\u540d\u79f0\uff0c\u540d\u79f0\u4e0e\u5143\u7d20\u4e4b\u95f4\u7528<code>$<\/code>\u7b26\u53f7\u5206\u9694\u3002<\/p>\n<p>\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528<code>[[index]]<\/code>\u6216\u8005<code>$name<\/code>\u7684\u65b9\u5f0f\u8bbf\u95ee\u5217\u8868\u4e2d\u7684\u5143\u7d20\u3002<code>[[index]]<\/code>\u7528\u6765\u6839\u636e\u5217\u8868\u4e2d\u7684\u5143\u7d20\u7684\u4f4d\u7f6e\uff08\u4ece1\u5f00\u59cb\u8ba1\u6570\uff09\u6765\u8bbf\u95ee\u5217\u8868\u4e2d\u7684\u5143\u7d20\u3002\u4f8b\u5982\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u4ee3\u7801\u8bbf\u95ee\u5217\u8868\u4e2d\u7684\u7b2c\u4e8c\u4e2a\u5143\u7d20\uff1a<\/p>\n<div class=\"bg-black mb-4 rounded-md\">\n<div class=\"p-4 overflow-y-auto\"><code class=\"!whitespace-pre hljs language-R\"><span class=\"hljs-comment\"># \u8bbf\u95ee\u5217\u8868\u4e2d\u7684\u7b2c\u4e8c\u4e2a\u5143\u7d20<\/span><br \/>\nprint<span class=\"hljs-punctuation\">(<\/span>mylist<span class=\"hljs-punctuation\">[[<\/span><span class=\"hljs-number\">2<\/span><span class=\"hljs-punctuation\">]<\/span><span class=\"hljs-punctuation\">]<\/span><span class=\"hljs-punctuation\">)<\/span><br \/>\n<\/code><\/div>\n<\/div>\n<p>\u8f93\u51fa\u7ed3\u679c\uff1a<\/p>\n<div class=\"bg-black mb-4 rounded-md\">\n<div class=\"p-4 overflow-y-auto\"><code class=\"!whitespace-pre hljs language-csharp\">[<span class=\"hljs-meta\">1<\/span>] <span class=\"hljs-number\">25<\/span><br \/>\n<\/code><\/div>\n<\/div>\n<p><code>$name<\/code>\u7528\u6765\u6839\u636e\u5217\u8868\u4e2d\u5143\u7d20\u7684\u540d\u79f0\u6765\u8bbf\u95ee\u5217\u8868\u4e2d\u7684\u5143\u7d20\u3002\u4f8b\u5982\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u4ee3\u7801\u8bbf\u95ee\u5217\u8868\u4e2d\u7684\u5206\u6570\u5217\u8868\uff1a<\/p>\n<div class=\"bg-black mb-4 rounded-md\">\n<div class=\"p-4 overflow-y-auto\"><code class=\"!whitespace-pre hljs language-R\"><span class=\"hljs-comment\"># \u8bbf\u95ee\u5217\u8868\u4e2d\u7684\u5206\u6570\u5217\u8868<\/span><br \/>\nprint<span class=\"hljs-punctuation\">(<\/span>mylist<span class=\"hljs-operator\">$<\/span>grades<span class=\"hljs-punctuation\">)<\/span><br \/>\n<\/code><\/div>\n<\/div>\n<p>\u8f93\u51fa\u7ed3\u679c\uff1a<\/p>\n<div class=\"bg-black mb-4 rounded-md\">\n<div class=\"p-4 overflow-y-auto\"><code class=\"!whitespace-pre hljs language-csharp\">[<span class=\"hljs-meta\">1<\/span>] <span class=\"hljs-number\">80<\/span> <span class=\"hljs-number\">90<\/span> <span class=\"hljs-number\">85<\/span><br \/>\n<\/code><\/div>\n<\/div>\n<p>\u6211\u4eec\u53ef\u4ee5\u5411\u5217\u8868\u4e2d\u6dfb\u52a0\u5143\u7d20\uff0c\u4e5f\u53ef\u4ee5\u5220\u9664\u5217\u8868\u4e2d\u7684\u5143\u7d20\u3002\u4e0b\u9762\u662f\u4e00\u4e2a\u5411\u5217\u8868\u4e2d\u6dfb\u52a0\u5143\u7d20\u548c\u5220\u9664\u5143\u7d20\u7684\u4f8b\u5b50\uff1a<\/p>\n<div class=\"bg-black mb-4 rounded-md\">\n<div class=\"p-4 overflow-y-auto\"><code class=\"!whitespace-pre hljs language-R\"><span class=\"hljs-comment\"># \u5411\u5217\u8868\u4e2d\u6dfb\u52a0\u5143\u7d20<\/span><br \/>\nmylist<span class=\"hljs-operator\">$<\/span>email <span class=\"hljs-operator\">&lt;-<\/span> <span class=\"hljs-string\">\"john@example.com\"<\/span><br \/>\nprint<span class=\"hljs-punctuation\">(<\/span>mylist<span class=\"hljs-punctuation\">)<\/span><\/p>\n<p><span class=\"hljs-comment\"># \u5220\u9664\u5217\u8868\u4e2d\u7684\u5143\u7d20<\/span><br \/>\nmylist<span class=\"hljs-operator\">$<\/span>email <span class=\"hljs-operator\">&lt;-<\/span> <span class=\"hljs-literal\">NULL<\/span><br \/>\nprint<span class=\"hljs-punctuation\">(<\/span>mylist<span class=\"hljs-punctuation\">)<\/span><br \/>\n<\/code><\/div>\n<\/div>\n<p>\u8f93\u51fa\u7ed3\u679c\uff1a<\/p>\n<div class=\"bg-black mb-4 rounded-md\">\n<div class=\"p-4 overflow-y-auto\"><code class=\"!whitespace-pre hljs language-perl\">$name<br \/>\n[<span class=\"hljs-number\">1<\/span>] <span class=\"hljs-string\">\"John\"<\/span><\/p>\n<p>$age<br \/>\n[<span class=\"hljs-number\">1<\/span>] <span class=\"hljs-number\">25<\/span><\/p>\n<p>$grades<br \/>\n[<span class=\"hljs-number\">1<\/span>] <span class=\"hljs-number\">80<\/span> <span class=\"hljs-number\">90<\/span> <span class=\"hljs-number\">85<\/span><\/p>\n<p>$email<br \/>\n[<span class=\"hljs-number\">1<\/span>] <span class=\"hljs-string\">\"john@example.com\"<\/span><\/p>\n<p>$name<br \/>\n[<span class=\"hljs-number\">1<\/span>] <span class=\"hljs-string\">\"John\"<\/span><\/p>\n<p>$age<br \/>\n[<span class=\"hljs-number\">1<\/span>] <span class=\"hljs-number\">25<\/span><\/p>\n<p>$grades<br \/>\n[<span class=\"hljs-number\">1<\/span>] <span class=\"hljs-number\">80<\/span> <span class=\"hljs-number\">90<\/span> <span class=\"hljs-number\">85<\/span><br \/>\n<\/code><\/div>\n<\/div>\n<p>\u9664\u4e86\u4e0a\u8ff0\u57fa\u672c\u64cd\u4f5c\u5916\uff0cR\u8bed\u8a00\u8fd8\u63d0\u4f9b\u4e86\u8bb8\u591a\u5217\u8868\u7684\u9ad8\u7ea7\u64cd\u4f5c\uff0c\u4f8b\u5982\u5217\u8868\u7684\u6392\u5e8f\u3001\u5217\u8868\u5143\u7d20\u7684\u7b5b\u9009\u7b49\u7b49\u3002\u5217\u8868\u7684\u7075\u6d3b\u6027\u4f7f\u5f97\u5b83\u53ef\u4ee5\u5b58\u50a8\u548c\u5904\u7406\u5404\u79cd\u590d\u6742\u7684\u6570\u636e\u7ed3\u6784\uff0c\u719f\u7ec3\u638c\u63e1\u5217\u8868\u7684\u4f7f\u7528\u5bf9\u4e8e\u4f7f\u7528R\u8bed\u8a00\u8fdb\u884c\u6570\u636e\u5206\u6790\u548c\u53ef\u89c6\u5316\u975e\u5e38\u91cd\u8981\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>R\u8bed\u8a00\u4e2d\u7684\u5217\u8868\uff08list\uff09\u662f\u4e00\u79cd\u6570\u636e\u7ed3\u6784\uff0c\u5b83\u53ef\u4ee5\u5305\u542b\u591a\u4e2a\u4e0d\u540c\u7c7b\u578b\u7684\u5143\u7d20\uff0c\u4f8b\u5982\u5411\u91cf\u3001\u77e9\u9635\u3001\u6570\u636e\u6846\u7b49\u3002\u4e0e\u5411\u91cf\u4e0d\u540c\uff0c [&hellip;]<\/p>\n","protected":false},"author":111,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[],"class_list":["post-383","post","type-post","status-publish","format-standard","hentry","category-r"],"_links":{"self":[{"href":"https:\/\/yunshangtulv.com.cn\/index.php?rest_route=\/wp\/v2\/posts\/383","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=383"}],"version-history":[{"count":0,"href":"https:\/\/yunshangtulv.com.cn\/index.php?rest_route=\/wp\/v2\/posts\/383\/revisions"}],"wp:attachment":[{"href":"https:\/\/yunshangtulv.com.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=383"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/yunshangtulv.com.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=383"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/yunshangtulv.com.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=383"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}