Re: [R] break string at specified possitions

2016-05-17 Thread Gabor Grothendieck
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) ## V1V2V3 ## 1 abcde fghij klmnopqrs On Wed, May 11, 2016 at

Re: [R] break string at specified possitions

2016-05-17 Thread Jan Kacaba
Excellent Hervé, thank you. 2016-05-13 11:48 GMT+02:00 Hervé Pagès : > Hi, > > Here is the Biostrings solution in case you need to chop a long > string into hundreds or thousands of fragments (a situation where > base::substring() is very inefficient): > >

Re: [R] break string at specified possitions

2016-05-13 Thread Hervé Pagès
Hi, Here is the Biostrings solution in case you need to chop a long string into hundreds or thousands of fragments (a situation where base::substring() is very inefficient): library(Biostrings) ## Call as.character() on the result if you want it back as ## a character vector.

Re: [R] break string at specified possitions

2016-05-12 Thread Martin Maechler
> On 5/11/2016 2:23 PM, Jan Kacaba wrote: > > Here is my attempt at function which computes margins from positions. > > > > require("stringr") > > require("dplyr") > > > > ends<-seq(10,100,8) # end margins > > test_string<-"Lorem ipsum dolor sit amet, consectetuer adipiscing > > elit. Aliquam in

Re: [R] break string at specified possitions

2016-05-12 Thread Jan Kacaba
Nice solution Jim, thank you. 2016-05-12 2:45 GMT+02:00 Jim Lemon : > Hi again, > Sorry, that should be: > > chop_string<-function(x,ends) { > starts<-c(1,ends[-length(ends)]+1) > return(substring(x,starts,ends)) > } > > Jim > > On Thu, May 12, 2016 at 10:05 AM, Jim

Re: [R] break string at specified possitions

2016-05-11 Thread Daniel Nordlund
On 5/11/2016 2:23 PM, Jan Kacaba wrote: Here is my attempt at function which computes margins from positions. require("stringr") require("dplyr") ends<-seq(10,100,8) # end margins test_string<-"Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aliquam in lorem sit amet leo accumsan

Re: [R] break string at specified possitions

2016-05-11 Thread Jim Lemon
Hi again, Sorry, that should be: chop_string<-function(x,ends) { starts<-c(1,ends[-length(ends)]+1) return(substring(x,starts,ends)) } Jim On Thu, May 12, 2016 at 10:05 AM, Jim Lemon wrote: > Hi Jan, > This might be helpful: > > chop_string<-function(x,ends) { >

Re: [R] break string at specified possitions

2016-05-11 Thread Jim Lemon
Hi Jan, This might be helpful: chop_string<-function(x,ends) { starts<-c(1,ends[-length(ends)]-1) return(substring(x,starts,ends)) } Jim On Thu, May 12, 2016 at 7:23 AM, Jan Kacaba wrote: > Here is my attempt at function which computes margins from positions. > >

Re: [R] break string at specified possitions

2016-05-11 Thread Jan Kacaba
Here is my attempt at function which computes margins from positions. require("stringr") require("dplyr") ends<-seq(10,100,8) # end margins test_string<-"Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aliquam in lorem sit amet leo accumsan lacinia." sekoj=function(ends){

Re: [R] break string at specified possitions

2016-05-11 Thread Bert Gunter
Dunno -- but you might have a look at Hadley Wickham's 'stringr' package: https://cran.r-project.org/web/packages/stringr/stringr.pdf Cheers, Bert Bert Gunter "The trouble with having an open mind is that people keep coming along and sticking things into it." -- Opus (aka Berkeley Breathed in

[R] break string at specified possitions

2016-05-11 Thread Jan Kacaba
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