R is a free, open source programming language and software environment for statistical computing and graphics.

learn more… | top users | synonyms

1
vote
1answer
65 views

Computing the distance and weight matrix of a graph

I would like to create an igraph object. First, I set up the size of igraph object — n, m, then create a random matrix. As a result matrix ...
1
vote
0answers
16 views

Flask json rpc2.0 extension

I created a simple extension to handle JSON RPC 2.0 requests on flask I would like some feedback regarding usage here is an usage example: ...
3
votes
0answers
35 views

Convert A for loop in R to apply function

My goal is to iterate over a datamatrix, calculate mean, standard error of the mean, and then have a bar plot representing the 2 groups of my data matrix in R. My code below works as a for loop. ...
4
votes
1answer
39 views

UK postcode validation and format correction tool

I've been working on a regex-based UK postcode validation and format correction tool - with the aim of creating a list of postcodes that can be readily geocoded. The variety of postcode formats is ...
4
votes
2answers
75 views

Picking the top 5 results for each individual

For loops are the devil. I can't see a way to speed this up with apply or other more speedy functions though... ...
4
votes
1answer
46 views

Import data from XML files into data.frame

I have a number of XML files containing data I would like to analyse. Each XML contains data in a format similar to this: ...
5
votes
1answer
56 views

Largest common multiple equal or lower than max

I made this small and easy function that returns the largest common multiple of the elements of ms that is equal to or lower than ...
2
votes
2answers
131 views

Using doParallel to cycle through *.rds files

Overview I have 165,000 *.rds files that are around 200,000 obs x 13 variables each. These files are unique to grid files (2.5 square mile data) so I need to keep them in their unique grid numbers. ...
4
votes
1answer
52 views

Order columns in R by substring

I want to order columns of a dataframe using a substring of the column name only. Suppose my columns are named ...
3
votes
2answers
72 views

Merge together multiple dataframes

I'm working on a script where I want to create one dataframe from a series of files with annual baseball data in them. I'm relatively new to R and I feel like the way I wrote ...
5
votes
1answer
92 views

Processing weather station data using idw - Follow Up

New Approach My previous question may have had a little too much going on and I realized I could simplify the problem by constructing the data a bit differently thanks to @Gentian Kasa . Previously, ...
0
votes
0answers
58 views

Optimizing a function in R over 10000000 values - follow-up

This is a follow up: Optimization over 7 constants, running a function 10,000,000 times My data can be downloaded here. The only kink left is the betaema ...
3
votes
1answer
274 views

Optimization over 7 constants, running a function 10,000,000 times

I am not quite sure how to attach my data, but it is 5737 observations of 3 variables. Variables V and P are strictly < 0, ...
4
votes
1answer
340 views

Processing data for five weather stations

Problem The main idea is to build some fine scale weather data using inverse distance weighting (idw) from the 5 closest stations of the observed station. If the ...
3
votes
2answers
47 views

Convert hex encoded string to byte array

The following should read a hex string such as "ece998a2fb" into vector 236 233 152 162 251. I was unable to find any built in ...
2
votes
0answers
59 views

Clean reading of HTML table with R

I have some data under an HTML format and would like to import it in R. However, it seems that type inference is much less sophisticated than what exists with functions such as read.table. I am using ...
1
vote
1answer
45 views

Adding column to table in a for loop

I'm running the following code on quite large data frames. I've rewritten it for the iris dataset to make it reproducable. I'm quite unexperienced with the apply ...
6
votes
1answer
72 views

Plotting level and temperature data from many Excel sheets

I've been working on a code that reads in all the sheets of an Excel workbook, where the first two columns in each sheet are "Date" and "Time", and the next two columns are either "Level" and ...
1
vote
1answer
46 views

R merge even/odd rows

I need to merge eve/odd rows on a data set. Example: ...
1
vote
0answers
35 views

Simultaneous confidence interval

I recently read an article in which the authors present Algorithm 1 to compute a simultaneous confidence interval. I was interested in implementing Algorithm 1 in R here. The algorithm is freely ...
2
votes
0answers
36 views

Invert a function via a lookup

The goal of this function is to an invert an income tax function. That is, given the tax paid and the financial year, the function should return the taxable income for that year. I would prefer to ...
1
vote
0answers
19 views

Implementation of conjoint analysis

Probably, this use of for-loops and lists is horrible. Thus, I describe my procedure below and am thankful for any constructive feedback! Conjoint analysis is used in marketing to extract preferences ...
2
votes
1answer
57 views

Is there a way to speed-up the following code?

Is there a way to speed-up the following R code? ...
5
votes
1answer
69 views

Mixed scripting language API to determine file upload location and scrape city government website to find corresponding government official

I wrote this script as an NYC-specific-API for file upload for a mobile app. Users upload a video file and also their geographic coordinates. I then use an external API to get the corresponding ...
1
vote
0answers
35 views

Penalized logistic ridge regression

This code takes a really long time. Can anyone help to make it faster? This code is for the penalized logistic regression that we should to chose \$\lambda\$ in regularization to control the trade ...
3
votes
1answer
44 views

Converting polar coordinates to Cartesian coordinates

