Questions tagged [r]

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

Filter by
Sorted by
Tagged with
1
vote
1answer
14 views

Statistical sampling from a vector

I have written a function/script to simulate data for sample size estimation. The following code samples from a vector of generated values with varying numbers of sample sizes and then concatenates ...
2
votes
3answers
34 views

Flagging system: Check for changing values in a data frame

I've written the following code to check if a value in a data frame changes. I'm looking at the last 5 values. If there was no change at all I want my code to return 1, if a single one (or multiple) ...
1
vote
0answers
31 views

code plots - spatial data

I am an absolute newcomer in R. For my bachelor thesis I worked with spatial data. I did many plots with the normal "points"-function. I already have my results, but would like to improve my code. ...
0
votes
0answers
20 views

Plotting spatial data [duplicate]

I am an absolute newcomer in R. For my bachelor thesis I worked with spatial data. I did many plots with the normal "points"-function. I already have my results, but would like to improve my code. ...
4
votes
1answer
56 views

Citymapper API wrapper

As a simple project to tackle during the holidays I've set to write a simple wrapper around Citymapper's api to familiarise with httr, ...
1
vote
0answers
22 views

Extracting English-French cognates from a messy .txt glossary

After using an online tool to convert a PDF glossary of English-French cognates to a .txt file, I wanted to write a simple script to extract the cognate pairs and save them to a CSV. I could then ...
1
vote
0answers
20 views

R solution to max product in matrix for four adjacent numbers (Euler 11)

Background This is solution to Problem 11 on Project Euler that is concerned with finding largest product of four adjacent numbers in the provided grid. Other than solving the problem I was also ...
9
votes
0answers
86 views

Generated Minecraft stone texture in R

I needed a Minecraft-like stone texture, instead of creating it using image editing software I decided to generate one using R. The idea is to create some noise and stretch it horizontally so the ...
1
vote
0answers
39 views

Is there a cleaner way of writing this dplyr sql server query

This is the first time I am writing R code to access/manipulate and save data. The SQL query I would normally run then save to a spreadsheet, read it into R, save to another sheet then copy and paste ...
3
votes
0answers
49 views

Stack Structure in R

I've written a stack implementation in R using S4 Classes. I would like feedback concerning anything with the application because it's my very first program in <...
0
votes
1answer
28 views

Correctness and Performance of graph plotting on R

Current State: I have two CSV files, their sample attached below: FileOutputWithoutBuffer-Metrics.csv ...
0
votes
1answer
77 views

R: Optimize algorithm speed that estimates hourly temperature and relative humidity

I built an algorithm to estimate real-time temperature and humidity values ​​based on daily values ​​of the same variables. The algorithm works, however the speed with which it processes the ...
1
vote
1answer
55 views

Computing features over the same dataframe

The following code computes three different features over the same dataset. I'm not sure if the filter_by_day_segment function can be made tidy or there's a more ...
2
votes
1answer
62 views

Dictionary function for R

I'm new to R and have created a dictionary function. A user will input a phrase into a text field and the server will read it and see if there's a match in a back-end data table and if so, output the ...
2
votes
1answer
83 views

Speed up a while loop that conditionally creates a new variable in R

I would like to speed up the following code in R. This is a loop to define new individuals (column newID) when the variable ...
1
vote
1answer
36 views

Filter string with min distance in r

I have the following sample data: target <- "Stackoverflow" candidates <- c("Stackflow", "Stackflow", "Stckoverfow") I would like to filter the string from ...
8
votes
1answer
400 views

Truth table generator for an arbitrary function

Summary: This function generates a truth table for a boolean function of variable number of arguments. The name of the function passed and its arguments are deduced outside of the computable function ...
2
votes
0answers
56 views

Compute angular distances between data points in a matrix

