Error In Node.agesubtree Subscript Out Of Bounds
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn subscript out of bounds in r more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags
Error In Pi[[j]] : Subscript Out Of Bounds Rbind
Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, solving problems of subscript out of bounds in r helping each other. Join them; it only takes a minute: Sign up Subscript out of bounds - general definition and solution? up vote 16 down vote favorite 18 When working with R I frequently get the error message
Rbind Subscript Out Of Bounds
"subscript out of bounds". For example: # Load necessary libraries and data library(igraph) library(NetData) data(kracknets, package = "NetData") # Reduce dataset to nonzero edges krack_full_nonzero_edges <- subset(krack_full_data_frame, (advice_tie > 0 | friendship_tie > 0 | reports_to_tie > 0)) # convert to graph data farme krack_full <- graph.data.frame(krack_full_nonzero_edges) # Set vertex attributes for (i in V(krack_full)) { for (j in names(attributes)) { krack_full <- set.vertex.attribute(krack_full, j, index=i, attributes[i+1,j]) } } # Calculate reachability for each vertix reachability error during wrapup: subscript out of bounds <- 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 <- 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 <- reachability(krack_full, 'in') reach_full_in This generates the following error Error in reach_mat[i, alter] = 1 : subscript out of bounds. 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: What is the definition of a subscript-out-of-bounds error? What causes it? Are there any generic ways of approaching this kind of error? r matrix sna share|improve this question asked Feb 22 '13 at 19:00 histelheim 1,40921339 1 @January has it. It means you're trying to get something, say a column or row, that doesn't exist. For example, say your table has 10 rows and your function tries to call for row 15. –Ben Feb 22 '13 at 19:16 1 And for anyone who's wondering about this PARTICULAR piece of code (from the McFarland network analysis labs) it's because igraph has changed its indexing scheme from 0-based to 1-based, and so '(i-1)' in 'subcomponent' should be just 'i'. –Sophologist Apr 30 at 17:46 add a comment| 4 Answers 4 a
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more
Error In * Tmp * Subscript Out Of Bounds
about Stack Overflow the company Business Learn more about hiring developers or posting ads
Options(error=recover)
with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow subscript out of bounds shiny is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up R error type “Subscript out of bounds” up vote 1 down vote favorite http://stackoverflow.com/questions/15031338/subscript-out-of-bounds-general-definition-and-solution I am simulating a correlation matrix, where the 60 variables correlate in the following way: more highly (0.6) for every two variables (1-2, 3-4... 59-60) moderate (0.3) for every group of 12 variables (1-12,13-24...) mc <- matrix(0,60,60) diag(mc) <- 1 for (c in seq(1,59,2)){ # every pair of variables in order are given 0.6 correlation mc[c,c+1] <- 0.6 mc[c+1,c] <- 0.6 } for (n in seq(1,51,10)){ # every group http://stackoverflow.com/questions/21114784/r-error-type-subscript-out-of-bounds of 12 are given correlation of 0.3 for (w in seq(12,60,12)){ # these are variables 11-12, 21-22 and such. mc[n:n+1,c(n+2,w)] <- 0.2 mc[c(n+2,w),n:n+1] <- 0.2 } } for (m in seq(3,9,2)){ # every group of 12 are given correlation of 0.3 for (w in seq(12,60,12)){ # these variables are the rest. mc[m:m+1,c(1:m-1,m+2:w)] <- 0.2 mc[c(1:m-1,m+2:w),m:m+1] <- 0.2 } } The first loop works well, but not the second and third ones. I get this error message: Error in `[<-`(`*tmp*`, m:m + 1, c(1:m - 1, m + 2:w), value = 0.2) : subscript out of bounds Error in `[<-`(`*tmp*`, m:m + 1, c(1:m - 1, m + 2:w), value = 0.2) : subscript out of bounds I would really appreciate any hints, since I don't see the loop commands get to exceed the matrix dimensions. Thanks a lot in advance! r loops share|improve this question edited Jan 14 '14 at 13:48 asked Jan 14 '14 at 13:29 Gina Zetkin 71118 try putting cat() or print() statements in your code to see what's going on, or use options(error=recover) to have R dump you into a browser when an error occurs ... –Ben Bolker Jan 14 '14 at 13:35 3 Note that : takes precedence ov
[ author ] Hi, the "subscript out of bounds" error nas nothing to do with memory. It reads exactly what it says: https://stat.ethz.ch/pipermail/r-help/2001-November/016421.html that subscript (index) is out of given bounds of a vector/matrix/general array... Do you still have p as a _matrix_ 2by1?, not as a _vector_ of length 2? Moreover, if p is 2by1 matrix, diagp<-diag(c(p[1,1],p[2,1])) is 2by2, not 4by4. Anyway, store p using as.matrix command (or try ?as.matrix for help) Jan ------------------------------------------------- designed for _monospaced_ font ------------------------------------------------- /- Jan subscript out Svatos, PhD Sokolovska 855/225 -/ /- Data Analyst, Prague 9 -/ /- Eurotel Praha 190 00 -/ /- jan_svatos at eurotel.cz Czechia -/ ------------------------------------------------- - - - Original message: - - - From: owner-r-help at stat.math.ethz.ch Send: 11/12/01 1:03:53 PM To: r-help at stat.math.ethz.ch Subject: [R] 'subscript out of bounds' in matrices Dear list Having read through all the subscript out of archives of the mailing lists, I've had no luck finding the answer to my problem. I am running a for(i in 1:n) loop and am creating a matrix, p, for each of the n observations. This matrix p is a 2x1 matrix. I am then doing the following: diagp<-diag(c(p[1,1],p[2,1])) to create a matrix with the elements of P on the diagonal (i.e. a 4x4 matrix). This works fine when I have n=60, however when I increase the size of the data set to n=100, I get the error message: Error in diag(c(p[1, 1], p[2, 1])) : subscript out of bounds I put this down to a problem with memory at first so increased the memory in my PC from 128Mb to 256Mb yet it made no difference and the error still occurred. I am eventually going to need to run this command for n=8000. Could anybody suggest what I can do to solve this problem? Do I need to store my matrix as another type of variable? Thanks in advance for any help Laura -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
be down. Please try the request again. Your cache administrator is webmaster. Generated Tue, 11 Oct 2016 18:34:55 GMT by s_ac15 (squid/3.5.20)