[R] Speeding up code
Jeff Newmiller
jdnewmil at dcn.davis.CA.us
Sun Nov 24 08:43:58 CET 2013
What is cldm?
We (and therefore you, to verify that we can) should be able to copy the example from the email and paste it into a newly-started instance of R. Not having some example data similar to yours to work with puts us at a major disadvantage. It would also be helpful to know what you are trying to accomplish (description).
You might want to use the str function to understand what each object you are creating really is. I don't know what you want the "df" object to be, but a data frame of two values in default-named columns is unusual. You may be confusing matrices with data frames?
(Note that there is a function called df in the core libraries, so you might want to avoid using that name to avoid confusion.)
---------------------------------------------------------------------------
Jeff Newmiller The ..... ..... Go Live...
DCN:<jdnewmil at dcn.davis.ca.us> Basics: ##.#. ##.#. Live Go...
Live: OO#.. Dead: OO#.. Playing
Research Engineer (Solar/Batteries O.O#. #.O#. with
/Software/Embedded Controllers) .OO#. .OO#. rocks...1k
---------------------------------------------------------------------------
Sent from my phone. Please excuse my brevity.
Amie Hunter <amie_hunter at hotmail.com> wrote:
>Hello R experts,
>
>I'm new to R and I'm wanting to know what is the best way to speed up
>my code. I've read that you can vectorize the code but I'm unsure on
>how to implement this into my code.
>
>
>df <- data.frame(31790,31790)
>
>for (i in 1:31790)
>{
> for (j in i:31790)
> {
> ken<-cor(cldm[i,3:17],cldm[j,3:17], method="kendall",
>use="pairwise")
> dis2<-deg.dist(cldm[i,2],cldm[i,1],cldm[j,2],cldm[j,1])
>
> df[i,j]<-ifelse(dis2<=500,ken,NA)
> }
> }
>df
>
>Thanks!
>______________________________________________
>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