First, import your data so that the first row is not headers:
tmp <- tempfile(fileext = ".csv")
write.csv(df, tmp, row.names = FALSE)
# If you already have your data as a CSV or similar, just add header = FALSE
# like this and ignore the above code (that's just for reproducibility)
df1 <- read.csv(tmp, header = FALSE)
Then, use tidyr::fill
to copy down the IDs:
library(dplyr)
library(tidyr)
df2 <- df1 %>%
# this will replace everything that's not an ID with NA
mutate(ID = as.numeric(V4)) %>%
# this is the function that copies down the IDs
fill(ID) %>%
# remove rows with headers
filter(V1 != "REF") %>%
# add column names
rename(
REF = V1,
ALT = V2,
INFO = V3,
VAR = V4
)