In R, is there a more efficient way to import an RDS of a data frame, append an existing data frame, and then write it to the same RDS than where f ...
In R, is there a more efficient way to import an RDS of a data frame, append an existing data frame, and then write it to the same RDS than where f ...
Say I have this data.frame The columns are mutually exclusive. I need to generate the output I've tried to to it with data.table fifelse but it ...
I would like to go over each row, and if the difference between the current row and the previous row is more than 7, then I would like to assign the c ...
How do I multiply the values inside a column by grouping from another column. Let's say I have : I want to multiply the elements of the value with ...
In the data.table below, I want to flag the first row by each group. Following is the expected outcome after adding the flag. Here is the soluti ...
I have a data.table that looks like the below, grouped by id and type. If the sample size is zero in period i and i is not equal to 1, I would like t ...
I have code which uses write.csv to save a large number of files in bzip2 format. Here's a small reproduceable example: I want to speed up the code ...
I'm stuck on how to conditionally lag a date variable within the same ID group, but skip the next date value and lag the one after if it is the same a ...
I have a very large 3D array (say 100 x 100 x 10) that I would like to apply a function over for pairwise comparisons. I've tried a number of solution ...
Data frames and data.tables behave differently when selecting columns using a variable with column names. Is there a single expression that will work ...
In the toy example below, I want to delete all rows that have Inf or Nan values. In my actual data.table, there are much more columns. To delete al ...
I have a data.table that I want to aggregate by group (customer ID) and look at how their first spend compares to the second spend, third spend etc. ...
I have data with a date column: I want to add a sequence of months, from 1 to x, to the dates in column "X". The result should be a set of new colu ...
Given a data table DT with a column Col1, select the rows of DT where the values x in Col1 satisfy some boolean expression, for example f(x) == TRUE o ...
I have a dataset that looks like this: I need to make a new variable that assigns a unique value to consecutive runs and restarts when counts == 0. ...
I have a large data.table object where one variable is a list of character vectors. I would like to aggregated by a unique ID and in the process combi ...
I want to count how many times the names in column y match those of column x. Trick is there are multiple names within each cell and there is no patte ...
I'm trying to write a function that will rename variables across multiple columns inside of a data table in R. My data table is structured similar to ...
I am new to R. I'm trying to write a function that will perform calculations on a column vector by groups and bind the results to the data table as a ...
Please note that this question has been edited after r2evans' answer. Example data I have example data as follows: Updating the strata For every ...