I have a dataset df1
like so:
snp <- c("rs7513574_T", "rs1627238_A", "rs1171278_C")
p.value <- c(2.635489e-01, 9.836280e-01 , 6.315047e-01 )
df1 <- data.frame(snp, p.value)
I want to remove the _
underscore and the letters after it (representing allele) in df1 and make this into a new dataframe df2
I tried this using the code
df2 <- df1[,c("snp", "allele"):=tstrsplit(`snp`, "_", fixed = TRUE)]
However, this changes the df1
data frame. Is there another way to do this?