Error In X$results 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 this site About Us Learn more about Stack Overflow the company error subscript out of bounds r help Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs
String Subscript Out Of Bounds Error In Teradata
Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, subscript out of bounds r list just like you, 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
R Subscript Out Of Bounds In Matrices
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 > 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]) } } # error in pi[[j]] : subscript out of bounds rbind 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, 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 '
here for a quick overview of the site Help Center Detailed answers to any questions
Solving Problems Of Subscript Out Of Bounds In R
you might have Meta Discuss the workings and policies of this
Error During Wrapup: Subscript Out Of Bounds
site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers rbind subscript out of bounds or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a http://stackoverflow.com/questions/15031338/subscript-out-of-bounds-general-definition-and-solution community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Subscript out of bound error in R up vote 1 down vote favorite While Using factanal function from stats package for performing factor analysis. I tried following thing. library(mirt) library(ltm) library(psych) library(stats) data(SAT12) http://stackoverflow.com/questions/28321135/subscript-out-of-bound-error-in-r data=SAT12 cor_mat=polychoric(data, ML=TRUE, global=F) fit <- factanal(factors=2, n.obs=nrow(data), covmat=cor_mat$rho) Divide_item_Factor_Loading(fit) when I am trying to run Divide_item_Factor_Loading(fit) an error called Error in a[[i]][[2]] : subscript out of bounds pops up. my complete code of Divide_item_Factor_Loading: Divide_item_Factor_Loading=function(fit) { a=list() items=NULL for(i in 1:nrow(fit$loadings)) ######corresponding to rows of loading matrix { k=which(fit$loadings[i,]==max(abs(fit$loadings[i,]))) a[[i]]=c(i,as.numeric(k)) } fact_item_mat=matrix(, nrow=nrow(fit$loadings), ncol=ncol(fit$loadings)) for(j in 1:(ncol(fit$loadings))) { for(i in 1:(nrow(fit$loadings))) { if(a[[i]][[2]]==j) {fact_item_mat[i,j]=a[[i]][[1]]} } } nam=names(fit$loadings[,1]) factor=list() for(i in 1:ncol(fit$loadings)) { factor[[i]]=sort(fact_item_mat[,i], decreasing = FALSE, na.last = NA) fac=factor[[i]] fac=nam[fac] factor[[i]]=fac } names(factor)=paste("factor", 1:ncol(fit$loadings), sep="") return(factor) } What steps should I take now to avoid this error? r factor-analysis share|improve this question edited Feb 5 '15 at 11:47 asked Feb 4 '15 at 12:14 user3755708 As Andrei says this is just the print method - all values are in the loadings matrix. Look at loadings(fit) and loadings(fit)[]. They look different because of the print method but the loadings matrices are the same. Check str(lo
[ 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 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])) http://tolstoy.newcastle.edu.au/R/help/04/07/1101.html 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 subscript out of 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 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. -.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Wed 21 Jul 2004 - 04:49:20 EST On Tue, 2004-07-20 at 13:12, Marie-Pierre Sylvestre wrote: > Hi > > I am running a simulation that involves a loop calling three 2 > functions that I have written. Everything works fine when the inside > of the loop is performed up to 1000 times (for (i in 1:750)). > > However, I sometimes get : ''Error: subscript out of bounds'' if I try > to increase the loop 'size' to 1000. I am thinking it has to to with > memory but I am not sure. I have increased my memory size to 512M but > it does not solve my problem. > > It would take to much place to copy and paste my code here. It would > be helpful if you could tell me whether my problem may or may not be > related to memory size. > > Beside, what's the difference between > > Error: subscript out of bounds > Error: subscript out of range ? > > > Regards > > M-P Sylvestre If this was a memory error, you would probably get a "cannot allocate ..." type of error message. More than likely, the object upon which you are using the loop has dimensions which are smaller than the value(s) that your loops are using for indexing into the object. The use of either dim(object) or str(object) will give you more information here. When you increase the loop size, presumably, you have not increased the size of your underlying object in kind. For example, if your object (say a matrix) has dimensions of 500 rows and 10 columns, your loop is trying to index object[510, 12], which is 'out of bounds' for your object. A search of the R source code using grep suggests that the 'out of bounds' message is generally used when trying to index (subset) an object with a value or values that are not correct as I have above. This could also be a single dimension vector, BTW. For example, trying to index object[100] when your vector is only 50 elements in size. In the case of the 'out of range' message, that appears to be typically used when an argument to a function or other constrained parameter is above or below the valid range that the argument or parameter may have. A scan of where and how the messages are used indicates some variability, probably as a result of the multiple authors involved. HTH, Marc Schwartz R-help@stat.math.ethz.ch mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/