rbind

Mass rbind.fill for many data frames

怎甘沉沦 提交于 2019-12-18 07:18:01
问题 I am attempting to row bind many data frames together into a single massive data frame. The data frames are named sequentially with the first named df1 , the second named df2 , the third named df3 , etc. Currently, I have bound these data frames together by explicitly typing the names of the data frames; however, for a very large number of data frames (roughly 10,000 total data frames are expected) this is suboptimal. Here is a working example: # Load required packages library(plyr) #

How to rbind all the data.frames in your working environment?

被刻印的时光 ゝ 提交于 2019-12-18 05:48:05
问题 I have over 50 data.frames in my working environment that I would like to rbind . Is there a way to rbind the data.frames with out having to type out each date.frame ? Example of what I have been doing: df <- rbind(A, B, C, D, E, F) I have tried: df <- rbind(ls()) But this just creates a list of names of all the data.frames in my working environment. 回答1: You can search for objects of data.frame class, and use function mget to retrieve them. a = b = c = data.frame(x=1:2, y=3, z=1:4) d = "junk

Rbind dataframes using wildcard

情到浓时终转凉″ 提交于 2019-12-18 05:22:07
问题 Suppose I have three dataframes called A1-pre, B3-pos, B4-pre and I want to merge these dataframes. The columns have the same name, so I can use rbind. newdf <- rbind(A1-pre, B3-pos, B4-pre) #this would work However, I do not want to manually input all the names of the dataframes myself, I rather use a wildcard for that, so something like newdf <- rbind(grep(-)) #but this does not work Any idea how I could do that? Or even better, matching any dataframe named "pre" or "pos" and rbind them all

Rbind dataframes using wildcard

女生的网名这么多〃 提交于 2019-12-18 05:22:05
问题 Suppose I have three dataframes called A1-pre, B3-pos, B4-pre and I want to merge these dataframes. The columns have the same name, so I can use rbind. newdf <- rbind(A1-pre, B3-pos, B4-pre) #this would work However, I do not want to manually input all the names of the dataframes myself, I rather use a wildcard for that, so something like newdf <- rbind(grep(-)) #but this does not work Any idea how I could do that? Or even better, matching any dataframe named "pre" or "pos" and rbind them all

Performance of rbind.data.frame

我的梦境 提交于 2019-12-18 02:49:42
问题 I have a list of dataframes for which I am certain that they all contain at least one row (in fact, some contain only one row, and others contain a given number of rows), and that they all have the same columns (names and types). In case it matters, I am also certain that there are no NA's anywhere in the rows. The situation can be simulated like this: #create one row onerowdfr<-do.call(data.frame, c(list(), rnorm(100) , lapply(sample(letters[1:2], 100, replace=TRUE), function(x){factor(x,

Replace rbind in for-loop with lapply? (2nd circle of hell)

有些话、适合烂在心里 提交于 2019-12-17 19:48:13
问题 I am having trouble optimising a piece of R code. The following example code should illustrate my optimisation problem: Some initialisations and a function definition: a <- c(10,20,30,40,50,60,70,80) b <- c(“a”,”b”,”c”,”d”,”z”,”g”,”h”,”r”) c <- c(1,2,3,4,5,6,7,8) myframe <- data.frame(a,b,c) values <- vector(length=columns) solution <- matrix(nrow=nrow(myframe),ncol=columns+3) myfunction <- function(frame,columns){ athing = 0 if(columns == 5){ athing = 100 } else{ athing = 1000 } value[colums

Merging df.1, df.2, df.3 … df.x into one dataframe

ⅰ亾dé卋堺 提交于 2019-12-17 16:54:24
问题 I am working on a project that imports all csv files from a given folder and merges them into one file. I was able to import the rows and columns I wanted from each of the files from the folder but now need help merging them all into one file. I do not know how many files I will eventually end up with (probably around 120) so I do not want to merge them 1 by 1. Here is what I have so far: # Import All files rowsToUse <- c(9:104,657:752) colsToUse <- c(15,27,28,29,30,33,35) filenames <- list

How can I prevent rbind() from geting really slow as dataframe grows larger?

你说的曾经没有我的故事 提交于 2019-12-17 09:52:41
问题 I have a dataframe with only 1 row. To this I start to add rows by using rbind df #mydataframe with only one row for (i in 1:20000) { df<- rbind(df, newrow) } this gets very slow as i grows. Why is that? and how can I make this type of code faster? 回答1: You are in the 2nd circle of hell, namely failing to pre-allocate data structures. Growing objects in this fashion is a Very Very Bad Thing in R. Either pre-allocate and insert: df <- data.frame(x = rep(NA,20000),y = rep(NA,20000)) or

Efficient way to rbind data.frames with different columns

孤街醉人 提交于 2019-12-17 02:16:17
问题 I have a list of data frames with different sets of columns. I would like to combine them by rows into one data frame. I use plyr::rbind.fill to do that. I am looking for something that would do this more efficiently, but is similar to the answer given here require(plyr) set.seed(45) sample.fun <- function() { nam <- sample(LETTERS, sample(5:15)) val <- data.frame(matrix(sample(letters, length(nam)*10,replace=TRUE),nrow=10)) setNames(val, nam) } ll <- replicate(1e4, sample.fun()) rbind.fill

Why is rbindlist “better” than rbind?

点点圈 提交于 2019-12-17 02:03:27
问题 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 rbindlist really excels over rbind ? Is there any advantage in terms of memory utilization? 回答1: rbindlist is an optimized version of do.call(rbind, list(...)) , which is known for being slow when using rbind.data.frame Where does it really excel Some