{"id":1771,"date":"2023-07-25T01:26:42","date_gmt":"2023-07-25T01:26:42","guid":{"rendered":"https:\/\/statorials.org\/pt\/r-indice-de-erro-fora-do-intervalo\/"},"modified":"2023-07-25T01:26:42","modified_gmt":"2023-07-25T01:26:42","slug":"r-indice-de-erro-fora-do-intervalo","status":"publish","type":"post","link":"https:\/\/statorials.org\/pt\/r-indice-de-erro-fora-do-intervalo\/","title":{"rendered":"Como reparar em r: \u00edndice fora dos limites"},"content":{"rendered":"<p><\/p>\n<hr>\n<p><span style=\"color: #000000;\">Um erro comum que voc\u00ea pode encontrar em R \u00e9:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong>Error in x[, 4]: subscript out of bounds\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Este erro ocorre quando voc\u00ea tenta acessar uma coluna ou linha de uma matriz que n\u00e3o existe.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Este tutorial mostra as etapas exatas que voc\u00ea pode seguir para resolver esse erro, usando a seguinte matriz como exemplo:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#make this example reproducible<\/span>\nset. <span style=\"color: #3366ff;\">seeds<\/span> (0)\n\n<span style=\"color: #008080;\">#create matrix with 10 rows and 3 columns<\/span>\nx = matrix(data = sample. <span style=\"color: #3366ff;\">int<\/span> (100, 30), nrow = 10, ncol = 3)\n\n<span style=\"color: #008080;\">#print matrix\n<\/span><span style=\"color: #993300;\">print<\/span> (x)\n\n      [,1] [,2] [,3]\n [1,] 14 51 96\n [2,] 68 85 44\n [3,] 39 21 33\n [4,] 1 54 35\n [5,] 34 74 70\n [6,] 87 7 86\n [7,] 43 73 42\n [8,] 100 79 38\n [9,] 82 37 20\n[10,] 59 92 28\n<\/strong><\/pre>\n<h3> <strong>Exemplo #1: \u00edndice fora do intervalo (com linhas)<\/strong><\/h3>\n<p> <span style=\"color: #000000;\">O c\u00f3digo a seguir tenta acessar a 11\u00aa linha da matriz, que n\u00e3o existe:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#attempt to display 11th row of matrix<\/span>\nx[11, ]\n\nError in x[11, ]: subscript out of bounds\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Como a 11\u00aa linha da matriz n\u00e3o existe, obtemos o erro <strong>do \u00edndice fora dos limites<\/strong> .<\/span><\/p>\n<p> <span style=\"color: #000000;\">Se n\u00e3o sabemos quantas linhas existem na matriz, podemos usar a fun\u00e7\u00e3o <strong>nrow()<\/strong> para descobrir:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#display number of rows in matrix<\/span>\nnrow(x)\n\n[1] 10\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Podemos ver que existem apenas 10 linhas na matriz. Portanto, s\u00f3 podemos usar n\u00fameros menores ou iguais a 10 para acessar as linhas.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Por exemplo, podemos usar a seguinte sintaxe para exibir a 10\u00aa linha da matriz:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#display 10th row of matrix<\/span>\nx[10, ]\n\n[1] 59 92 28\n<\/strong><\/pre>\n<h3> <strong>Exemplo #2: \u00edndice fora do intervalo (com colunas)<\/strong><\/h3>\n<p> <span style=\"color: #000000;\">O c\u00f3digo a seguir tenta acessar a 4\u00aa coluna da matriz, que n\u00e3o existe:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#attempt to display 4th column of matrix<\/span>\nx[, 4]\n\nError in x[, 4]: subscript out of bounds\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Como a 4\u00aa coluna da matriz n\u00e3o existe, obtemos o erro <strong>do \u00edndice fora dos limites<\/strong> .<\/span><\/p>\n<p> <span style=\"color: #000000;\">Se n\u00e3o sabemos quantas colunas a matriz cont\u00e9m, podemos usar a fun\u00e7\u00e3o <strong>ncol()<\/strong> para descobrir:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#display number of columns in matrix<\/span>\nncol(x)\n\n[1] 3\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Vemos que existem apenas 3 colunas na matriz. Assim, s\u00f3 podemos utilizar n\u00fameros menores ou iguais a 3 para acessar as colunas.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Por exemplo, podemos usar a seguinte sintaxe para exibir a terceira coluna da matriz:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#display 3rd column of matrix<\/span>\nx[, 3]\n\n[1] 96 44 33 35 70 86 42 38 20 28<\/strong><\/pre>\n<h3> <strong>Exemplo #3: \u00edndice fora do intervalo (linhas e colunas)<\/strong><\/h3>\n<p> <span style=\"color: #000000;\">O c\u00f3digo a seguir tenta acessar o valor da 11\u00aa linha e 4\u00aa coluna da matriz, que n\u00e3o existe:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#attempt to display value in 11th row and 4th column<\/span>\nx[11, 4]\n\nError in x[11, 4]: subscript out of bounds\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Como nem a 11\u00aa linha nem a 4\u00aa coluna da matriz existem, obtemos o erro <strong>do \u00edndice fora dos limites<\/strong> .<\/span><\/p>\n<p> <span style=\"color: #000000;\">Se n\u00e3o sabemos quantas linhas e colunas existem na matriz, podemos usar a fun\u00e7\u00e3o <strong>dim()<\/strong> para descobrir:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#display number of rows and columns in matrix<\/span>\ndim(x)\n\n[1] 10 3\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Vemos que existem apenas 10 linhas e 3 colunas na matriz. Assim, s\u00f3 podemos utilizar n\u00fameros menores ou iguais a esses valores no acesso a linhas e colunas.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Por exemplo, podemos usar a seguinte sintaxe para exibir o valor na 10\u00aa linha e na 3\u00aa coluna da matriz:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#display value in 10th row and 3rd column of matrix<\/span>\nx[10, 3]\n\n[1] 28\n<\/strong><\/pre>\n<h3> <span style=\"color: #000000;\"><strong>Recursos adicionais<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">Os tutoriais a seguir explicam como resolver outros erros comuns em R:<\/span><\/p>\n<p> <a href=\"https:\/\/statorials.org\/pt\/erro-rbind-em-nomes-r-nao-correspondem-aos-nomes-anteriores\/\" target=\"_blank\" rel=\"noopener\">Como corrigir em R: os nomes n\u00e3o correspondem aos nomes anteriores<\/a><br \/> <a href=\"https:\/\/statorials.org\/pt\">Como corrigir em R: o comprimento de um objeto mais longo n\u00e3o \u00e9 m\u00faltiplo do comprimento de um objeto mais curto<\/a><br \/> <a href=\"https:\/\/statorials.org\/pt\/contrastes-aplicados-a-fatores-com-2-ou-mais-niveis\/\" target=\"_blank\" rel=\"noopener\">Como corrigir em R: contrastes s\u00f3 podem ser aplicados a fatores com 2 ou mais n\u00edveis<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Um erro comum que voc\u00ea pode encontrar em R \u00e9: Error in x[, 4]: subscript out of bounds Este erro ocorre quando voc\u00ea tenta acessar uma coluna ou linha de uma matriz que n\u00e3o existe. Este tutorial mostra as etapas exatas que voc\u00ea pode seguir para resolver esse erro, usando a seguinte matriz como exemplo: [&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-1771","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 reparar em R: dica fora dos limites - Statorials<\/title>\n<meta name=\"description\" content=\"Este tutorial explica como corrigir o seguinte erro em R: \u00edndice fora do intervalo.\" \/>\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-indice-de-erro-fora-do-intervalo\/\" \/>\n<meta property=\"og:locale\" content=\"pt_PT\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Como reparar em R: dica fora dos limites - Statorials\" \/>\n<meta property=\"og:description\" content=\"Este tutorial explica como corrigir o seguinte erro em R: \u00edndice fora do intervalo.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/statorials.org\/pt\/r-indice-de-erro-fora-do-intervalo\/\" \/>\n<meta property=\"og:site_name\" content=\"Statorials\" \/>\n<meta property=\"article:published_time\" content=\"2023-07-25T01:26:42+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=\"3 minutos\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/statorials.org\/pt\/r-indice-de-erro-fora-do-intervalo\/\",\"url\":\"https:\/\/statorials.org\/pt\/r-indice-de-erro-fora-do-intervalo\/\",\"name\":\"Como reparar em R: dica fora dos limites - Statorials\",\"isPartOf\":{\"@id\":\"https:\/\/statorials.org\/pt\/#website\"},\"datePublished\":\"2023-07-25T01:26:42+00:00\",\"dateModified\":\"2023-07-25T01:26:42+00:00\",\"author\":{\"@id\":\"https:\/\/statorials.org\/pt\/#\/schema\/person\/e08f98e8db95e0aa9c310e1b27c9c666\"},\"description\":\"Este tutorial explica como corrigir o seguinte erro em R: \u00edndice fora do intervalo.\",\"breadcrumb\":{\"@id\":\"https:\/\/statorials.org\/pt\/r-indice-de-erro-fora-do-intervalo\/#breadcrumb\"},\"inLanguage\":\"pt-PT\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/statorials.org\/pt\/r-indice-de-erro-fora-do-intervalo\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/statorials.org\/pt\/r-indice-de-erro-fora-do-intervalo\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Lar\",\"item\":\"https:\/\/statorials.org\/pt\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Como reparar em r: \u00edndice fora dos limites\"}]},{\"@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 reparar em R: dica fora dos limites - Statorials","description":"Este tutorial explica como corrigir o seguinte erro em R: \u00edndice fora do intervalo.","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-indice-de-erro-fora-do-intervalo\/","og_locale":"pt_PT","og_type":"article","og_title":"Como reparar em R: dica fora dos limites - Statorials","og_description":"Este tutorial explica como corrigir o seguinte erro em R: \u00edndice fora do intervalo.","og_url":"https:\/\/statorials.org\/pt\/r-indice-de-erro-fora-do-intervalo\/","og_site_name":"Statorials","article_published_time":"2023-07-25T01:26:42+00:00","author":"Dr. benjamim anderson","twitter_card":"summary_large_image","twitter_misc":{"Escrito por":"Dr. benjamim anderson","Tempo estimado de leitura":"3 minutos"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/statorials.org\/pt\/r-indice-de-erro-fora-do-intervalo\/","url":"https:\/\/statorials.org\/pt\/r-indice-de-erro-fora-do-intervalo\/","name":"Como reparar em R: dica fora dos limites - Statorials","isPartOf":{"@id":"https:\/\/statorials.org\/pt\/#website"},"datePublished":"2023-07-25T01:26:42+00:00","dateModified":"2023-07-25T01:26:42+00:00","author":{"@id":"https:\/\/statorials.org\/pt\/#\/schema\/person\/e08f98e8db95e0aa9c310e1b27c9c666"},"description":"Este tutorial explica como corrigir o seguinte erro em R: \u00edndice fora do intervalo.","breadcrumb":{"@id":"https:\/\/statorials.org\/pt\/r-indice-de-erro-fora-do-intervalo\/#breadcrumb"},"inLanguage":"pt-PT","potentialAction":[{"@type":"ReadAction","target":["https:\/\/statorials.org\/pt\/r-indice-de-erro-fora-do-intervalo\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/statorials.org\/pt\/r-indice-de-erro-fora-do-intervalo\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Lar","item":"https:\/\/statorials.org\/pt\/"},{"@type":"ListItem","position":2,"name":"Como reparar em r: \u00edndice fora dos limites"}]},{"@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\/1771","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=1771"}],"version-history":[{"count":0,"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/posts\/1771\/revisions"}],"wp:attachment":[{"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/media?parent=1771"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/categories?post=1771"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/tags?post=1771"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}