Combining data.frames in R based off a character list

I have multiple data.frames that I want to rbind together using R. I also have a character vector with the names of each of these data.frames. What I’m looking to do is use this character vector to determine which data.frames to bind together. For example, I have 5 similar data.frames below and I want to… Read More Combining data.frames in R based off a character list

R merge two dataframes by rows with some similar but also different columns

aa <- data.frame(a= c(1,1,2,3,4), b = c(5,3,2,6,1)) bb <- data.frame(a= c(1,1,6,7,4), c = c(4,3,7,2,1)) I want to merge aa and bb by the rows, however, when I use the rbind() function, it gives me an error that "the numbers of columns of arguments do not match". The final format that I want keeps all the… Read More R merge two dataframes by rows with some similar but also different columns

One-liner to concatenate two data frames with a distinguishing column?

I often find myself creating two similar data frames that I’d like to rbind together but keep track of which one each row came from with a distinguishing column. My typical motif has been new_df <- rbind( cbind(df1, id="A"), cbind(df2, id="B") ) which collapses nicely into a single line for readability but feels clunky and… Read More One-liner to concatenate two data frames with a distinguishing column?

How to insert rows in specific indices of dataframe containing sum of few rows above only in R pipe dplyr

for dataframe below, df <- data.frame(id = c(rep(101, 4), rep(202, 3)), status = c("a","b","c","d", "a", "b", "c"), wt = c(100,200,100,105, 20,22,25), ht = c(5.3,5.2,5,5.1, 4.3,4.2,4.1)) df id status wt ht 1 101 a 100 5.3 2 101 b 200 5.2 3 101 c 100 5.0 4 101 d 105 5.1 5 202 a 20 4.3… Read More How to insert rows in specific indices of dataframe containing sum of few rows above only in R pipe dplyr