Questions tagged [r]
R is a free, open source programming language and software environment for statistical computing and graphics.
385
questions
2
votes
1
answer
35
views
Comparing univariable regression results between complete-case and multiple imput data sets
Dear Code Review community,
I try to develop a reproducible code to pool univariable regression estimates across multiple imputed data sets in R.
I therefore prepared the following code that is ...
0
votes
0
answers
40
views
Forecast the turnover with a prophet model in R
I am a student who is interested in data analytics and currently figuring out how to write forecast models for several scenarios in R. I'm working on a fictitious project in which I want to forecast ...
1
vote
0
answers
93
views
Filtering spatial data based on a distance matrix from large datasets
I am using a R function to spatially filter location points. There are five steps in the function: 1) calculate the distance between all points, 2) for each point, define the number of neighboring ...
0
votes
1
answer
32
views
Transform variables based on a constant in another object
My problem
I am working with two objects, structured as follows:
...
1
vote
0
answers
23
views
LASSO kernel for nonparametric models
I am a novice in nonparametric modeling and have recently begun exploring the world of varying coefficient models. Essentially, these models involve a non-linear least squares problem that relies on ...
1
vote
1
answer
56
views
Optimize an algorithm for preparing a dataset for machine learning
I'm learning how to use R coming from a python background. I'm following Andrej Karpathy's zero-to-hero course, reimplementing it in R.
We start with a list of 32033 names. These names have to be ...
1
vote
0
answers
328
views
R function to sort columns of gtsummary::tbl_summary objects
I work with gtsummary package a lot and wanted to try creating a function to sort the columns of table output from tbl_summary() ...
5
votes
0
answers
51
views
1
vote
1
answer
70
views
Group uncorrelated variables into subsets using correlation matrix
I am trying to group uncorrelated variables into subsets. So, using the correlation matrix, I check each variable to see the correlation. If correlation is more then a threshold I will create a new ...
3
votes
2
answers
88
views
Convert dataset from wide to a longer format for two different set of columns
I have a dataset that is a bit too wide for the EDA plots I would like to make.
The data can be found here: https://www.massey.ac.nz/~kgovinda/data/Bill_Colour.RData
But looks something like this:
...
8
votes
3
answers
578
views
Python+R Project: Fantasy Football Power Rankings Graphic Generator
I am in a fantasy football league and each week I send out a power rankings poll through Microsoft Forms. People will send in their rankings poll and I will create a graphic based on responses. I was ...
2
votes
1
answer
58
views
Calculate number of max and min outliers from data.frame
I am working on a problem where I need to get specific information for min and max outliers.
This is in relation to the ggplot library. I will be getting all my information from ggplot_build object.
...
0
votes
1
answer
62
views
How can I can do better with my R code to analyze word counts
I am new to R and to learn I start to code to do things that interest me. I have a biological background and I am very interested in bioinformatics.
I know some python, but I want to use R as tool to ...
0
votes
0
answers
28
views
Remake fs path() in pure R
My first post here, where I would like to create a function similar to path()
in fs package.
fs is based on the external C library libuv, but I need path() in ...
1
vote
1
answer
204
views
Find Reddit comments with a particular keyword
I am writing a loop (in R) to webscrape Reddit posts - using Reddit's API ("Pushshift").
Essentially, I would like to get every comment that contains the word "Trump" between now ...
1
vote
0
answers
62
views
convert GPS coordinates to C-SQUARES, resolution 0.05°×0.05°
This is a simple C-Squares encoder in R.
FYI, C-Squares is a geocoding algorithm that assigns GPS coordinates to a spatial grid with a chosen resolution. Its specifications is here: https://www.cmar....
2
votes
0
answers
63
views
S_n covariance calculation function
I am trying to understand the estimator proposed in ["Multidimensional outlier detection and robust estimation using Sn covariance"][1]. I wrote the code in a basic line-by-line form which ...
2
votes
0
answers
47
views
Plot ellipse hypothesis plots with confidence intervals for multiple models
I have developed a function to graphically plot between two predictors of interest their confidence interval regions on an ellipse. It states whether the null hypotheses have been accepted for the one-...
2
votes
0
answers
111
views
All permutations of a linear model given all predictors
I have developed a fairly large function that can do the following:
From a dataset, select the response variable and the independent variables.
Get all the number of permutations for the formula ...
2
votes
1
answer
39
views
R: Function to return the category that has the maximum in another variable [closed]
Is there a nice simple function to return which diet has the highest average? I can calculate the means from each diet using:
...
1
vote
0
answers
57
views
Extract, transform, and load Excel files
I am curious to know if there is a cleaner/better way to write this. Any suggestions would be greatly appreciated! I do ask some questions in comments within the code specific to certain functions/...
1
vote
1
answer
62
views
R code to calculate coef
Can you help me think of some way to reduce the computational time of a code that generates a certain value, which in this case I call coef, which will depend on <...
1
vote
0
answers
37
views
Another solution approach to find if trailing zeros exist for each row id
The code below removes trailing zeros exist for each row id.
This question has been resolved here https://stackoverflow.com/questions/69452882/delete-column-depending-on-the-date-and-code-you-choose. ...
0
votes
0
answers
47
views
calculating all prime numbers up to a given number
This program calculates all prime numbers up to n. However it runs pretty slowly.
I was wondering if there was any optimisations I could make.
...
-1
votes
1
answer
52
views
Mapping variables in two data frames using a third data frame
I have two data frames, df1 and df2 of identical structure. The first three columns, id, <...
2
votes
1
answer
359
views
Create a folder with subfolders and files from a R dataframe
I have such a dataframe:
...
0
votes
1
answer
56
views
A function that modifies the column types of a `data.frame`, given a character vector of "format codes"
Problem
A business process requires me to read two different text files (raw and processed) into R as data.frames, with each column being read as a character type. ...
1
vote
1
answer
64
views
How can I simplify the code using just the tidyverse?
So I have the data frame below, and I'm trying to creat a new Data frame which show me the name of the department which have the highest and the lowest employee turnover. The code that I write is ...
0
votes
1
answer
53
views
Faster way to print Number of Descents in a permutation in R
I am trying to find a more efficient way to print the number of descents in a permutation using R as my programming language. This code does it for the numbers 3 to 10:
...
3
votes
0
answers
45
views
R language optimize converting mpfr to gmp
I wrote a function to convert, without loss of precision, a mpfr - class value to a gmp bigq value. (This particular operation ...
1
vote
1
answer
65
views
Conditionally drop rows in grouped data.frame using dplyr in R
I have a data frame with columns for three predictors that try to predict the target variable 'change' with values 'yes' and 'no'. The data frame is grouped by id, and for every id, I have 4 years.
...
0
votes
0
answers
78
views
How can I make this code more efficient
i try to get the row count for last three column (Kindly refer the below image ).I have done using for loop but the concern is it takes so much of time to execute in my application, and i heard apply ...
2
votes
2
answers
119
views
Assign 0 or 1 with different probabilities conditional on another column in R
I am trying to assign a 0 or 1 with some stochasticity based on another column in a data frame (outcome). If outcome == 1, the ...
1
vote
0
answers
58
views
Estimating risk differences for marginal models
I need to estimate risk differences for marginal models. I have worked on the Probratio function to create an equivalent function for RDs that works.
Please provide feedback on accuracy or comments to ...
1
vote
0
answers
44
views
Combine several calculations on several variables
This is my very first time here, I am coming from stackoverflow.com thanks to @r2evans.
So I apologize in advance if I don't follow all the rules.
I wrote a code in ...
0
votes
1
answer
56
views
Increase speed of lapply function identifying the sum of all existing combinations
I have a dataframe of cases that score 0-1 on a group of binary attributes.
What I want to do is extract all possible ombinations of attribute triplets (e.g. A/B/C, A/B/D... out of A-E) and then sum ...
2
votes
0
answers
29
views
Transform dataframe to a certain JSON format
I need to go from this dataframe:
...
3
votes
1
answer
87
views
Simulating disease spread in a population
I am trying to build a model that allows me to estimate the spread of disease in the population. The setup is similar to the SIR model, with the difference that this model includes the stochastic ...
0
votes
1
answer
285
views
An efficient way for removing rows with zero elements iteratively while constructing the matrix
Based on a previous post, Accelerating creation of matrices and finding ways for optimal scaling, we managed to accelerate the way that I construct a matrix in Rcpp (inputs for example are at the end ...
0
votes
1
answer
56
views
R code for reading tabular data files and plotting light curves of modeled stars
Here is a minimal example of my task...
I have four 2-column files. profile1.data
...
1
vote
1
answer
38
views
R code for reading tabular data files and plotting light curves of modeled stars
I am given a file named profile1.data that looks like this:
...
1
vote
1
answer
69
views
Accelerating creation of matrices and finding ways for optimal scaling
I have the following specific task, for which I have written code, in Rcpp, but it doesn't scale well and I would like to improve it. I'll describe first the steps of the procedure
Step 1:
We have ...
1
vote
2
answers
65
views
R coding: creating a name variable to use with select
I am wondering if this is correct:
...
0
votes
1
answer
70
views
R code optimization
I have about 977 obs in top500Stocks which contains name of 977 stocks.
...
2
votes
1
answer
236
views
Find if a dataset of words contains any words containing all vowels by using exactly 5 calls to str_detect
Take the words dataset from stringr. An R4DS exercise challenges the reader to check if there are any words in that dataset that ...
1
vote
0
answers
37
views
using R probability
I am working on the subject of the French championship 2019, composed of 20 teams, and each team plays 38 times, if team A plays with team B, whatever the result, each team plays another time with ...
3
votes
0
answers
126
views
Rcpp sparse CSC matrix class
This is a sparse matrix (dgCMatrix) class that extends Rcpp.
WHAT: This class includes Rcpp::NumericVector and ...
1
vote
1
answer
69
views
R Container for Multiple data.frame with a Brief Description of the Content of the data.frame
For a project I have a large dataset with a multitude of variables from different questionnaires. Not all variables are required for all analyses.
So I created a preprocessing script, in which subsets ...
0
votes
2
answers
92
views
Algorithm that creates in a systematic form, matrix with zero-one elements
I'm working on Rcpp and I wrote the following code
...
1
vote
0
answers
42
views
Reimplemented R function(s) is surprisingly slow
I reimplemented the functions https://rdrr.io/cran/fclust/man/RI.F.html, https://rdrr.io/cran/fclust/man/ARI.F.html and https://rdrr.io/cran/fclust/man/JACCARD.F.html of the R package https://rdrr.io/...