Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [r]

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

1
vote
1answer
55 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
38 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 ...
0
votes
0answers
25 views

Neural network in R to analyze diabetes data

This is my first attempt at writing a neural network and I am experiencing immense difficulty in reducing the error value which is relatively high and thus reduces the accuracy of the model. ...
2
votes
1answer
28 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
32 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 ...
2
votes
1answer
50 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....
1
vote
1answer
39 views

Speed up computation on lists of lists in R (scalability issues)

My goal is to take a source list of vectors and apply a mapping to each vector. The mapping creates a list of lists. When the vector size in each list element is large (~20000), and the number of ...
1
vote
0answers
26 views

Cluster correlations for many (> 500k) features by threshold

I have a matrix with roughly 500,000 features that I'd like to correlate and find features that have correlations >= 0.90, then cluster these into one group. Is there an efficient algorithm to do this?...
3
votes
1answer
84 views

A series of yes-no questions to predict yes-no outcomes

I have been writing R scripts for about a week. I have been writing code for 20 years. I have a series of yes-no questions that I hope to predict yes-no outcomes so I know the R-squared will be ...
1
vote
1answer
56 views

Radix sort function in R

I know that sort in R uses radix sort, and I played around in implementing it (mainly to be sure I understood the algorithm properly). However, my implementation is ...
1
vote
1answer
52 views

Transform wide dataset into “tidy-data” within R

I have some really wide data in R that I want to transform into the "tidy data" format. Unfortunately, I cannot change the process that generates this data, so it must be done within R. My raw data ...
3
votes
1answer
75 views

Effective 3d array transposition with R/C++ (Rcpp)

Task is reshape 3d array from [row, col, slice] to [slice,row,col]. I tried implement base::aperm analog with Rcpp. ...
1
vote
2answers
61 views

Speed up sorting algorithm in R: make one column “smaller” than the other

Consider the following sorting algorithm: ...
1
vote
1answer
50 views

Character pattern replacement using gsub, loops, and data.table

I was trying to see if data.table could speed up a gsub pattern matching function over a list. Data for reprex. It's a list of ...
1
vote
2answers
48 views

Stitching together badly formatted log files

I needed to stitch together a large number of badly formatted log files. I [painfully] developed a script for it in R, one that successfully dealt with the various flaws in the dataset. However, this ...
1
vote
1answer
113 views

Efficiently sample a single row of an array at random

I have the following C++ code snippet that randomly samples a single row in an array called pop with num_specs columns and ...
0
votes
2answers
74 views

Checking the presence of certain variables in a dataframe

I'm writing an Exploratory Data Analysis using R Markdown. First of all, I need to check the "sanity" of the input data set. Among the other check I perform, I need to check if at least one between ...
2
votes
1answer
59 views

Iteratively simulate a parasite population

I'm trying to build a simulation in R to model the effects of different parasite egg laying behaviors on how many offspring the parasite has, given a limited amount of resources. In brief, this ...
2
votes
1answer
57 views

Read a directory of CSV files in R

I'm writing a lot of R in my spare time and am trying to get into good habits by using TidyVerse as much as possible. A large part of this has required reading entire directories of dated log files ...
2
votes
1answer
57 views

Fast algorithm for any(M==2)

I want to find a quick way to see if a matrix M has at least one value that is, say, 2. In R, I would use any(M==2). However, this computes first ...
4
votes
1answer
264 views

Group-wise deviations from means / centering with dplyr vs. data.table

I am trying in R to "center" a matrix (i.e. remove mean) group-wise (i.e. remove group means for each variable). Input is a matrix (including the grouping variable), and output is the same matrix, ...
1
vote
1answer
24 views

Creating the design matrices for a canonical correlation analysis

I have this code to generate symmetric matrices for testing how the design of the canonical correlation analysis I am performing works out. This is a extension of this solution Each row of the matrix ...
6
votes
1answer
68 views

Random Weighted Classifier in R

I am computing a random weighted classifier based on the rates at which 3 labels appear in a "train" set. I want to use this RWC as a baseline for other classifiers. I'm doing this over 1000 ...
1
vote
1answer
54 views

Extract numerics from matrix A with logical matrix B

I have a matrix A containing numeric values and a matrix B containing 0/1s: ...
0
votes
1answer
63 views

Is there a more efficient way of doing function 'which' in R?

The data file is here. Here are my codes: ...
-1
votes
1answer
42 views

Using R to transform Excel files to be combined

I have 50+ excel files that I need to transform (and eventually combine) to use in analyses. I’ve written a code that transforms them into the format I need, but it is extremely slow for files with ...
3
votes
2answers
60 views

Summations zu.mpfr and zstar based on a probability sample

Here is my code: ...
5
votes
1answer
60 views

Plain C implementation of 'Cumulative All' operation for R

