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

learn more… | top users | synonyms

3
votes
1answer
22 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 ...
3
votes
1answer
57 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
49 views

Optimize CSV reader

This code takes more than 5 days running, but, it worked perfectly on the data test. ...
2
votes
0answers
43 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
1answer
46 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 ...
1
vote
0answers
21 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
39 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
52 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 ...
0
votes
1answer
31 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
47 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
30 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
61 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 ...
3
votes
1answer
50 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
49 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
61 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
38 views

Value matching in R

I have three data frames A, B and C: ...
2
votes
1answer
35 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
50 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
16 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) ...
4
votes
0answers
33 views

Pivot-friendly binning of arbitrary vector

I frequently get a situation in which I want a pretty binned column from a vector of values, so that I divide the vector in approximately even ranges and choose 'sensible' values so that it looks ...
1
vote
0answers
45 views

Algorithm for correcting missing values

I have problem with setting missing values in data frame. In the first 3 columns there are ID of product, ID of store, and number of week. There are also 28 columns from 4 to 31 corresponding to last ...
3
votes
1answer
91 views

Nonlinear Scaling Normalization

I have a procedure for normalizing variables, 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 variables. Below is ...
4
votes
2answers
74 views

Reducing memory usage for FizzBuzz in R

I've been trying all night to get my fizzbuzz to use below 20 MB of RAM but I can't seem to get it much smaller than this. ...
3
votes
1answer
45 views

Fast canonical indexing of elements in array

Given two arrays of elements: aaabbccdefaa zzzccddafgzz I want to check whether these two arrays are equivalent up to a relabeling. My strategy is to map them into a canonical form and ...
1
vote
0answers
77 views

Time-course of drug amounts in the different compartments of a pharmacokinetic system

I am looking for a way to speed up applying my function to every individual in the data frame. Currently I am using the ddply but it is very slow for big data sets. ...
2
votes
0answers
114 views

Genetic algorithm for the minimum of the Schaffer function

I have to implement a genetic algorithm in R to optimize the minimum of the Schaffer function. Below I describe each step and I need to create one big function and another loop for 100 iterations (and ...
0
votes
0answers
72 views

Stochastic gradient descent in R

Please, review my code, which counts global minimum with method stochastic gradient descent for schaffer function ...
5
votes
1answer
322 views

Simulated annealing in R

I am new in R and I have to implement simulated annealing for schaffer function and I did it. However I am not sure about the correctness of the code. ...
1
vote
0answers
95 views

Naive Grouping for Factorization

UPDATE: I have posted this question on math.se along with the identification of a new relationship to lattice points on hyperbola. I have a naive grouping method for factorization. I am curious as ...
3
votes
1answer
118 views

Trial Multiplication for Factorization

I am trying a trial multiplication for factorization. This is a general example, but each sequence can be specified to pairs of sequences \${p,q}\$ for a given \$n\$. For example, if \$n\$ ended in 3, ...
3
votes
0answers
47 views

Computing pairwise distance covariances for a symmetric matrix

I wrote a non-vectorized, non-parallel wrapper function for computing the pairwise distance covariances (Wikipedia) (original paper) in a data frame: ...
6
votes
2answers
77 views

2D lattice random walk plots in functional style

To practice writing code in the functional programming style, I wrote a program to plot two-dimensional lattice random walks. I'd appreciate any feedback about how to improve its "functionaliness". ...
4
votes
0answers
138 views

Crawling and parsing meteorological data from the web into R

I am interested in collecting directly into R data published by the Mexican Met-office. The data pieces are spread through several URLs, but one can start here. There I can get the names and ...
1
vote
0answers
83 views

Extract and rename specific columns of a CSV data file

I have a CSV data file with 3,896 columns (variables), and I am attempting to extract a particular subset of columns for use in a data analysis project. To avoid the burden of having to constantly ...
6
votes
1answer
63 views

Lookup GINI by year and country

This takes a dataframe as an argument, looks at all pairs of two columns in that data frame (country and year) and returns a column value of that pair in another data frame (the gini number). ...
4
votes
1answer
254 views

Sublime Text 2 R Build System (source file, send selection to interactive session)

The following is the description of the R build system I am using (very happy) with Sublime Text 2 on linux (Crunchbang). With it, I am able to: to source the current file.R to an interactive R ...
2
votes
0answers
113 views

Smoothing matrix for visual representation

I recently started playing around with R and am currently trying to plot GPS data points onto a perspective plot. I have a script that works and I get my desired results out of it and it works ok for ...
3
votes
0answers
46 views

Volatility updating with Heston-Nandi model

I'm trying to program a volatility updating rule using iteration. I start with the well-known Heston-Nandi model where the returns dynamics are: $$ \left\{ \begin{array}{rcl} R_{t+1} ...
2
votes
1answer
126 views

Quick estimation for empirical permutation and correlation test in R

I have two matrices (a, b), each including 3 genes and 6 observations. I have estimated the Spearman correlation for gene pairs (rcorr.observed). Then I want to do an empirical permutation (1000 ...
3
votes
2answers
76 views

Python path-breaking script for use in R

R does not support line continuation as Python, and it's disturbing to have long file paths like /media/user/data/something-not-very-important-but-super-long/some-curious-secret-file.pdf and ...
4
votes
1answer
69 views

Creating a special Toeplitz matrix in R

I'd like to know if there is a standard way of creating a matrix like the one shown below using the R programming language. $$ \begin{bmatrix} 1 & \rho & \rho^2 & \cdots ...
5
votes
2answers
122 views

Concisely adding values in a loop to a column

In my data frame I assign values to the column Register by checking another column (Source) for specific values. Based on those values, the output in Register changes. I am relatively new to R, but I ...
3
votes
1answer
58 views

Simulation of animal skins

This is a simulation of animal skins, like a cellular automat. I'd like it improved. ...
1
vote
0answers
30 views

Comparison of two regression types on the same set of models

I wrote a relatively simple R script to run a bunch of regressions. To be precise, it is a hurdle negative binomial regression (fancy stuff for count data). To print it out easily to ...
3
votes
1answer
36 views

Merging predicted values into measured values

I created the following function below to merge the real values with the predicted values (when real are absent) in a new column in data.frame. The function ...
1
vote
3answers
228 views

An R function for checking whether a variable is binary or continuous

This function takes a numeric vector and returns "con" if it's continous and "bin" if it's binary. It does not take the multinomial case into account, i.e. if a variable y has three possible values ...
4
votes
1answer
86 views

Speeding up nested for-loop analysis code

I have two matrices, the first one is mat 2000*500, the second one is 6000*500 ...
1
vote
1answer
56 views

Frequency form to case form - unexpected values in table

I'm taking count data on voting preferences by race and entering it into a table in frequency form, then expanding out to case form and using CrossTable to look at ...
3
votes
0answers
68 views

Finding the Cox regression coefficients in a mixed model for microarray data

I have written a code for a project which aims at finding the Cox regression coefficients in a mixed model for microarray data. The study was carried out on the Affymetrix Hgu133a platform. In the ...
5
votes
1answer
106 views

Vector comparison inside for-loop

The following code finds no-rain periods in a time series that were preceded by rain over a threshold (e.g. 10mm in 2 days [k=48]). ...