I have a functional script that converts polar coordinates to Cartesian coordinates and then matches a value in a separate array to the coordinates. It works well, but I find that it takes a long time ...
1
vote
1answer
38 views

For loop step including last value

I've got the following code. I want to loop through my dataset (which is a matrix) in steps of let's say 50.000 and perform biglm on it. ...
0
votes
0answers
37 views

Compute Random Forest with a leave one ID out cross validation in R

I have a dataframe df ...
4
votes
2answers
311 views

Make 10 from the numbers 1,1,5 and 8 using the 4 operations, by brute force

I tried to calculate the following problem by brute force using R (under the assumption that a single pair of parenthesis would suffice). Make 10 from the numbers 1, 1, 5, 8. You can use the ...
1
vote
0answers
75 views

Optimizing R + ROracle performance

For my internship I have to perform certain analysis to determine residuals and outliers. The table I'm currently using has over 12 million records with 130+ columns. My first tests take approx. 5398 ...
2
votes
1answer
48 views

Compute histrogram bins for a large data.frame fast

I know about apply, but I'm not sure how to write it so that it works for embedded for loops with if statements and so forth. It ...
3
votes
0answers
113 views

Web scraping from the Google Play store

I am using this R function to web scrape data from the google play store. Is there a way to increase its efficiency using R? This code takes about 4 seconds for 14 urls with my machine/internet ...
3
votes
1answer
39 views

Updating an inventory with R using apply functions

I have created an inventory that works via QR codes. Briefly: the QR code codes for an email with the book/student checking it out. The email is downloaded into R using the gmailR package (code not ...
4
votes
1answer
130 views

Generating frequency tables based on CSV dataset, in R

As a follow-up to this question concerning Python I present you with the exact same thing - for R. Initially I started with R. However, it takes 44 minutes to run when unleashed on all my data. I ...
2
votes
0answers
57 views

Optimization with a lower value constraint for positive solutions

Let \$D\$ be a \$N\times N\$ positive definite matrix. I am minimizing a quadratic funtion $$ f(w)=w^T D\ w$$ with respect to the weight vector \$ w=(w_1, w_2, ..., w_N)\$, subject to the ...
1
vote
2answers
101 views

Monte Carlo Pi with R + Fortran + MPI

I created a R package to calculate Pi with a Monte Carlo simulation. My goal is to optimize the parallel function SnowPi as much as possible. This is the ...
3
votes
1answer
120 views

Plotting 2D histograms from files of matrices in R

I wrote a script to turn a file like this one into a colored 2D histogram: ...
1
vote
1answer
49 views

ANOVA Using Continuous CDFs

I have a procedure for conducting ANOVA, the details of which can be viewed in this white paper. I would like to be able to make the routine scalable to handle any number of groups. Below is the R ...
2
votes
1answer
118 views

Fill missing values based on group

I am trying to fill values based on group, in my case id. I would like to fill the missing values according to the available ...
1
vote
1answer
40 views

3D plot from lm model with a nonlinear parameter

I am trying to plot a 3Dplot of a linear regression with two variables. My linear model: ls = lm(mpg ~ disp + qsec, data = mtcars) The minimum and maximum ...
4
votes
1answer
49 views

Long format data - fill episode based on conditional previous episode

The data are organised as long format data. 4 individuals are observed during 4 or 5 days (BCSID is the name of the unique key). Basically, the data describe ...
1
vote
1answer
36 views

Programmatic text substitution across rows and columns in R

I'm replaced character strings with numeric codes in R. I find myself doing a lot of copying and pasting, so there's probably a better solution with apply, ...
2
votes
2answers
65 views

Calculate number of co-occurrences for two vectors

I would like to understand how to get rid of all the loops I am using in this code. I have a dataframe of 20 rows. I am simply counting the number of occurrences that the variables ...
4
votes
1answer
403 views

Implementation of KNN in R

I have implemented the K-Nearest Neighbor algorithm with Euclidean distance in R. It works fine but takes tremendously huge time than the library function (get.knn). Please point out the possibility ...
3
votes
1answer
302 views

Identify changes between two data.frames, explain deltas for x columns

I wrote the following snippet to deal with a situation in which I have two datasets (usually the current version versus a previous one) and I need to identify what changes have occured: usually ...
4
votes
1answer
167 views

Plotting a vector field in R + ggplot

I've written a small program that draws a vector field in R using ggplot for a given differential equation. There is a topic on the subject here however, the proposed solutions either don't provide ...
3
votes
1answer
42 views

Value matching in R

I have three data frames A, B and C: ...
2
votes
1answer
38 views

Scaling up the intelligent concatenation of 2 columns in R

I've got a huge dataset in R which contains (among other things) 2 columns indicating "Term Code", which are "Term Code" and "Term Code1". "Term Code" is the mostly-correct column, which usually ...
1
vote
0answers
56 views

Numerical maximization procedure normal distribution

Firstly, I programmed this gaussian density as an R function which takes the parameters mean and variance (mean=4,sd=1) and ...
0
votes
0answers
20 views

Numerical maximization procedure normal distribution functions

I generate a sample of size 1000 consisting of realizations of independent N(4, 1) distributed random variables: n <- 1000 x <- rnorm(n, mean = 4, sd = 1) ...