Error In Re I 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
Error In X I Subscript Out Of Bounds
site About Us Learn more about Stack Overflow the company Business Learn more error in xi j subscript out of bounds about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss
Error In Rval I J Drop = Drop. ... Subscript Out Of Bounds
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 How to fix subscript out of bounds list r “Subscript out of bounds error” up vote 1 down vote favorite I have a R code applied on certain data X and Y, The code is rather simple but it gives certain error "Error in `[<-`(`*tmp*`, R, , value = c(1, 1)) : subscript out of bounds" Can anyone please help me to sort it out. #X <- read.table("data1.dat") #Y <-read.table("data2.dat") X <- c(1,2,43,1,6,5,44,6.8,7.8,9.8) r subscript out of bounds in matrices Y <- c(1,3,31,26,78,4,5,44,4,6) length(X) length(Y) Rmax <- 15 data_len <- length(X) Z <- as.matrix(cbind(X,Y)) Cen <- matrix(rnorm(2*Rmax),Rmax,2) Xe <- as.matrix(cbind(1,X)) w <- matrix(rnorm(2*Rmax),Rmax,2) lambda <- matrix(rnorm(1*Rmax),Rmax,1) U <- matrix(rnorm(1*Rmax),Rmax,1) gamma <- matrix(rnorm(2*Rmax),Rmax,2) P_matrix <- 10^3*matrix(rnorm(2*2),2,2) Yhat <- matrix(,data_len,1) a1 <- 0 a2 <- 0 a4 <- matrix(rnorm(2),1,2) a3 <- 0 Pz <- 0 P <- matrix(rnorm(1*Rmax),Rmax,1) dist <- numeric(Rmax) r <- 0.04 m3 <- 0 k <- 1 while (k < length(X)){ if(k == 1){ Cen[1,] <- Z[k,]; U[k,] <- 1; lambda <- matrix(sapply(U,function(x){x/sum (U)}),Rmax,1); Yhat[k,] <- Xe[k,]%*%(t(w)%*%lambda) } else { a1 <- big_V(Z[k,]);a2 <- a2+ big_V(Z[k-1,]);a4 <- a4 + Z[k-1,];a3 <- sum(Z[k,]*a4) B <- ((k-1)*(a1+1))+a2-(2*a3); Pz <- (k-1)/B for(i in 1:length(P)){ P[i] <- ((k-1)*P[i])/((k-2)+(P[i])+(P[i])*(dist(Z[k-1,],Z[k,]))) } print(k) for (i in 1:Rmax){ dist[i] <- abs(sqrt(sum((Z[k,]-Cen[i,])^2))) } p1 <- min(dist) p2 <- which.min(dist) m1 <- max(P) m2 <- which.max(P) m3 <- (p1/r)+(Pz/m1) if (Pz > m1 & m3 < 1){ Cen[m2,] <- Z[k,] P[m2] <- Pz } for (i in 1:Rmax){ U[i] <- exp(-r*(abs(sqrt(sum((X[k,]-Cen[i,1])^2))))) } lambda <- sapply(U, function(x) x/sum(U)) P_matrix <- (diag(2)-(t(gamma)%*%lambda%*%Xe[k,]))%*%P_matrix A <- lambda%*%Xe[k,] Z1 <- P_matrix%*%t(A) Z2 <- A%*%P_matrix%*%t(A) Z3 <- diag(15)+Z2 gamma <- t(Z1%*%solve(Z3)) w_bar <- Xe[1,]%*%t(w)%*%lambda w <-
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies
Gbm Subscript Out Of Bounds
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 Documentation Tags Users
Subscript Out Of Bounds In R
Badges Ask Question 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 http://stackoverflow.com/questions/26541594/how-to-fix-subscript-out-of-bounds-error minute: Sign up For Loop Error - Subscript Out of Bounds up vote -2 down vote favorite I have been searching 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{ http://stackoverflow.com/questions/24666313/for-loop-error-subscript-out-of-bounds 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 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 A
view ♦ ♦ | Report Content as Inappropriate ♦ ♦ Subscript out of Bounds I currently have this code: for(j in 2:n){ for(i in 1:(j-1)){ # Make sure the inputs are http://r.789695.n4.nabble.com/Subscript-out-of-Bounds-td3481990.html for the matrix "m" input1=rownames(m)[i] input2=colnames(m)[j] q=t[(t$Rec1==input1 & t$Rec2==input2),output] if(length(q)==0){ q=t[(t$Rec1==input2 & t$Rec2==input1),output] } m[i,j]=mean(q) m[j,i]=mean(q) m[j,j]=mean(q) }} http://tolstoy.newcastle.edu.au/R/help/04/07/1101.html I already created a 20x20 matrix "m" and have the rows and columns made up: m=matrix(data=NA, nrow=rl, ncol=rl, dimnames=list(R1=rec.list, R2=rec.list)) the length of a column in the matrix is 20 the length of n is 430 subscript out When I run this, the error: "Subscript is out of Bounds" appears when it reaches the m[i,j]. Checking again, the issue is primarily with "j" How would I go about fixing this issue (nevermind the "mean(q)", as I don't even know if that works and didn't get the chance to explore it)? [[alternative HTML version deleted]] ______________________________________________ [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, subscript out of minimal, self-contained, reproducible code. Duncan Murdoch-2 Threaded Open this post in threaded view ♦ ♦ | Report Content as Inappropriate ♦ ♦ Re: Subscript out of Bounds On 28/04/2011 3:49 PM, Dat Mai wrote: > I currently have this code: > > for(j in 2:n){ > for(i in 1:(j-1)){ > > # Make sure the inputs are for the matrix "m" > input1=rownames(m)[i] > input2=colnames(m)[j] > > q=t[(t$Rec1==input1& t$Rec2==input2),output] > > if(length(q)==0){ > q=t[(t$Rec1==input2& t$Rec2==input1),output] > } > > m[i,j]=mean(q) > m[j,i]=mean(q) > m[j,j]=mean(q) > }} > > I already created a 20x20 matrix "m" and have the rows and columns made up: > > m=matrix(data=NA, nrow=rl, ncol=rl, dimnames=list(R1=rec.list, R2=rec.list)) > > the length of a column in the matrix is 20 > the length of n is 430 > > When I run this, the error: "Subscript is out of Bounds" appears when it > reaches the m[i,j]. > Checking again, the issue is primarily with "j" > > How would I go about fixing this issue (nevermind the "mean(q)", as I don't > even know if that works and didn't get the chance to explore it)? Just before you get to that line
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/posting-guide.html Received on Wed Jul 21 04:57:01 2004 This message: [ Message body ] Next message: Kjetil Halvorsen: "Re: [R] Sort a data frame" Previous message: Sundar Dorai-Raj: "Re: [R] regression slope" In reply to Marie-Pierre Sylvestr