Re: [R] Need very fast application of 'diff' - ideas?

2012-01-29 Thread Kevin Ummel
imself and he > gives an implementation that gives you 25x improvement here as well as > tips for getting even more out of it: > > http://tolstoy.newcastle.edu.au/R/e17/help/12/01/2471.html > > Michael > > On Sat, Jan 28, 2012 at 12:28 PM, Kevin Ummel wrote: >> Thanks. I&

Re: [R] Need very fast application of 'diff' - ideas?

2012-01-28 Thread Kevin Ummel
on my old laptop. > > HTH > > Peter > > > On Fri, Jan 27, 2012 at 4:15 PM, Kevin Ummel wrote: >> Hi everyone, >> >> Speed is the key here. >> >> I need to find the difference between a vector and its one-period lag (i.e. >> the differen

[R] Need very fast application of 'diff' - ideas?

2012-01-27 Thread Kevin Ummel
Hi everyone, Speed is the key here. I need to find the difference between a vector and its one-period lag (i.e. the difference between each value and the subsequent one in the vector). Let's say the vector contains 10 million random integers between 0 and 1,000. The solution vector will have 9

[R] Lagged values problem requiring short solution time

2011-12-11 Thread Kevin Ummel
temp = sign(chg)*chg - delta temp1=temp temp1[chg>=(-delta)] = 0 temp1 = c(temp1[length(temp1)],temp1[-length(temp1)]) temp2 = temp temp2[chg<=delta] = 0 y = y+temp1+temp2 chg = diff(c(y,y[1]))

[R] Find number of elements less than some number: Elegant/fast solution needed

2011-04-14 Thread Kevin Ummel
Take vector x and a subset y: x=1:10 y=c(4,5,7,9) For each value in 'x', I want to know how many elements in 'y' are less than 'x'. An example would be: sapply(x,FUN=function(i) {length(which(yhttps://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.o

Re: [R] Match numeric vector against rows in a matrix?

2011-01-11 Thread Kevin Ummel
x27;binary expansion' approach was the fastest by about a factor of 8. Cheers, Kevin On Jan 11, 2011, at 9:20 AM, Petr Savicky wrote: > Dear Kevin Ummel: > > There were several suggestions on R-help concering your question below. > None of them suggests a base function. I would also ex

[R] Match numeric vector against rows in a matrix?

2011-01-05 Thread Kevin Ummel
Two posts in one day is not a good day...and this question seems like it should have an obvious answer: I have a matrix where rows are unique combinations of 1's and 0's: > combs=as.matrix(expand.grid(c(0,1),c(0,1))) > combs Var1 Var2 [1,]00 [2,]10 [3,]01 [4,]1

Re: [R] How to 'explode' a matrix

2011-01-05 Thread Kevin Ummel
eq(nrow(m)), each = 2), rep(seq(ncol(m)), each = 2)] > > On Wed, Jan 5, 2011 at 10:03 AM, Kevin Ummel wrote: > Hi everyone, > > I'm looking for a way to 'explode' a matrix like this: > > > matrix(1:4,2,2) > [,1] [,2] > [1,]1

[R] How to 'explode' a matrix

2011-01-05 Thread Kevin Ummel
Hi everyone, I'm looking for a way to 'explode' a matrix like this: > matrix(1:4,2,2) [,1] [,2] [1,]13 [2,]24 into a matrix like this: > matrix(c(1,1,2,2,1,1,2,2,3,3,4,4,3,3,4,4),4,4) [,1] [,2] [,3] [,4] [1,]1133 [2,]1133 [3,]22

Re: [R] Pass character vector to function argument

2010-11-16 Thread Kevin Ummel
"missing" At this point, this may be more of a 'raster' issue for the R-Sig-Geo list... On Nov 16, 2010, at 7:09 PM, Kevin Ummel wrote: > Thanks, David. That does, indeed, work. It didn't occur to me that a list > would do the job as an argument. > > Than

Re: [R] Pass character vector to function argument

2010-11-16 Thread Kevin Ummel
Thanks, David. That does, indeed, work. It didn't occur to me that a list would do the job as an argument. Thanks for the fix! kevin On Nov 16, 2010, at 6:58 PM, David Winsemius wrote: > > On Nov 16, 2010, at 1:04 PM, Kevin Ummel wrote: > >> Sorry, I shouldn't have

Re: [R] Pass character vector to function argument

2010-11-16 Thread Kevin Ummel
generate the equivalent of... stack(r1,r2) ...using a variation of obs as an argument to 'stack' (potentially very long). Cheers, Kevin On Nov 16, 2010, at 5:07 PM, David Winsemius wrote: > > On Nov 16, 2010, at 10:34 AM, Kevin Ummel wrote: > >> A bit embarrassed to p

[R] Pass character vector to function argument

2010-11-16 Thread Kevin Ummel
A bit embarrassed to post this seemingly trivial question, but I can't find anything in the archive that's quite relevant: a1=1 a2=2 obs=objects(pattern=glob2rx("a?")) I want to utilize 'obs' as a function argument to produce something like: sum(a1,a2) Obviously, sum(obs) doesn't work, but I'

[R] Plot point text labels over polygon w/o overlap?

2010-02-05 Thread Kevin Ummel
on top of nearby country/state borders, etc. Many thanks, Kevin Ummel Central European University Department of Environmental Science and Policy __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting

[R] Create sequence given start and end vector

2009-12-12 Thread Kevin Ummel
aster) way. Many thanks in advance, Kevin Ummel Central European University Department of Environmental Science and Policy __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-p