Simplest way to get rbind to ignore column names

You might find setNames handy here… rbind(df, setNames(rev(df), names(df))) # x y #1 1 3 #2 2 4 #3 3 1 #4 4 2 I suspect your real use-case is somewhat more complex. You can of course reorder columns in the first argument of setNames as you wish, just use names(df) in the second argument, … Read more

rbind dataframes with a different column name

My favourite use of mapply: Example Data a <- data.frame(a=runif(5), b=runif(5)) > a a b 1 0.8403348 0.1579255 2 0.4759767 0.8182902 3 0.8091875 0.1080651 4 0.9846333 0.7035959 5 0.2153991 0.8744136 and b b <- data.frame(c=runif(5), d=runif(5)) > b c d 1 0.7604137 0.9753853 2 0.7553924 0.1210260 3 0.7315970 0.6196829 4 0.5619395 0.1120331 5 0.5711995 0.7252631 … Read more

What’s wrong with my function to load multiple .csv files into single dataframe in R using rbind?

There’s a lot of unnecessary code in your function. You can simplify it to: load_data <- function(path) { files <- dir(path, pattern = ‘\\.csv’, full.names = TRUE) tables <- lapply(files, read.csv) do.call(rbind, tables) } pollutantmean <- load_data(“specdata”) Be aware that do.call + rbind is relatively slow. You might find dplyr::bind_rows or data.table::rbindlist to be substantially … Read more

Why is rbindlist “better” than rbind?

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 questions that show where rbindlist shines are Fast vectorized merge of list of data.frames by row Trouble converting long list of data.frames (~1 million) to single data.frame using do.call and ldply These … Read more