Hello, R-users, I have a datafile with 37313 records and each record has 5 different measurements on the same variables. The format looks like this: treeID, VIG0, VIG1, VIG2, VIG3, VIG4 I was trying to convert the one row record to 5 rows record with format like this (treeID, MEASUREMENT, VIGOR). My code like this: treeMeas<-matrix(data=0,nrow=(length(tree1$indivTree)*5), ncol=3) colnames(treeMeas)<-c("indivTree", "meas", "vigor") for(i in 1:length(tree1$indivTree)) { treeMeas[(i-1)*5+1:(i*5),1]<-tree1$indivTree[i] treeMeas[(i-1)*5+1:(i*5),2]<-c(0:4) treeMeas[(i-1)*5+1:(i*5),3]<-c(tree1$VIG0[i], tree1$VIG1[i], tree1$VIG2[i], tree1$VIG3[i], tree1$VIG4[i]) } When I run the code, I always got error message like this " Error in treeMeas[(i - 1) * 5 + 1:(i * 5), 1] <- tree1$indivTree[i] : subscript out of bounds". I couldn't figure out why subscript out of bounds. Is this because the matrix is too big (186565 by 3)? Any one can help? Thank you very much. Yuzhen [[alternative HTML version deleted]]
______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.