[R] speed up merge
kees duineveld
kees.duineveld at gmail.com
Fri Mar 2 11:36:56 CET 2012
Hi Ben,
It seems you merge a matrix and a vector. As far as I understand the
first thing merge does is convert these to data.frame. Is it possible
to make the preceding steps give data frames?
Regards,
Kees
On Fri, Mar 2, 2012 at 11:24 AM, Ben quant <ccquant at gmail.com> wrote:
>
> Hello,
>
> I have a nasty loop that I have to do 11877 times. The only thing that
> slows it down really is this merge:
>
> xx1 = merge(dt,ua_rd,by.x=1,by.y= 'rt_date',all.x=T)
>
> Any ideas on how to speed it up? The output can't change materially (it
> works), but I'd like it to go faster. I'm looking at getting around the
> loop (not shown), but I'm trying to speed up the merge first. I'll post
> regarding the loop if nothing comes of this post.
>
> Here is some information on what type of stuff is going into the merge:
>
> > class(ua_rd)
> [1] "matrix"
> > dim(ua_rd)
> [1] 20 2
> > head(ua_rd)
> AName rt_date
> 2007-03-31 "14066.580078125" "2007-04-26"
> 2007-06-30 "14717" "2007-07-19"
> 2007-09-30 "15528" "2007-10-25"
> 2007-12-31 "17609" "2008-01-24"
> 2008-03-31 "17168" "2008-04-24"
> 2008-06-30 "17681" "2008-07-17"
> > class(dt)
> [1] "character"
> > length(dt)
> [1] 1799
> > dt[1:10]
> [1] "2007-03-31" "2007-04-01" "2007-04-02" "2007-04-03" "2007-04-04"
> "2007-04-05" "2007-04-06" "2007-04-07"
> [9] "2007-04-08" "2007-04-09"
>
> thanks,
>
> Ben
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help
mailing list