Re: [R] options other than regex

2018-05-25 Thread Alex Zarebski
The stringr package might beof interest to you (and I think magrittr makes it more readable). > library(stringr) > library(magrittr) > '10110111' %>% str_split('') %>% unlist %>% str_flatten('.') [1] "1.0.1.1.0.1.1.1" Note that the unlist is there because we are only applying this to a single str

Re: [R] options other than regex

2018-05-25 Thread Greg Minshall
Evan, are you really looking at numbers, or just at character strings (that, in your case, happen to be numbers)? if just characters, this rather odd combination of strsplit() and Reduce() might do the trick: > x <- '10110111' > print(x) [1] "10110111" > y <- Reduce(function (x,y) { paste(x,

Re: [R] how to make the code more efficient using lapply

2018-05-25 Thread Bert Gunter
... and, of course, the original premise is false. apply() type statements **are** loops at the interpreter level and are typically not appreciably faster -- sometimes even a bit slower -- than explicit for() loops. Their chief advantage is adherence to a functional programming paradigm that for ma

Re: [R] how to make the code more efficient using lapply

2018-05-25 Thread MacQueen, Don via R-help
Eric's approach seems reasonable to me, and I agree that it's probably not the use of a "for" loop that makes the original version slow. As Eric mentioned, there are lots of unnecessary things happening in the loop. For example, list.files() was called twice inside the loop, which is unnecessar

Re: [R] options other than regex

2018-05-25 Thread Evan Cooch
Numbers -- thanks. Another clever trick. On 5/25/2018 11:54 AM, Greg Minshall wrote: > Evan, > > are you really looking at numbers, or just at character strings (that, > in your case, happen to be numbers)? if just characters, this rather > odd combination of strsplit() and Reduce() might do the

Re: [R] options other than regex

2018-05-25 Thread Evan Cooch
Thanks, another good idea. On 5/25/2018 11:30 AM, PIKAL Petr wrote: > Hi > I am not sure if it is more readable > >> paste(paste(unlist(strsplit(x,"")),".", sep=""), collapse="") > [1] "1.0.1.1.0.1.1.1." > > If you did not want last dot, it is a bit shorter. >> paste(unlist(strsplit(x,"")),collaps

Re: [R] options other than regex

2018-05-25 Thread PIKAL Petr
Hi I am not sure if it is more readable > paste(paste(unlist(strsplit(x,"")),".", sep=""), collapse="") [1] "1.0.1.1.0.1.1.1." If you did not want last dot, it is a bit shorter. > paste(unlist(strsplit(x,"")),collapse=".") [1] "1.0.1.1.0.1.1.1" > Cheers Petr Tento e-mail a jakékoliv k němu připo

[R] options other than regex

2018-05-25 Thread Evan Cooch
Hi -- I'm looking for alternatives to regex for a fairly simply 'reformatting' problem. Alternatives only because a lot of folks have trouble parsing/interpreting regex expressions, and I'm looking for suggestions for something more 'transparent'. Here is an example of what I'm trying to do.

[R] TukeyHSD for multiple response

2018-05-25 Thread Sergio Ferreira Cardoso
Dear all, I'm testing the effect of species and sex in my sample by using the principal component scores of a PCA analysis. I have 30 PCs and I tried to see if there is any significant difference from males to females, given that there is a significant effect of phylogeny (factor with several

[R] Query on the Arimax modeling results

2018-05-25 Thread Sanchi Bhatia
Hi R team, We’ve run Arimax models in R. We had a lot of queries around the interpretation of the outputs. *Dependent variable =* Volume (Growth %) *Independent Variables =* 3 Macroeconomic variables (Growth %) Following is the line of code Arimax.Model <- auto.arima(y = input.data[,"V

Re: [R] how to make the code more efficient using lapply

2018-05-25 Thread Eric Berger
Hi Stephen, I am not sure that the "for loop" is the source of slowness. You seem to be doing a lot of unnecessary work each time through the loop. e.g. no need to check if it's the last file, just move that section outside of the loop. It will be executed when the loop finishes. As it is you are c