R is a free, open source programming language and software environment for statistical computing and graphics.
0
votes
1answer
73 views
Learning R – repeated measures simulator optimisation
I am learning to program in R and to do that and create something useful in the process, I have decided to rewrite this Java applet for repeated measures simulation and to implement some new ...
2
votes
1answer
61 views
Vectorize or otherwise speed up a double for loop
I have this function containing some loops and a double for loop. What it does is set up a matrix first to store results in (the task at hand is comparing genomes) and then with sliding window, ...
0
votes
1answer
41 views
Which components of this r loop are inefficient?
I realize that there is a surfeit of posts on SE/SO about optimizing one's R for() loops. I'm afraid, though, that I don't understand all of the guidance in the answers there, or how to apply their ...
3
votes
1answer
57 views
More elegant filter script in R
I'm very new both to programming and to R so please bear with me :-)
I've written the following bit of code, which works perfectly well and runs through a data file with 17446 rows in about 35 ...
1
vote
2answers
78 views
Is this correct R? remove first duplicate dataframe
I have a dataframe with several columns. One of them is an user id column, in this column, I have several ids that can be repeated several times. What I want to do is remove the first id, for ...
2
votes
0answers
90 views
Speed up a monte carlo simulation with nested loop
I would like to know if there is a more efficiency way to speed up below code. It uses a procedure where subsampling is required in the nested loop (which a previous answer ...
3
votes
1answer
60 views
Compute intersections of all combinations of vectors in a list of vectors in R
My goal is to compute the intersections of several vectors (sets of identifiers, gene-names to be specific). I start with a list of vectors and run the function below, which loops through 1:n where n ...
2
votes
1answer
95 views
Increase efficiency for an R simulator of the Monty Hall Puzzle
The Monty Hall Problem is a simple puzzle involving probability that even stumps professionals in careers dealing with some heavy-duty math. Here's the basic problem:
Suppose you're on a game show, ...
3
votes
2answers
42 views
Speeding up for-loop over a list
I have two lists with ca. 4000 elements where each each element have two columns. These are being fed into a function. Besides the function they are being fed into, is it possible to speed it up ...
2
votes
1answer
111 views
R code is slow on filling a matrix
I am running an R code, which is implementing a Markov Chain Monte Carlo algorithm for updating a density distribution
There is a specific section of my code which tries to fill a very large matrix ...
1
vote
1answer
90 views
Speed up a sampling function
I have the following dataset
kkk<-data.frame(days=1:100,positive=rbinom(100,1,0.05))
Over the monitoring period of 100 days, if an event occurs then for that day kkk$positive==1 else ...
2
votes
1answer
69 views
How do I speed up the following R code?
I have files containing data set which contain 11,000 rows. I have to run a loop through each row, this is taking me 25minutes for each file.
I am using following code:
z <- ...
1
vote
1answer
103 views
increase speed for 'for loop'
I have files containing data set which contain 11,000 rows. I have to run a loop through each row, this is taking me 25minutes for each file.
I am using following code:
z <- read.zoo("Title.txt", ...
3
votes
2answers
137 views
How would you improve this code in R?
I'm trying to implement a function that given a data frame returns the same data frame with four columns added. These new four columns are: for each row, I get the maximun element and its index and ...
1
vote
1answer
211 views
Improving R script performance
i am having some performance problems with a little R script of mine that I use to visualize simulation results of a project of ( mine ). It now takes longer on my machine to run the R script than the ...
3
votes
2answers
90 views
Improving R code - remove redundant if's and assignments
I've written this brief function, it's to do with calculating which calendar year a student would be in Year 1 based on their DOB. In 1998 there was a change in the DOB cut points for starting Year 1, ...
0
votes
1answer
295 views
Optimize C++ Code
I have the following C++ function which I'd like to speed up, if possible. This program will have many different users, so parallelization is not really an option.
The C++ function is wrapped by C ...
5
votes
2answers
350 views
My R code runs very slowly, how to improve?
I wrote the following code in R, basically I want to convert all categorical column in a R dataframe to several binary columns:
for example, a categorical column like
Company
-------
IBM
Microsoft
...
1
vote
0answers
111 views
Can anyone speed up this R function?
This script fetches a list of "end-positions" from a MYSQL database. The positions are array positions that are the same in both MYSQL and R.
Next, the script takes the previous 34 elements for each ...
3
votes
1answer
296 views
Generate graph in Matlab
I use this Matlab code:
load ~/emailAnalysis/results.txt
results=results(size(results,1)-400:size(results,1),:)
temp = results(:,3)-1238370000;
h=plot(temp,smooth(results(:,1)),':b')
...
1
vote
1answer
48 views
Is there a more efficient way to simulate in R, by exposition factor, gender and disease profile?
I started working with R recently and need to do a simulation for 100 000 people that
divides them in exposition factor for a disease, gender and presence or absence of
disease.
My background info is ...
3
votes
1answer
112 views
What is the best approach to use in R and why?
I'm starting working with R, and found some tutorials and exercises online.
I want to divide one variable in two, bigger and equal 79 and smaller 79.
Perhaps because I'm used to python, my first ...
4
votes
3answers
159 views
Is there a better way to get the index of a minimum?
Consider the following reproducible example:
# note that lh is a standard ts dataset that ships with R
lh
# fit an R model
ar.mle<-ar(lh,method="mle")
# now get the min AIC, this is the ...
3
votes
1answer
119 views
How can I get this R code to pass the “1 minute” test for this Project Euler question?
I am attempting to learn R programming by going through the questions in Project Euler.
The code below is my solution to problem 5 which asks for the smallest number that is evenly divisible by 1 ...
1
vote
0answers
158 views
Making this code more R-like
I've written the code below to do some work on machine learning in R. I'm not overly happy with some bits of it, and I suspect I could improve it quite a bit. Bits I'm specifically interested in ...
3
votes
2answers
541 views
How to simplify nested conditional for loop in R?
I have this for loop for creating a list of variables:
vars <- c( 'beta.o', 'sd.y')
for (x in c('ghs', 'site', 'trt')) {
if(model.parms[[x]] == 1) {
data <- data[, which(names(data) != ...
