rbind

rbind data.frames in a list in R

风格不统一 提交于 2021-02-19 09:30:30
问题 Suppose we have 3 list s of data.frame s. In BASE R, I was wondering how I could automatically (ex. in a looping structure) rbind the data.frame s within these 3 lists? Please note I want the looping structure so it can rbind any more number of similar lists (ex. g4 g5 ...) g1 <- list(b1 = list(data.frame(a = 1:3, b = 3:5))) g2 <- list(b1 = list(data.frame(a = 1:3, b = 3:5))) g3 <- list(b1 = list(data.frame(a = 1:3, b = 3:5))) 回答1: Here is an option with base R do.call(rbind, lapply(mget(ls

rbind data.frames in a list in R

孤人 提交于 2021-02-19 09:25:12
问题 Suppose we have 3 list s of data.frame s. In BASE R, I was wondering how I could automatically (ex. in a looping structure) rbind the data.frame s within these 3 lists? Please note I want the looping structure so it can rbind any more number of similar lists (ex. g4 g5 ...) g1 <- list(b1 = list(data.frame(a = 1:3, b = 3:5))) g2 <- list(b1 = list(data.frame(a = 1:3, b = 3:5))) g3 <- list(b1 = list(data.frame(a = 1:3, b = 3:5))) 回答1: Here is an option with base R do.call(rbind, lapply(mget(ls

Combine data frames from a vector of names

独自空忆成欢 提交于 2021-02-16 21:27:18
问题 I have an issue that I thought easy to solve, but I did not manage to find a solution. I have a large number of data frames that I want to bind by rows. To avoid listing the names of all data frames, I used "paste0" to quickly create a vector of names of the data frames. The problem is that I do not manage to make the rbind function identify the data frames from this vector of name. More explicitely: df1 <- data.frame(x1 = sample(1:5,5), x2 = sample(1:5,5)) df2 <- data.frame(x1 = sample(1:5,5

Rbind list of vectors with differing lengths

邮差的信 提交于 2021-02-05 08:44:50
问题 I am new to R and I am trying to build a frequency/severity simulation. Everything is working fine except that it takes about 10min to do 10000 simulations for each of 700 locations. For the simulation of one individual location, I got a list of vectors with varying lengths and I would like to efficiently rbind these vectors, filling in NAs for all non-existing values. I would like R to return a data.frame to me. So far, I used rbind.fill.matrix after converting the vectors in the list to

Rbind list of vectors with differing lengths

怎甘沉沦 提交于 2021-02-05 08:44:26
问题 I am new to R and I am trying to build a frequency/severity simulation. Everything is working fine except that it takes about 10min to do 10000 simulations for each of 700 locations. For the simulation of one individual location, I got a list of vectors with varying lengths and I would like to efficiently rbind these vectors, filling in NAs for all non-existing values. I would like R to return a data.frame to me. So far, I used rbind.fill.matrix after converting the vectors in the list to

How to reproduce all column names when producing a table to cross reference column names and datatypes from multiple dbfs in R

这一生的挚爱 提交于 2021-01-29 19:39:12
问题 This is a follow up question to Implementing lists in a for loop in R to produce a table of column names and datatypes from multiple dbfs. I’m trying to extract the column names and associated datatypes from a number of dbfs and put the results into a table to cross reference which column names and datatypes appear in which dbfs. The dbfs have different numbers of columns so I’ve used rbind and lapply to fill missing values with NULL in the resulting table. Although the script I have works to

Rbind with XTS. How to stack without sorting by index date

北战南征 提交于 2021-01-04 02:41:41
问题 I am using quantmod which generates XTS objects with ticker info, and I am looking to compile/stack a bunch of XTS documents on top of each other to process code. Using Rbind with XTS I find that it does not stack XTS on top of each other, rather it merges and sorts by date: x <- xts(1:10, Sys.Date()+1:10) x [,1] 2014-07-10 1 2014-07-11 2 2014-07-12 3 2014-07-13 4 2014-07-14 5 2014-07-15 6 2014-07-16 7 2014-07-17 8 2014-07-18 9 2014-07-19 10 y <- xts(rep(2,3), Sys.Date()+c(1,2,3)) y [,1] 2014

Rbind with XTS. How to stack without sorting by index date

痴心易碎 提交于 2021-01-04 02:40:53
问题 I am using quantmod which generates XTS objects with ticker info, and I am looking to compile/stack a bunch of XTS documents on top of each other to process code. Using Rbind with XTS I find that it does not stack XTS on top of each other, rather it merges and sorts by date: x <- xts(1:10, Sys.Date()+1:10) x [,1] 2014-07-10 1 2014-07-11 2 2014-07-12 3 2014-07-13 4 2014-07-14 5 2014-07-15 6 2014-07-16 7 2014-07-17 8 2014-07-18 9 2014-07-19 10 y <- xts(rep(2,3), Sys.Date()+c(1,2,3)) y [,1] 2014

R: Error in pi[[j]] : subscript out of bounds — rbind on a list of dataframes

前提是你 提交于 2021-01-02 07:57:32
问题 I am trying to rbind a large list of data frames (outputDfList), which is generated by lapply a complicated function to a large table. You can recreate outputDfList by: df1=data.frame("randomseq_chr15q22.1_translocationOrInsertion", "chr15", "63126742") names(df1)=NULL df2=df1=data.frame("chr18q12.1_chr18q21.33_large_insertion", "chr18 ", "63126741") names(df2)=NULL outputDfList=list(df1,df2) my code is do.call(rbind, outputDfList) The error message I received: Error in pi[[j]] : subscript

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

坚强是说给别人听的谎言 提交于 2020-12-29 12:13:19
问题 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