Error In X 1 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 error in t i subscript out of bounds this site About Us Learn more about Stack Overflow the company Business Learn error in x$content i subscript out of bounds more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question error in x 1 subscript out of bounds in r x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up error in *tmp* jj subscript out of bounds 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 "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 >
Error In X@coords I Drop = False Subscript Out Of Bounds
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 <- 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, t
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
Subscript Out Of Bounds List R
the company Business Learn more about hiring developers or posting ads with us Stack shiny subscript out of bounds Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of error subscript out of bounds r help 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up For Loop Error - Subscript Out of Bounds up vote -2 down vote favorite I have been searching http://stackoverflow.com/questions/15031338/subscript-out-of-bounds-general-definition-and-solution the internet for hours trying to resolve the following error: Error in Dataset[i, Year] : subscript out of bounds Below is the section of my code producing the error: for(i in (2*YF):1){ if(Dataset[i,Year] < 0){ Dataset[i,Total_Births] <- Dataset[i,Male_Births] + Dataset[i,Female_Births] }else{ Dataset[i,Total_Births] <- with(Dataset, sum(Dataset[Female_Births > (i-AEB) & Female_Births <= (i-ABB),Female_Births])) Dataset[i,Male_Births] <- MBR * Dataset[i,Total_Births] Dataset[i,Female_Births] <- FBR * Dataset[i,Total_Births] } } 'Year' starts with 500 and ends with -500 skipping http://stackoverflow.com/questions/24666313/for-loop-error-subscript-out-of-bounds 0. I need to populate the columns from the bottom up. Any help would be much appreciated. Below is the full code: #DECLARE PARAMETERS YF <- 500 #Years Ago Flood Occurred FBR <- .5 #Historical Female Birth Rate MBR <- (1-FBR) #Historical Male Birth Rate ABF <- 12 #Average Births per Female AL <- 60 #Average Lifespan NF <- 4 #Number of Females at Debark NM <- 4 #Number of Males at Debark NAD <- 40 #Noah's Age at Debark NWA <- 40 #Emzara's (Noah's Wife) Age at Debark SA <- 35 #Shem's (Noah's Son) Age at Debark SWA <- 35 #Sedeqetelebab's (Shem's Wife) Age at Debark HA <- 30 #Ham (Noah's Son) Age at Debark HWA <- 30 #Ne'elatama'uk's (Ham's Wife) Age at Debark JA <- 25 #Japheth (Noah's Son) Age at Debark JWA <- 25 #Adataneses's (Japheth's Wife) Age at Debark CP <- 20 #Current Population of World Today ABB <- 18 #Age Begin Births AEB <- 30 #Age End Births ###CREATE MATRIX - YEAR### YearA <- YF:1 YearB <- -1:-YF Year <- c(YearA,YearB) ###POPULATE BIRTHS DATA### BF_Male_Births <- rep.int(0,YF) BF_Female_Births <- rep.int(0,YF) BF_Male_Births[NAD] <- 1 BF_Female_Births[NWA] <- 1 BF_Male_Births[SA] <- 1 BF_Female_Births[SWA] <- 1 BF_Male_Births[HA] <- 1 BF_Female_Births[HWA] <- 1 BF_Male_Births[JA] <- 1 BF_Female_Births[JWA] <- 1 BF_Total_Births <- rep.int(0,YF) AF_Male_Births <- rep.i
[ author ] Hi, the "subscript out of bounds" error nas nothing to do with memory. It reads exactly what it says: that subscript (index) is https://stat.ethz.ch/pipermail/r-help/2001-November/016421.html out of given bounds of a vector/matrix/general array... Do you still have p http://r.789695.n4.nabble.com/how-does-a-valid-subscript-can-produce-an-quot-subscript-out-of-bounds-quot-error-td4693536.html 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 Svatos, PhD Sokolovska 855/225 -/ /- Data Analyst, subscript out 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 archives of the mailing lists, I've had no luck finding the answer to subscript out of 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 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. -.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._. _._._ -.-
messages Witold E Wolski Threaded Open this post in threaded view ♦ ♦ | Report Content as Inappropriate ♦ ♦ how does a valid subscript can produce an "subscript out of bounds" error? how does a valid subscript (see first 2 lines) can produce an "subscript out of bounds" error (see line 4)? 1> sum(!rownames(msexp$rt) %in% msexp$pepinfo$transition_group_id) [1] 0 2> sum(!msexp$pepinfo$transition_group_id %in% rownames(msexp$rt)) [1] 0 3> class(msexp$rt) [1] "matrix" 4> msexp$rt = as.matrix(msexp$rt[msexp$pepinfo$transition_group_id,]) Error in msexp$rt[msexp$pepinfo$transition_group_id, ] : subscript out of bounds > -- Witold Eryk Wolski ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code. Duncan Murdoch-2 Threaded Open this post in threaded view ♦ ♦ | Report Content as Inappropriate ♦ ♦ Re: how does a valid subscript can produce an "subscript out of bounds" error? On 04/07/2014, 6:35 PM, Witold E Wolski wrote: > how does a valid subscript (see first 2 lines) can produce an > "subscript out of bounds" error (see line 4)? > > > 1> sum(!rownames(msexp$rt) %in% msexp$pepinfo$transition_group_id) > [1] 0 > 2> sum(!msexp$pepinfo$transition_group_id %in% rownames(msexp$rt)) > [1] 0 > 3> class(msexp$rt) > [1] "matrix" > 4> msexp$rt = as.matrix(msexp$rt[msexp$pepinfo$transition_group_id,]) > Error in msexp$rt[msexp$pepinfo$transition_group_id, ] : > subscript out of bounds >> > How are we supposed to know, since you didn't show us msexp$pepinfo$transition_group_id or the thing it was indexing, msexp$rt ? Please post reprod