I have a tibble with very many columns. I need to add a row to it at a specific location (e.g. before row 2). How can I do this without typing column names before the values?
E.g. this is what I must do (imagine more columns, V1, V2, V3, ...):
library(tidyverse)
tbl1 = tibble(V1=c(1,2), V2=c(3,4))
tbl1 %>% add_row(V1=1.5, V2=2.5, .before = 2)
This is what I wish I could do (returns error, since column names not specified):
library(tidyverse)
tbl1 = tibble(V1=c(1,2), V2=c(3,4))
tbl1 %>% add_row(c(1.5,3.5), .before = 2)
I can create another tibble based on the first one and append it to the old one using bind_rows
, but that adds it at the end, i.e. I can't specify the location before row 2:
library(tidyverse)
tbl1 = tibble(V1=c(1,2), V2=c(3,4))
tbl2 = tbl1 %>% summarise_all(mean)
bind_rows(tbl1, tbl2)
(The goal is to interpolate between the two values in tbl1.) Method must be efficient, i.e. can't copy tbl1.