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
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,
... 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
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
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
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
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
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.
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
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
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
11 matches
Mail list logo