Skip to content

Instantly share code, notes, and snippets.

@f0nzie
Created February 3, 2019 04:33
Show Gist options
  • Save f0nzie/a7f8b0a6b0b1a507beba6a339a06d65d to your computer and use it in GitHub Desktop.
Save f0nzie/a7f8b0a6b0b1a507beba6a339a06d65d to your computer and use it in GitHub Desktop.
Make a table from text (tsv) using data.table
title output
R Notebook
html_notebook
write.table(read.table(text = "
 CHR_A     BP_A          SNP_A  CHR_B         BP_B          SNP_B           R2 
 1    154834183      rs1218582      1    154794318      rs9970364    0.0929391 
 1    154834183      rs1218582      1    154795033     rs56744813      0.10075 
 1    154834183      rs1218582      1    154797272     rs16836414     0.106455 
 1    154834183      rs1218582      1    154798550    rs200576863    0.0916789 
 1    154834183      rs1218582      1    154802379     rs11264270     0.176911 ", 
 sep="x"),
          "Type1.txt", col.names=FALSE, row.names=FALSE, quote=FALSE)  
require(data.table) # v1.9.5+
ans <- fread("Type1.txt")
ans
write.table(read.table(text="
CHR_A BP_A SNP_A CHR_B BP_B SNP_B R2
1 154834183 rs1218582 1 154794318 rs9970364 0.0929391
1 154834183 rs1218582 1 154795033 rs56744813 0.10075
1 154834183 rs1218582 1 154797272 rs16836414 0.106455
1 154834183 rs1218582 1 154798550 rs200576863 0.0916789
1 154834183 rs1218582 1 154802379 rs11264270 0.176911", sep=" "),
            "Type2.txt", col.names=FALSE, row.names=FALSE, quote=FALSE, sep="\t")
require(data.table) # v1.9.5+
ans <- fread("Type2.txt")
ans
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment