Hi folks, I'm trying to accomplish something that seems like it should be straightforward, but I've gotten tied in knots trying to figure it out. A toy example of my issue is below. I've played with diff and can't seem to figure out a systematic solution that will give me the two column output independent of the number of breakpoints in the vector... test<-c(1:5, 22:29,33:40) example.output<-matrix(c(1,5,22,29,33,40),nrow=3,ncol=2,byrow=TRUE) Any ideas? Thanks! Lizzy -- "The obvious goal of any bacterium is to become bacteria." Lizzy Wilbanks Graduate Student, Eisen and Facciotti Labs UC Davis, Microbiology Graduate Group
May be: ?matrix(c(test[c(TRUE,diff(test)>1)],test[c(which(diff(test)>1),length(test))]),ncol=2) #???? [,1] [,2] #[1,]??? 1??? 5 #[2,]?? 22?? 29 #[3,]?? 33?? 40 A.K. ----- Original Message ----- From: Lizzy Wilbanks <egwilbanks at ucdavis.edu> To: r-help at r-project.org Cc: Sent: Monday, May 13, 2013 9:18 PM Subject: [R] Boundaries of consecutive integers Hi folks, I'm trying to accomplish something that seems like it should be straightforward, but I've gotten tied in knots trying to figure it out.? A toy example of my issue is below.? I've played with diff and can't seem to figure out a systematic solution that will give me the two column output independent of the number of breakpoints in the vector... test<-c(1:5, 22:29,33:40) example.output<-matrix(c(1,5,22,29,33,40),nrow=3,ncol=2,byrow=TRUE) Any ideas? Thanks! Lizzy -- "The obvious goal of any bacterium is to become bacteria." Lizzy Wilbanks Graduate Student, Eisen and Facciotti Labs UC Davis, Microbiology Graduate Group ______________________________________________ R-help at 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.
How's this: big.gap = diff(test) > 1 cbind(test[c(TRUE, big.gap)], test[c(big.gap, TRUE)]) -----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of Lizzy Wilbanks Sent: Tuesday, 14 May 2013 1:18p To: r-help at r-project.org Subject: [R] Boundaries of consecutive integers Hi folks, I'm trying to accomplish something that seems like it should be straightforward, but I've gotten tied in knots trying to figure it out. A toy example of my issue is below. I've played with diff and can't seem to figure out a systematic solution that will give me the two column output independent of the number of breakpoints in the vector... test<-c(1:5, 22:29,33:40) example.output<-matrix(c(1,5,22,29,33,40),nrow=3,ncol=2,byrow=TRUE) Any ideas? Thanks! Lizzy -- "The obvious goal of any bacterium is to become bacteria." Lizzy Wilbanks Graduate Student, Eisen and Facciotti Labs UC Davis, Microbiology Graduate Group ______________________________________________ R-help at 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.