{"id":1865,"date":"2023-07-24T16:36:13","date_gmt":"2023-07-24T16:36:13","guid":{"rendered":"https:\/\/statorials.org\/pt\/r-numero-incorreto-de-indices-na-matriz\/"},"modified":"2023-07-24T16:36:13","modified_gmt":"2023-07-24T16:36:13","slug":"r-numero-incorreto-de-indices-na-matriz","status":"publish","type":"post","link":"https:\/\/statorials.org\/pt\/r-numero-incorreto-de-indices-na-matriz\/","title":{"rendered":"Como corrigir em r: n\u00famero incorreto de \u00edndices na matriz"},"content":{"rendered":"<p><\/p>\n<hr>\n<p><span style=\"color: #000000;\">Um erro que voc\u00ea pode encontrar no R \u00e9:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong>Error in x[i, ] &lt;- 0: incorrect number of subscripts on matrix\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Este erro ocorre quando voc\u00ea tenta atribuir um valor a uma posi\u00e7\u00e3o em um vetor, mas acidentalmente inclui uma v\u00edrgula como se estivesse atribuindo um valor a uma posi\u00e7\u00e3o de linha e coluna em uma matriz.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Este tutorial explica exatamente como corrigir esse erro.<\/span><\/p>\n<h3> <strong>Exemplo 1: Corrigindo um erro para um \u00fanico valor<\/strong><\/h3>\n<p> <span style=\"color: #000000;\">Suponha que temos o seguinte vetor em R com 5 valores:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#definevector\n<\/span>x &lt;- c(4, 6, 7, 7, 15)\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Agora suponha que tentamos atribuir o valor \u201c22\u201d ao terceiro elemento do vetor:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#attempt to assign the value '22' to element in third position<\/span>\nx[3, ] &lt;- 22\n\nError in x[3, ] &lt;- 22: incorrect number of subscripts on matrix\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Estamos recebendo um erro porque inclu\u00edmos uma v\u00edrgula ao tentar atribuir o novo valor.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Em vez disso, s\u00f3 precisamos remover o comando:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">assign the value '22' to element in third position<\/span>\nx[3] &lt;- 22\n\n<span style=\"color: #008080;\">#display updated vector<\/span>\nx\n\n[1] 4 6 22 7 15\n<\/strong><\/pre>\n<h3> <strong>Exemplo 2: corrija um erro em um loop for<\/strong><\/h3>\n<p> <span style=\"color: #000000;\">Este erro tamb\u00e9m pode ocorrer ao tentar substituir v\u00e1rios valores em um vetor usando um loop \u2018for\u2019.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Por exemplo, o c\u00f3digo a seguir tenta substituir cada valor em um vetor por zero:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\"><span style=\"color: #000000;\"><span style=\"color: #008080;\">#definevector\n<\/span>x &lt;- c(4, 6, 7, 7, 15)\n<\/span>\n<span style=\"color: #000000;\"><span style=\"color: #008080;\">#attempt to replace every value in vector with zero\n<\/span><span style=\"color: #008000;\">for<\/span> (i <span style=\"color: #008000;\">in<\/span> 1:length(x)) {\n    x[i, ]=0\n  }\n\nError in x[i, ] = 0: incorrect number of subscripts on matrix\n<\/span><\/span><\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Estamos recebendo um erro porque inclu\u00edmos uma v\u00edrgula ao tentar atribuir zeros.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Em vez disso, s\u00f3 precisamos remover o comando:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\"><span style=\"color: #000000;\"><span style=\"color: #008080;\">#definevector\n<\/span>x &lt;- c(4, 6, 7, 7, 15)\n\n<span style=\"color: #008080;\">#replace every value in vector with zero<\/span>\n<span style=\"color: #008000;\">for<\/span> (i <span style=\"color: #008000;\">in<\/span> 1:length(x)) {\n    x[i]=0\n  }\n\n<span style=\"color: #008080;\">#view updated vector<\/span>\nx\n<\/span>\n<span style=\"color: #000000;\">[1] 0 0 0 0 0\n<\/span><\/span><\/strong><\/pre>\n<p> <span style=\"color: #000000;\"><span style=\"color: #000000;\">Depois que a v\u00edrgula for removida, o c\u00f3digo ser\u00e1 executado sem erros.<\/span><\/span><\/p>\n<h3> <span style=\"color: #000000;\"><strong>Recursos adicionais<\/strong><\/span><\/h3>\n<p> <a href=\"https:\/\/statorials.org\/pt\/nas-introduzido-por-coercao-em-r\/\" target=\"_blank\" rel=\"noopener\">Como corrigir em R: NAs introduzidos por coer\u00e7\u00e3o<\/a><br \/> <a href=\"https:\/\/statorials.org\/pt\/r-indice-de-erro-fora-do-intervalo\/\" target=\"_blank\" rel=\"noopener\">Como reparar em R: \u00edndice fora dos limites<\/a><br \/><a href=\"https:\/\/statorials.org\/pt\/r-numero-incorreto-de-dimensoes\/\" target=\"_blank\" rel=\"noopener\">Como corrigir erro em R: n\u00famero incorreto de dimens\u00f5es<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Um erro que voc\u00ea pode encontrar no R \u00e9: Error in x[i, ] &lt;- 0: incorrect number of subscripts on matrix Este erro ocorre quando voc\u00ea tenta atribuir um valor a uma posi\u00e7\u00e3o em um vetor, mas acidentalmente inclui uma v\u00edrgula como se estivesse atribuindo um valor a uma posi\u00e7\u00e3o de linha e coluna em [&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-1865","post","type-post","status-publish","format-standard","hentry","category-guia"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v21.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Como corrigir em R: n\u00famero incorreto de \u00edndices na matriz<\/title>\n<meta name=\"description\" content=\"Este tutorial explica como corrigir o seguinte erro em R: N\u00famero incorreto de \u00edndices na matriz.\" \/>\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\/pt\/r-numero-incorreto-de-indices-na-matriz\/\" \/>\n<meta property=\"og:locale\" content=\"pt_PT\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Como corrigir em R: n\u00famero incorreto de \u00edndices na matriz\" \/>\n<meta property=\"og:description\" content=\"Este tutorial explica como corrigir o seguinte erro em R: N\u00famero incorreto de \u00edndices na matriz.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/statorials.org\/pt\/r-numero-incorreto-de-indices-na-matriz\/\" \/>\n<meta property=\"og:site_name\" content=\"Statorials\" \/>\n<meta property=\"article:published_time\" content=\"2023-07-24T16:36:13+00:00\" \/>\n<meta name=\"author\" content=\"Dr. benjamim anderson\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Escrito por\" \/>\n\t<meta name=\"twitter:data1\" content=\"Dr. benjamim anderson\" \/>\n\t<meta name=\"twitter:label2\" content=\"Tempo estimado de leitura\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutos\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/statorials.org\/pt\/r-numero-incorreto-de-indices-na-matriz\/\",\"url\":\"https:\/\/statorials.org\/pt\/r-numero-incorreto-de-indices-na-matriz\/\",\"name\":\"Como corrigir em R: n\u00famero incorreto de \u00edndices na matriz\",\"isPartOf\":{\"@id\":\"https:\/\/statorials.org\/pt\/#website\"},\"datePublished\":\"2023-07-24T16:36:13+00:00\",\"dateModified\":\"2023-07-24T16:36:13+00:00\",\"author\":{\"@id\":\"https:\/\/statorials.org\/pt\/#\/schema\/person\/e08f98e8db95e0aa9c310e1b27c9c666\"},\"description\":\"Este tutorial explica como corrigir o seguinte erro em R: N\u00famero incorreto de \u00edndices na matriz.\",\"breadcrumb\":{\"@id\":\"https:\/\/statorials.org\/pt\/r-numero-incorreto-de-indices-na-matriz\/#breadcrumb\"},\"inLanguage\":\"pt-PT\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/statorials.org\/pt\/r-numero-incorreto-de-indices-na-matriz\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/statorials.org\/pt\/r-numero-incorreto-de-indices-na-matriz\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Lar\",\"item\":\"https:\/\/statorials.org\/pt\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Como corrigir em r: n\u00famero incorreto de \u00edndices na matriz\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/statorials.org\/pt\/#website\",\"url\":\"https:\/\/statorials.org\/pt\/\",\"name\":\"Statorials\",\"description\":\"O seu guia para a literacia estat\u00edstica!\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/statorials.org\/pt\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"pt-PT\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/statorials.org\/pt\/#\/schema\/person\/e08f98e8db95e0aa9c310e1b27c9c666\",\"name\":\"Dr. benjamim anderson\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"pt-PT\",\"@id\":\"https:\/\/statorials.org\/pt\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/statorials.org\/pt\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg\",\"contentUrl\":\"https:\/\/statorials.org\/pt\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg\",\"caption\":\"Dr. benjamim anderson\"},\"description\":\"Ol\u00e1, sou Benjamin, um professor aposentado de estat\u00edstica que se tornou professor dedicado na Statorials. Com vasta experi\u00eancia e conhecimento na \u00e1rea de estat\u00edstica, estou empenhado em compartilhar meu conhecimento para capacitar os alunos por meio de Statorials. Saber mais\",\"sameAs\":[\"https:\/\/statorials.org\/pt\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Como corrigir em R: n\u00famero incorreto de \u00edndices na matriz","description":"Este tutorial explica como corrigir o seguinte erro em R: N\u00famero incorreto de \u00edndices na matriz.","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\/pt\/r-numero-incorreto-de-indices-na-matriz\/","og_locale":"pt_PT","og_type":"article","og_title":"Como corrigir em R: n\u00famero incorreto de \u00edndices na matriz","og_description":"Este tutorial explica como corrigir o seguinte erro em R: N\u00famero incorreto de \u00edndices na matriz.","og_url":"https:\/\/statorials.org\/pt\/r-numero-incorreto-de-indices-na-matriz\/","og_site_name":"Statorials","article_published_time":"2023-07-24T16:36:13+00:00","author":"Dr. benjamim anderson","twitter_card":"summary_large_image","twitter_misc":{"Escrito por":"Dr. benjamim anderson","Tempo estimado de leitura":"2 minutos"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/statorials.org\/pt\/r-numero-incorreto-de-indices-na-matriz\/","url":"https:\/\/statorials.org\/pt\/r-numero-incorreto-de-indices-na-matriz\/","name":"Como corrigir em R: n\u00famero incorreto de \u00edndices na matriz","isPartOf":{"@id":"https:\/\/statorials.org\/pt\/#website"},"datePublished":"2023-07-24T16:36:13+00:00","dateModified":"2023-07-24T16:36:13+00:00","author":{"@id":"https:\/\/statorials.org\/pt\/#\/schema\/person\/e08f98e8db95e0aa9c310e1b27c9c666"},"description":"Este tutorial explica como corrigir o seguinte erro em R: N\u00famero incorreto de \u00edndices na matriz.","breadcrumb":{"@id":"https:\/\/statorials.org\/pt\/r-numero-incorreto-de-indices-na-matriz\/#breadcrumb"},"inLanguage":"pt-PT","potentialAction":[{"@type":"ReadAction","target":["https:\/\/statorials.org\/pt\/r-numero-incorreto-de-indices-na-matriz\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/statorials.org\/pt\/r-numero-incorreto-de-indices-na-matriz\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Lar","item":"https:\/\/statorials.org\/pt\/"},{"@type":"ListItem","position":2,"name":"Como corrigir em r: n\u00famero incorreto de \u00edndices na matriz"}]},{"@type":"WebSite","@id":"https:\/\/statorials.org\/pt\/#website","url":"https:\/\/statorials.org\/pt\/","name":"Statorials","description":"O seu guia para a literacia estat\u00edstica!","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/statorials.org\/pt\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"pt-PT"},{"@type":"Person","@id":"https:\/\/statorials.org\/pt\/#\/schema\/person\/e08f98e8db95e0aa9c310e1b27c9c666","name":"Dr. benjamim anderson","image":{"@type":"ImageObject","inLanguage":"pt-PT","@id":"https:\/\/statorials.org\/pt\/#\/schema\/person\/image\/","url":"https:\/\/statorials.org\/pt\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg","contentUrl":"https:\/\/statorials.org\/pt\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg","caption":"Dr. benjamim anderson"},"description":"Ol\u00e1, sou Benjamin, um professor aposentado de estat\u00edstica que se tornou professor dedicado na Statorials. Com vasta experi\u00eancia e conhecimento na \u00e1rea de estat\u00edstica, estou empenhado em compartilhar meu conhecimento para capacitar os alunos por meio de Statorials. Saber mais","sameAs":["https:\/\/statorials.org\/pt"]}]}},"yoast_meta":{"yoast_wpseo_title":"","yoast_wpseo_metadesc":"","yoast_wpseo_canonical":""},"_links":{"self":[{"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/posts\/1865","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/comments?post=1865"}],"version-history":[{"count":0,"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/posts\/1865\/revisions"}],"wp:attachment":[{"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/media?parent=1865"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/categories?post=1865"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/tags?post=1865"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}