How do i append rows to an existing dataframe in r without creating a new dataframe and trying to merge data from new to the old one everytime.
what is the specific problem you are trying to solve?
can you provide a reproducible example (reprex)
I'm confused about you wanting to append (but not wanting to 'try and merge' )
When you consider this simple example , do you see problems or undesirable aspects to it ?
library(tidyverse)
(original_df <- slice(mtcars,1:3))
(new_df_to_add <- slice(mtcars,4:5))
(original_df <- union_all(original_df,new_df_to_add))
Hi ritm, I am confused by what problem you try to solve. Is it appending rows to an existing dataframe or reading new data from a existing csv? Why is merging a problem?
Anyways,
For appending rows you could try rbind()
or dplyr::bind_rows()
or the solution from nigrrahamuk.
For reading new data from csv you could try read.csv
and use the skip
parameter to skip over the old data rows. The old data rows are calculated by counting the rows in the old dataframe nrow(my_dataframe)
.
BR.
union_all works on only two dataframes.It doesnt work if i tried to add a third dataframe.How do i do it if i have to merge rows from more than two dataframes into a single dataframe.
bind_rows then. you can list as many data.frames as you like
This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.