Questions tagged [rbindlist]

22 questions
140
votes
2 answers

Why is rbindlist "better" than rbind?

I am going through documentation of data.table and also noticed from some of the conversations over here on SO that rbindlist is supposed to be better than rbind. I would like to know why is rbindlist better than rbind and in which scenarios…
CHP
  • 16,149
  • 4
  • 33
  • 56
6
votes
3 answers

Make rbindlist skip, ignore or change class attribute of the column

I would like to merge a large set of dataframes (about 30), which each have about 200 variables. These datasets are very much alike but not identical. Please find two example dataframes below: library(data.table) library(haven) df1 <- fread( "A …
Tom
  • 1,237
  • 8
  • 29
3
votes
1 answer

Error encountered with using rbindlist: column 25 of result is determined to be integer64 but maxType == 'Character' !=REALSXP

I used the following function to merge all .csv files in my directory into one dataframe: multmerge = function(mypath){ filenames = list.files(path = mypath, full.names = TRUE) rbindlist(lapply(filenames,fread),fill = TRUE) } dataframe =…
Audrey Liu
  • 35
  • 4
3
votes
1 answer

Import text file separated by new line

Ultimately, I need to create the following table: ID Age Gender 1 25 F 2 14 M and so on. . . I got my data in many txt files, where the ID is the name of the file. Age and Gender are separated by new line, for example: Age: 25 Gender: F Now,…
mRiddle
  • 214
  • 1
  • 7
  • 16
2
votes
2 answers

Expand multiple columns of data.table containing observations

I have a data.table where more than 2 columns are of the type list. I would like to expand these columns, so that each element of the list becomes a new column. I would like to have a more elegant way than to "manually" expand each column and then…
ira
  • 1,956
  • 1
  • 14
  • 27
2
votes
4 answers

rbindlist a list column of data.frames and select unique values

I have a data.table 'DT' with a column ('col2') that is a list of data frames: require(data.table) DT <- data.table(col1 = c('A','A','B'), col2 = list(data.frame(colA = c(1,3,54, 23), colB =…
Ankhnesmerira
  • 1,068
  • 8
  • 19
1
vote
2 answers

How to rbind reshaped data tables of different column sizes and with different names

I checked similar entries in SO, none answers my question exactly. My problem is this: Let's say, User1 has 6 purchases, User2 has 2. Purchase data is something like this: set.seed(1234) purchase <- data.frame(id = c(rep("User1", 6), rep("User2",…
maop
  • 158
  • 12
1
vote
3 answers

rbindlist only elements that meet a condition

I have a large list. Some of the elements are strings and some of the elements are data.tables. I would like to create a big data.table, but only rbind the elements that are data.tables. I know how to do it in a for loop, but I am looking for…
Maja
  • 81
  • 7
1
vote
1 answer

rbindlist - how to get an additional column with info about a source?

I have more than 30 large .csv files stored in one folder. I would like to read them in R as one data.frame/data/table with the following criteria: (1) first and last 25 rows of each file should be skipped (number of rows differs in each file) (2)…
barbrka
  • 123
  • 9
0
votes
1 answer

How to define the first column before import and bind ( rbindlist ) in R

Goal import and bind a list of xlsx file with unpredicted irrelevant first column. (Have to eliminate it but you don't know which file contains irrelevant first column.) # sample : remind that the xlsx file originally don't have any column…
rane
  • 769
  • 1
  • 7
  • 19
0
votes
0 answers

Read files in a loop using part of their name to create a new variable in large combined data frame using fread(cmd=...) and rbindlist

I am trying to read multiple files from a folder and combine them into one large data frame. I would like the new data frame to have a column that identifies from which file it comes, in my case, the year which is part of the file name.…
Lil
  • 23
  • 6
0
votes
0 answers

Using the error message to determine the course of action

I have posted a question pertaining to the code: df_merged <- rbindlist(list(df1, df2), fill=TRUE, use.names=TRUE) Which resulted for me resulted in the following error message: Error in rbindlist(list(df1, df2), fill = TRUE, use.names = TRUE) : …
Tom
  • 1,237
  • 8
  • 29
0
votes
1 answer

decimal separator in multiple .txt importing

I need to import a multiple .txt files with "." decimal separators in some columns when i import the data, the numeric variables columns (with decimals like: 16,500.56) are loaded like character variables, using the next…
Rantulucci
  • 29
  • 5
0
votes
0 answers

Using parLapply with data.table's rbindlist causes CPU to go over 100%

Consider the following code block: library(data.table) library(parallel) random_function<-function(i){ n<-1000000 big_list<-list("vector") for (k in 1:100){ big_list[[k]]<-data.table(rnorm(n),rnorm(n)) } rbindlist(big_list,use.names =…
Vitalijs
  • 762
  • 5
  • 16
0
votes
2 answers

Binding dataframes in list after data cleaning on list

This is a follow up on my last question (Rbinding large list of dataframes after I did some data cleaning on the list). I've gotten smarter and the former question got messy. I have 43 xlsx files which I loaded in to a list in R: file.list <-…
1
2