Re: [R] Generate Variable Length Strings from Various Sources

2014-01-18 Thread Jeff Newmiller
People who subscribe to an avoid-for-loops "mantra" are often missing the point. Converting for loops to indexing can often yield speed improvements. Converting for loops to apply functions does not improve speed. (If you think it does, you are probably handling memory allocation differently.) W

Re: [R] Generate Variable Length Strings from Various Sources

2014-01-18 Thread Burhan ul haq
Hi Rainer, Thanks for the tip. Your suggestion works perfectly, however as per the R Mantra of avoiding for loops, I propose the following this alternate: # number of strings to be created n <- 50 # random length of each string v.length = sample( c( 2:4), n, rep = TRUE ) # letter sources src.

Re: [R] Generate Variable Length Strings from Various Sources

2014-01-15 Thread Rainer Schuermann
### How I would do it: # container for the result res <- NULL # number of strings to be created n <- 50 # random length of each string v.length = sample( c( 2:4), n, rep = TRUE ) # letter sources src.1 = LETTERS[ 1:10 ] src.2 = LETTERS[ 11:20 ] src.3 = "z" src.4 = c( "1", "2" ) # turn into a l

[R] Generate Variable Length Strings from Various Sources

2014-01-15 Thread Burhan ul haq
Hi, I am trying to generate variable length strings from variable sources as follows: # >8 8<- # Function to generate a string, given: # its length(passed as len) # and the source(passed as src) my.f = functio