I am having a hard time speeding up a function that I use to compute angular distances between data points in a matrix. More precisely, I want to compute $$\sum_{r=1}^n|\pi - \arccos\left(\frac{(X_{i}-...
1
vote
0answers
164 views

Random Forest model

I am new in machine learning methods and I am trying to use a Random Forest regression. I want to explain the influence of my variables on the variable "one" and I have the following code: ...
6
votes
2answers
127 views

Mandelbrot rendering code in R

I'm trying out a new continuous histogram coloring method for Mandelbrot rendering in R, and since it requires three loops (three passes), each of them doubly nested, there should be a way to ...
4
votes
2answers
78 views

Looping through two lists and randomly aggregating elements to equal an element from another list

I have three datasets, "CV", "FV" and "LA". I have attached reproducible data for all of them. The idea is that some combination of the elements in each column of CV and FV should sum up to equal the ...
10
votes
1answer
117 views

error-specific tryCatch

R doesn't have classed errors, just (for the most part) error and warning, so determining if the error should be caught or ...
3
votes
0answers
105 views

Efficient way to fill 2D matrices by rows in a list using R

I have a list of 2D matrices. Each matrix is filled using the function “fillMatrices”. This function adds a number of individuals to each day 0 in a matrix and updates the columns “a_M”, “b_M” and “...
3
votes
1answer
290 views

Merge dataframes on timestamps and time intervals using data.table in R

I have two dataframes (x and y) that I need to join, conditional on the timestamp in ...
2
votes
2answers
87 views

Generate a large block diagonal covariance matrix with exponential decay

I am implementing Kalman filtering in R. Part of the problem involves generating a really huge error covariance block-diagonal matrix (dim: 18000 rows x 18000 columns = 324,000,000 entries). We denote ...
2
votes
1answer
80 views

Group by consecutive values in first column and second column value

I have a typing log in which rows are grouped by consecutive package_name, and within those groups rows are grouped if they are logged within 180,000 ms from each ...
3
votes
1answer
46 views

dput() concatenated vector with no quotes, separated by commas in R

An oddly specific task - I have a dataframe with columns with values I need to concatenate in order to prepare a query for a website that requires very specific inputs: unquoted strings, separated by ...
1
vote
1answer
60 views

Replace values in R data frame according to values in other data frame

I would like to change row names values from a first data frame if these rows names are present in another data frame, and change it to a corresponding value (defined in the second data frame). I ...
4
votes
1answer
70 views

Generating random sparse matrix

My goal is to generate a large sparse matrix with majority (~99%) zeros and ones. Ideally, I would be working with 10,000 rows and 10,000,000 columns. Additionally, each column is generated as a ...
1
vote
1answer
30 views

Two-Part Hurdle Model Simulation with Bootstrapping

I am running a simulation study where I am using two-part hurdle modeling on different effect sizes. I tried to stream-line my code for the best optimization including foreach loops and ...
2
votes
0answers
69 views

Bias-corrected percentile Bootstrapping Optimization

I have never posted to this forum, but was referred here. I need some help printing key iterations as well as optimizing my code for run time. If someone had some time to help/explain how to correct ...
3
votes
1answer
54 views

Extracting small word parts (quadgrams) from text using R

I would like to extracts small word parts (quadgrams) from text. Example: hello world results in: ...
5
votes
1answer
79 views

Manually writing a function matrixpower() in R

Problem 1 - Matrix powers in R R does not have a built-in command for taking matrix powers. Write a function matrixpower() with two arguments mat and k ...
2
votes
1answer
54 views
5
votes
1answer
84 views

Passing uint64_t from C++ to R: Hilbert Mapping - xy2d function

I have been working with Rcpp to perform a forward and backward Hilbert Mapping. Below is an implementation based on this code. My application is in genomics and I may be dealing with enormous ...
3
votes
1answer
42 views

Sample size, P-values (its relationship), and data visualization with plots. ggplot and T test

We know that P-values (within t-test context as an example..) is highly sensitive to sample size. A larger sample will yield a smaller p-value remaining everything else constant. On the other hand, ...
4
votes
3answers
61 views

Fill missing value based on ID

Say that I have running id from 1 to n, and a value column: ...
3
votes
2answers
71 views

Finding values below a threshold

I am wondering if it's possible to avoid looping. I want to make the function faster. The function is to find how many times a particular value is lower in the overall data. For example: ...
0
votes
0answers
58 views

Text2Vec - fit_transform, $transform TF-IDF

I am sorry if this is a wrong place to post a question. I have two questions: ~ A) I am trying to do text similarity using TF-IDF cosine similarity. I somehow managed it in the fallowing code, ...
3
votes
1answer
151 views

Discrete event simulation for production defects

I have one machine, which produces parts. In machine_failure_rate% it produces faulty parts which need to be produced again. Thus, we end up with a simple queuing ...
3
votes
1answer
92 views

Plots of prior and posterior distributions for a model

I have an exercise that ask to plot the prior and posterior distribution in the Poisson-Gamma model. I did it (I think it's correct) inspired in the answer of this question https://stats.stackexchange....
2
votes
1answer
84 views

A faux parser for fdf files

Introduction If you know what FDF files are, you can skip this section. PDF files sometimes includes form fields. These fields can be represented as FDF in plain text form, extracted using certain ...
1
vote
1answer
111 views

Using findInterval to assign vector elements to corresponding brackets

The following function receives a vector of positive integers and list of brackets. The function returns a data frame with a logical vector for each bracket indicating whether a given element of a ...
0
votes
1answer
387 views

Calculate decile table with some loop in R

I wrote code which calculates: Decile threshold for every decile group Total income in the decile group Number of persons Share of decile in total income (%) Tax Share of tax (%) But unfortunately I ...
1
vote
1answer
75 views

Simulating data generating process correctly

My aim is to simulate the following model by means of a Monte Carlo simulation. I wonder if my R code is correct for generating the data. Could somebody check? The model: $$Y = \sum_{j=1}^{100} (...
1
vote
1answer
76 views

Get maximum sequence lengths taking into account the tradeoff of omitted observations

From a data frame d I have to select the longest possible sequences of x. variables. Example: ...
-1
votes
1answer
54 views

R Regex : Need only numeric figures [closed]

I'm working on R and using regex to keep only numeric figures in a column (I need to keep digits, negative and decimal sign). Suppose I've a value ...
2
votes
1answer
75 views

dplyr — tidyverse, pipes, correlation, same variable across time “a” “b”

Have a look at this dataset. The"a" and "b" are used to make possible differentiate when the same variable was measured. In this case X1a and X1b access the same variable, but "a" was (suppose..) in ...
1
vote
1answer
304 views

Using dplyr and pipes for logistic regression plotting

I have successfully created a plot of a binomial glm using example data. https://sciences.ucf.edu/biology/d4lab/wp-content/uploads/sites/125/2018/11/parasites.txt The predictors of the model include ...
3
votes
1answer
81 views

Applying a function to each row of a matrix

My goal is to apply a function func1 to each row of the matrix input and then return a new one resulting from the transformation....