I want to implement a cumulative all through R's C interface. I was able to hack something together that produces the correct results, but I have little idea what idiomatic C should look like. The ...
0
votes
1answer
75 views

R Function to Generate Predictions from Ratings and Save Results

I am trying to generate predictions using the function below in combination with sapply. My actual datasets are very large, I am attempting to make 1.5 million predictions with this function and it is ...
1
vote
1answer
85 views

R function to generate predictions from ratings

I am trying to improve the run time of a program I wrote in R. Generally, what I am doing is feeding a function a data frame of values and generating a prediction off of operations on specific columns....
2
votes
1answer
78 views

Average calculation

I'm testing the influence of the time period on the end result of my calculations. To do this, I'm using a for loop, that is detailed below. In the current state of ...
0
votes
1answer
45 views

Function to calculate Persistence Rate with optional group_by variable and logical arguments

The Function "Persistence" is sometimes also referred to as "retention". It is defined as the number of units (ID's) in a given term/period that are also found in the subsequent term/period. So, if I ...
3
votes
0answers
30 views

Function to calculate “Persistence Rate” by group with a logical argument to determine whether to include overall persistence

The Function "Persistence Rate" is also sometimes referred to as "retention rate". It is the number of ID's in a given term/period that are also found in the next term/period. (e.g., I have 10 ...
4
votes
2answers
105 views

Vectorizing a complex nested for loop in R (running models on different subsets of a data set, subsetting the data differently for each loop)

This is my first time posting so hopefully I manage to get my question across in a clear and concise manner. I'm not sure this is the right place but someone on StackOverflow suggested I ask here. I ...
4
votes
1answer
43 views

Streamline R code for Shiny usage

I have the following code to create a table for overall percentages and the past 30 day percentages. I would like to add this to a Shiny app I'm making, but I feel there is a simpler or shorter way ...
1
vote
0answers
64 views

Predicting Disaster (Titanic)

Intro I have started a new course (Analyzing Big Data with Microsoft R) and have an exam soon. So I wanted to test my skills, and a nice way to do this was by doing a Kaggle competition Titanic: ...
1
vote
0answers
71 views

Euclidean distance of two matrices

I am writing codes to have the Euclidean distance of two matrices and then storing them in a matrix. Could anyone please review this? ...
1
vote
1answer
36 views

Tenis Common opponents R

I'm follow this article about "common opponent in tennis", my goal is to script it in the most efficient way. Below you can find my code but is so slow. To calculate the result of 1 match my laptop ...
3
votes
1answer
60 views

Determining whether a list of pathways and its genes are all included in another list

I am evaluating if a list of pathways and its genes has pathways included in another pathways. So the way I thought about it is to create a function that does just a single comparison. ...
1
vote
1answer
83 views

Find the minimum value that data could have had before it was rounded

I have this function in R: ...
0
votes
1answer
51 views

1D data classification

This R code separates the values in rData. They are classified according to the class in rClass. To do that, ...
2
votes
2answers
61 views

grouping data and date management in R

PROBLEM STATEMENT I have a code to treat agronomic data. I have a data.frame called yieldwith different information (dry.weight / infected pod / healthy pod). These ...
6
votes
2answers
187 views

Moving average function in C++ for use with R

I am trying to improve the code and speed up in C++ (Rcpp) a (centered) weighted moving average function I coded. An example of what the roll_mean function does. Note that the function works no ...
0
votes
1answer
198 views

pattern matching, replacement and for loop optimization in R

0 down vote favorite I have two data frame loc_df and and city_df (city and country) now loc_df has 5 column but considering only 2 here (Organization.Location.1 and Organization.Location.2) with ...
2
votes
1answer
179 views

Constructing a tibble from another tibble (without for loops?)

tibbles documentation I've got this doing what I want, but it's using a for loop and I've read many times to avoid for loops in R for efficiency and style. Well, it's not a computationally demanding ...
0
votes
1answer
87 views

Rolling mean lag function for multiple variables

Thanks to @josliber's help (Rolling mean lag function), I was able to speed up a rolling mean function for different groups and rollmean lengths. Now I'd like to add to this function the ability to ...
2
votes
1answer
105 views

Rolling mean lag function

I'm working in base R here, but would like to convert these functions to something more efficient in R (e.g. speed up processing with dplyr). This takes a while ...
2
votes
0answers
57 views

Reshape GET Request to Long Data Frame in R

Overview Converting the content of the httr::GET() request from json into an r data frame required a few data manipulation steps to reshape the data to long format ...
4
votes
1answer
108 views

Concise Proof of the Monty Hall Problem in R

This is an attempt at a concise proof of the Monty Hall problem in probability and statistics in R. For those unfamiliar, the scenario is this: There exists a contestant on a game show. This ...