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

2012-01-29 Thread Kevin Ummel
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 kevinum...@gmail.com wrote: Thanks. I've played around with pure R

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

2012-01-28 Thread Kevin Ummel
, at 9:14 AM, Peter Langfelder wrote: ehm... this doesn't take very many ideas. x = runif(n=10e6, min=0, max=1000) x = round(x) system.time( { y = x[-1] - x[-length(x)] }) I get about 0.5 seconds on my old laptop. HTH Peter On Fri, Jan 27, 2012 at 4:15 PM, Kevin Ummel kevinum

[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

[R] Lagged values problem requiring short solution time

2011-12-11 Thread Kevin Ummel
(temp1)]) temp2 = temp temp2[chg=delta] = 0 y = y+temp1+temp2 chg = diff(c(y,y[1])) } #Solution vector: y Thank you, Kevin Kevin Ummel CARMA Project Manager Center for Global Development [[alternative HTML

[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(yi))}) [1] 0 0 0 0 1 2 2 3 3 4 But this solution is far too slow when x and y have lengths in the

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

2011-01-11 Thread Kevin Ummel
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 expect that there is a base

[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] How to 'explode' a matrix

2011-01-05 Thread Kevin Ummel
(seq(ncol(m)), each = 2)] On Wed, Jan 5, 2011 at 10:03 AM, Kevin Ummel kevinum...@gmail.com wrote: 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

[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

[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

Re: [R] Pass character vector to function argument

2010-11-16 Thread Kevin Ummel
' (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 post this seemingly trivial question, but I can't find anything in the archive that's quite relevant: a1=1 a2=2 obs=objects

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 used 'sum' as an example; I

Re: [R] Pass character vector to function argument

2010-11-16 Thread Kevin Ummel
' 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. Thanks for the fix! kevin On Nov 16, 2010, at 6:58 PM, David Winsemius wrote: On Nov 16, 2010

[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
. 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-project.org