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

learn more… | top users | synonyms

1
vote
0answers
13 views

Estimate Hidden Markov Model with both continuous and discrete observations, possible missing data

My code estimates a Hidden Markov Model (HMM) using the expectations-maximization (EM) algorithm. I followed https://www.princeton.edu/~rvan/orf557/hmm080728.pdf with modifications to allow for panel ...
-2
votes
0answers
14 views

Web Scraping of Google News using R [on hold]

I am trying to scrap data from Google news for a particular topic using XML and Curl Package of R. I am able to extract the summary part of the news through XPath but in a similar way, I am trying to ...
2
votes
1answer
18 views

Matching dataframe rows for finding trade match

I need some help to refactor the script. I have a script which matches the buy and sell trades based on FIFO order. The initial dataframe looks like this: ...
1
vote
0answers
25 views

Self organizing maps

I have already asked similar question here, but I figured this place might be better on getting some actual implementation feedback. I tried to implement a simple SOM. You can see the training ...
2
votes
1answer
39 views

Look up value from one dataframe and find percent of values in another dataframe that are less than that

Is there a one-liner that can accomplish this same thing? Essentially I have two dataframes: one that has my raw data (data), and one that has values that I want to ...
2
votes
0answers
37 views

Numerical differentiation using the y-intercept

I have a routine for determining the derivative of a function using the y-intercept (B) to infer the finite difference step (h). ...
0
votes
1answer
61 views

Code for finding repeated entries with different data

project is the data frame. For the purpose of the code, HOUSE.NO is a column of the type character, and ...
4
votes
1answer
62 views

Rolling regressions in R

I want to run rolling regressions over each group and store the coefficient. The following works, but it's slow, since I have too many series and I want to run too many regressions for each group. ...
2
votes
1answer
39 views

Clinical decision tree using R

I'm trying to code this decision tree using R. I was wondering if there was a better way to go about this rather than using a ton of conditionals? ...
1
vote
1answer
59 views

Permutations with repetitions algorithm in R

Given a string of length n, print all permutation of the given string. The code bellow generates all permutations (with repetitions) for the given string and stores them in object ...
1
vote
0answers
35 views

Caching calculation results in R

Here is what I came to for calculation result caching/invalidating. What do you think? How to use: ...
3
votes
2answers
72 views

Filtering numeric vectors by proximity to any elements of another vector in R

I frequently want to filter and select elements from a long (10,000s to millions of elements) vector in R. Often, this vector is a column in a data.frame. I am ...
2
votes
1answer
48 views

Nested loops - Random Forest, multiple parameters

I'm writing a code which task is to grow Random Forest trees based on multiple parameters. In short: Firstly, I declare a data frame in which model parameters and some stats will be saved. Secondly, ...
2
votes
1answer
55 views
2
votes
1answer
47 views

Cumulative transition matrix Markov Chain simulation

I have a cumulative transition matrix with probabilities for all the possible states from 1 to 5. Now the algorithm for simulating future states is following: the initial state is selected randomly, ...
2
votes
1answer
51 views

Achieve a dataframe from a dynamic list of lists

This code works for me, but I am trying to improve my coding and am looking for advice on how to improve it. Specifically I want to simplify this so that perhaps I can have a dynamically updating ...
2
votes
2answers
61 views

Generating time series for generator ON or OFF

Want to create time series for the nuclear power plant performance using the equation for Time to fail and time to repair for 8736 hours in the year so that I have the time series in hours when the ...
2
votes
1answer
38 views

Design a main function which determines which secondary function to be used

I am writing an R package. The package consists of a main function and lots of auxiliary functions that perform different calculations. The main function The idea behind the package is to make the ...
3
votes
0answers
120 views

Nonlinear Nonparametric Regression

I explain the nonlinear correlation coefficients in this paper and provided the code in this post. The nonlinear nonparametric regression is an extension of this work and its description can be found ...
1
vote
2answers
38 views

Performing several hundred raster multiplications

I have several hundred "A" rasters, numbered from 001_A.tif to 100_A.tif. I also have several hundred "B" rasters, numbered ...
0
votes
0answers
34 views

Naive-Bayes classifier, to be packaged in a function

I need to create a Naive-Bayes classifier. I have eight labels (S) stored in tumors object, and 20531 attributes (A), I have stored the P(S,A) in objects of name ...
2
votes
0answers
29 views

Complex Space Factorization

I have posted a discussion on Math.SE regarding visualizing the complex space and effects of factorization methods on that space. A quick link to the paper is available here. I have 3 routines in ...
3
votes
0answers
100 views

Correlation and Dependence

It is well known that 0 dependence implies 0 correlation, while 0 correlation does not imply 0 dependence. I have a paper here illustrating nonlinear correlation coefficients from relationship subsets ...
1
vote
1answer
84 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
33 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: ...
2
votes
0answers
93 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
47 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
80 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
66 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
173 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
80 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
84 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
103 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
62 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
277 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
348 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
50 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
90 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
60 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
83 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 ...
2
votes
1answer
70 views

R merge even/odd rows

I need to merge eve/odd rows on a data set. Example: ...
1
vote
0answers
41 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
40 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
20 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
78 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
37 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
46 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
40 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. ...