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
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.
### 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
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
4 matches
Mail list logo