Note that there are some explanatory texts on larger screens.

plurals
  1. POSubscript out of bounds - general definition and solution?
    primarykey
    data
    text
    <p>When working with R I frequently get the error message "subscript out of bounds". <a href="http://sna.stanford.edu/sna_R_labs/lab_2.R">For example</a>:</p> <pre><code># Load necessary libraries and data library(igraph) library(NetData) data(kracknets, package = "NetData") # Reduce dataset to nonzero edges krack_full_nonzero_edges &lt;- subset(krack_full_data_frame, (advice_tie &gt; 0 | friendship_tie &gt; 0 | reports_to_tie &gt; 0)) # convert to graph data farme krack_full &lt;- graph.data.frame(krack_full_nonzero_edges) # Set vertex attributes for (i in V(krack_full)) { for (j in names(attributes)) { krack_full &lt;- set.vertex.attribute(krack_full, j, index=i, attributes[i+1,j]) } } # Calculate reachability for each vertix reachability &lt;- function(g, m) { reach_mat = matrix(nrow = vcount(g), ncol = vcount(g)) for (i in 1:vcount(g)) { reach_mat[i,] = 0 this_node_reach &lt;- subcomponent(g, (i - 1), mode = m) for (j in 1:(length(this_node_reach))) { alter = this_node_reach[j] + 1 reach_mat[i, alter] = 1 } } return(reach_mat) } reach_full_in &lt;- reachability(krack_full, 'in') reach_full_in </code></pre> <p>This generates the following error <code>Error in reach_mat[i, alter] = 1 : subscript out of bounds</code>.</p> <p>However, my question is not about this particular piece of code (even though it would be helpful to solve that too), but my question is more general:</p> <ul> <li>What is the definition of a subscript-out-of-bounds error? What causes it?</li> <li>Are there any generic ways of approaching this kind of error?</li> </ul>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload