break string at specified possitions
Here are two ways that do not use any packages: s <- paste(letters, collapse = "") # test input substring(s, first, last) ## [1] "abcde" "fghij" "klmnopqrs" read.fwf(textConnection(s), last - first + 1) ## V1 V2 V3 ## 1 abcde fghij klmnopqrs
On Wed, May 11, 2016 at 4:12 PM, Jan Kacaba <jan.kacaba at gmail.com> wrote:
Dear R-help I would like to split long string at specified precomputed positions. 'substring' needs beginings and ends. Is there a native function which accepts positions so I don't have to count second argument? For example I have vector of possitions pos<-c(5,10,19). Substring needs input first=c(1,6,11) and last=c(5,10,19). There is no problem to write my own function. Just asking. Derek
______________________________________________ R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see 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.
Statistics & Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com