rbind

R: Combine list of data frames into single data frame, add column with list index

怎甘沉沦 提交于 2020-12-29 12:06:20
问题 The question is very similar to this one . It is for combining a list of data frames into a single longer data frame. However, I want to keep the information from which item of the list the data came from by adding an extra column with the index (id or source) of the list. This is the data (borrowing code from the linked example): dfList <- NULL set.seed(1) for (i in 1:3) { dfList[[i]] <- data.frame(a=sample(letters, 5, rep=T), b=rnorm(5), c=rnorm(5)) } Using the code below provides a

combining dataframes using rbind + adding a separate column that includes the names of the individual dataframes [duplicate]

£可爱£侵袭症+ 提交于 2020-12-15 04:19:15
问题 This question already has answers here : Combine a list of data frames into one data frame (9 answers) Closed 3 months ago . Just a question on rbind. When running df_all <- rbind(df_1, df_2 ...) to combine multiple dataframes, I was wondering whether is it possible to add in a separate column that includes the names of the individual dataframes where each observation originates from? Many Thanks, Mervyn 回答1: Try this approach : library(dplyr) new_df <- bind_rows(lst(df_1, df_2), .id = 'id')

combining dataframes using rbind + adding a separate column that includes the names of the individual dataframes [duplicate]

做~自己de王妃 提交于 2020-12-15 04:16:24
问题 This question already has answers here : Combine a list of data frames into one data frame (9 answers) Closed 3 months ago . Just a question on rbind. When running df_all <- rbind(df_1, df_2 ...) to combine multiple dataframes, I was wondering whether is it possible to add in a separate column that includes the names of the individual dataframes where each observation originates from? Many Thanks, Mervyn 回答1: Try this approach : library(dplyr) new_df <- bind_rows(lst(df_1, df_2), .id = 'id')

Merging multiple .xls files in R [duplicate]

北战南征 提交于 2020-12-13 04:14:34
问题 This question already has answers here : How to import multiple .csv files at once? (13 answers) How can I read multiple (excel) files into R? [duplicate] (1 answer) Closed last year . I am trying to merge a list of .xls files in google drive. I have now managed to create a list of all the files I need, but for some reason I still can't manage to merge them, this is the code I have so far: library(googledrive) inputfiles <- drive_ls(path = "Email It In", pattern = "*PDOL_dataexport", n_max =

list data.tables in memory and combine by row (rbind)

老子叫甜甜 提交于 2020-07-30 10:23:29
问题 I have many data.tables in memory with names following a specific pattern (e.g.: RE_1, RE_2... CO_1, CO_2...). I want to bind them efficiently to get only two data.tables (RE and CO). I tried: RE <- rbindlist(ls(pattern = "RE")) But I got the following error: "Error in rbindlist(ls(pattern = "RE")) : Input to rbindlist must be a list of data.tables". Is there a way to make such a "usable" list of data.tables (or data frames)? 回答1: Try rbindlist(lapply(ls(pattern = "RE"),get)) Dont know if

rbind dataframes across nested lists

不羁岁月 提交于 2020-07-18 11:38:29
问题 I've had a look at various rbinding list questions such as this but I can't really find a more efficient way of doing this. I have a nested list nestlist that contains three lists which each contain two dataframes: df1 <- data.frame(ID = paste0(LETTERS[1:4],1:4), valueA = seq(0.1,0.4,0.1), Category= "Apples") df2 <- data.frame(ID = paste0(LETTERS[1:4],1:4), valueB = seq(0.1,0.4,0.1), Category= "Apples") list1 <- list(df1,df2) df3 <- data.frame(ID = paste0(LETTERS[1:4],1:4), valueA = seq(0.1,0

Merge multiple .csv files into one [duplicate]

血红的双手。 提交于 2020-02-20 11:21:48
问题 This question already has answers here : How to import multiple .csv files at once? (12 answers) Closed 2 years ago . I am aware this question has been asked multiple times, but despite of trying to apply the aforementioned solutions i was not able to solve my little problem: I have saved all my .csv that i am aiming to merge into one folder: > file_list <- list.files() > file_list[] [1] "SR-einfam.csv" "SR-garage.csv" "SR-hotel.csv" [4] "SR-IndustrieGewerbe.csv" "SR-mehrfam.csv" "SR-OffG.csv