Questions tagged [data.table]

2 votes
1 replies
How do I change the column names using dcast?
I'm transforming my data from long to wide. Part of the data are dates. My problem is that I would like to have other colnames. It is formed li...
asked 1 month ago
0 votes
1 replies
How to efficiently replace one set of values with another set of values in data.table?
This is a typical situation, when you have two datasets, in which the same observations are named differently, and you need to rename one of them...
asked 1 month ago
1 votes
2 replies
How to match linked steps indicated by two columns of a data.table
I have a data like this: structure(list(step_origin = c(4897L, 3105L, 129L, 2689L, 2945L, 161L), step_destination = c(3105L, 1057L, 2689L, 2945...
asked 1 month ago
1 votes
1 replies
Calculate the differences between one row and the rest of the data per group
I have a data.table with three id groups. The first group (batch1) has fixed dx and varied dy. The 2nd group (batch1) and 3rd group (batch2) have...
asked 1 month ago
6 votes
2 replies
Assign multiple results from function when grouping
I have this code which does exactly what I want but I have to call my function three times for every group which seems very inefficient. library...
asked 1 month ago
0 votes
3 replies
count row by time period in R with data.table
library(data.table) dt <- fread(" ID DATE A1 20170220 A1 20170308 A1 20170311 A1...
asked 1 month ago
10 votes
3 replies
Efficiently merging large data.tables
I have two fairly large data.table objects that I want to merge. dt1 has 500.000.000 observations on 5 columns. dt2 has 300.000 observations...
asked 1 month ago
0 votes
2 replies
Rolling Mean By Group Dplyr/data.table
I have a large data.frame with 350k rows. Currently I am trying to create a rolling mean of the lag_close column in the data.table. Since I am mo...
asked 1 month ago
-1 votes
1 replies
How to add quantile function to a data.table?
I am developing a function that returns a statistical summary on a data table. I want to add the quantiles to the output put I have been unsucces...
asked 1 month ago
0 votes
3 replies
Cumulative sum from a month ago until the current day for all the rows
I have a data.table with ID, dates and values like the following one: DT <- setDT(data.frame(ContractID= c(1,1,1,2,2), Date = c("2018-02-01",...
asked 1 month ago
0 votes
0 replies
If I am writing a list of tables to a csv file, how can I write also the list name and not only the content?
I am writing a list of tables in a .csv file. Everything fine, but when I write it down I would like to have at the beginning of each table the n...
asked 1 month ago
-1 votes
0 replies
Count rows by time period with data.table in r [closed]
I'm trying to count rows by time period(30days) with data.table in R I have dt like below : library(data.table) dt <- fread(" ID DATE...
asked 1 month ago
2 votes
4 replies
Conditional selection of repeated measures from data frame
I have data with repeat measurements on each subject (id) at a variable number of timepoints. I would like to retain two row for each subject, t...
asked 1 month ago
0 votes
4 replies
R data.table How to obtain the VALUE from one of many columns (by column NAME), based on the value of another column
I am trying to extract a specific value, from a data.table in R, by referencing the column name require(data.table) # Create data.frame cohort...
asked 1 month ago
3 votes
0 replies
How can I prevent the glm() function from adding back-ticks to some of my variable names?
I'm using glm() to create some models. The variables in my input data.table have names like "day" and "day^2". The model generated by glm() puts...
asked 1 month ago
0 votes
0 replies
Determining the most recent observation by group using .SD is extremely slow [duplicate]
Assume I have a data table containing some baseball players: library(plyr) library(data.table) bdt <- as.data.table(baseball) For each pla...
asked 1 month ago
1 votes
2 replies
How to shift values in rows of data.table based on value in the same row
I have a data.table like: structure(list(level = c(1, 2, 1, 3, 1, 1), step_destination_step_1 = c(3105, 2689, 1610, 4897, 129, 161), step_desti...
asked 1 month ago
1 votes
1 replies
compare rows by reference in data.table
In the search, I found a lot of questions on how to do this for columns, but not for rows. # Works just fine: data = as.data.table(iris) head(da...
asked 1 month ago
3 votes
1 replies
How can you calculate column sums based on a condition using data.table?
I have a table of IDs and 1000 columns of random values. I want to group the IDs and calculate the number of values less than 0.01 for each colum...
0 votes
1 replies
What does the error mean in a data.table with the function “seq” — “The RHS length must either be 1 or match the LHS length exactly”?
I am attempting to: calculate the difference in call duration between police units responding to the same call identify the longest duration a...
asked 1 month ago
0 votes
1 replies
Expanding rows to include interim years in a date range
I have a dataframe with date ranges in it, from which I'd like to create new rows representing each year encompassed by that range (including sta...
asked 1 month ago
-1 votes
2 replies
How to FILL DOWN (autofill) value , eg replace NA with first value in group, using data.table in R?
Very simple and common task: I need an equivalent to Excel's FILL DOWN (autofill) in data.table so that library(data.table) DT <- fread( "Pau...
asked 1 month ago
0 votes
1 replies
Sorting elements of a list column present in R's data.table
I need to sort the elements of a 'list' column of data.table in alphabetical order and coerce them to a character vector in another intermediate...
asked 1 month ago
0 votes
0 replies
Unexpected behaviour of data.table setcolorder [duplicate]
I'm having a little trouble understanding the pass-by-reference properties of data.table. Some operations seem to 'break' the reference, and I'd...
asked 1 month ago
1 votes
1 replies
Import from `.` `data.table` so that lintr recognizes it
When running lintr on an R function that uses data.table I get the following warning: warning: no visible global function definition for '.', Di...
asked 1 month ago