Re: [R] Speeding up code?

2015-07-16 Thread Ignacio Martinez
Thank Jim! This makes a huge difference. Can you explain why are data frame slower than a matrix? Any other suggestions on how to improve the code would be greatly appreciated. Thanks again! Ignacio On Thu, Jul 16, 2015 at 1:42 PM jim holtman wrote: > Actually looking at the result, you don't

Re: [R] Speeding up code?

2015-07-16 Thread jim holtman
Actually looking at the result, you don't need the transpose; that was an artifact of how you were doing it before. xm <- do.call(rbind, str_split(string = AllpairsTmp, pattern = "-")) # convert to dataframe and do transpose on matrix and not dataframe separoPairs <- as.data.frame((xm), strings

Re: [R] Speeding up code?

2015-07-16 Thread jim holtman
Here is one improvement. Avoid dataframes in some of these cases. This create a character matrix and then converts to a dataframe after doing the transpose of the matrix. This just takes less than 10 seconds on my system: > library(stringr) > # create character matrix; avoid dataframes in th

Re: [R] Speeding up code?

2015-07-16 Thread Ignacio Martinez
Hi Collin, The objective of the gen.names function is to generate N *unique *random names, where N is a *large *number. In my computer `gen.names(n = 5)` takes under a second, so is probably not the root problem in my code. That said, I would love to improve it. I'm not exactly sure how you pr

Re: [R] Speeding up code?

2015-07-15 Thread Collin Lynch
Hi Ignacio, If I am reading your code correctly then the top while loop is essentially seeking to select a random set of names from the original set, then using unique to reduce it down, you then iterate until you have built your quota. Ultimately this results in a very inefficient attempt at samp

[R] Speeding up code?

2015-07-15 Thread Ignacio Martinez
Hi R-Help! I'm hoping that some of you may give me some tips that could make my code more efficient. More precisely, I would like to make the answer to my stakoverflow question more efficient

Re: [R] Speeding up code

2013-11-25 Thread MacQueen, Don
ditto to everything Jeff Newmiller said, but I'll take it a little further. I'm guessing that with df <- data.frame(31790,31790) you thought you were creating something with 31790 rows and 31790 columns. You weren't. You were creating a data frame with one row and two columns: > data.frame(317

Re: [R] Speeding up code

2013-11-23 Thread Jeff Newmiller
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 ar

[R] Speeding up code

2013-11-23 Thread Amie Hunter
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: