79179693

Date: 2024-11-12 03:25:42
Score: 0.5
Natty:
Report link

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
  )

enter image description here

Reasons:
  • Probably link only (1):
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Low reputation (0.5):
Posted by: Eonema