[英]How to determine the type of delim used in a txt file?
Here is my sample data: https://github.com/Patricklv/Txt-file这是我的示例数据: https ://github.com/Patricklv/Txt-file
I tried to load the data using the following code:我尝试使用以下代码加载数据:
library(tidyverse)
data <- read_delim("<PATH>\\pgc.cross.SCZ17.2013-05.txt", delim = " ")
head(data)
This returns the following results:这将返回以下结果:
# A tibble: 6 × 12
snpid hg18chr bp a1 a2 or se pval info ngt CEUaf
<chr> <lgl> <lgl> <lgl> <lgl> <lgl> <lgl> <lgl> <lgl> <lgl> <lgl>
1 "rs3131… NA NA NA NA NA NA NA NA NA NA
2 "rs3131… NA NA NA NA NA NA NA NA NA NA
3 "rs3131… NA NA NA NA NA NA NA NA NA NA
4 "rs1048… NA NA NA NA NA NA NA NA NA NA
5 "rs1256… NA NA NA NA NA NA NA NA NA NA
6 "rs4040… NA NA NA NA NA NA NA NA NA NA
# … with 1 more variable: ...12 <lgl>
# ℹ Use `colnames()` to see all variable names
I also tried:我也试过:
data <- read_delim("<PATH>\\pgc.cross.SCZ17.2013-05.txt", delim = "\t")
head(data)
This returns:这将返回:
# A tibble: 6 × 1
`snpid hg18chr bp a1 a2 or se pval info ngt CEUaf `
<chr>
1 "rs3131972\t1\t742584\tA\tG\t1\t0.0966\t0.9991\t0.702\t0\t0.16055"
2 "rs3131969\t1\t744045\tA\tG\t1\t0.0925\t0.9974\t0.938\t0\t0.133028"
3 "rs3131967\t1\t744197\tT\tC\t1.001\t0.0991\t0.9928\t0.866\t0\t."
4 "rs1048488\t1\t750775\tT\tC\t0.9999\t0.0966\t0.9991\t0.702\t0\t0.8364…
5 "rs12562034\t1\t758311\tA\tG\t1.025\t0.0843\t0.7716\t0.988\t0\t0.0925…
6 "rs4040617\t1\t769185\tA\tG\t0.9993\t0.092\t0.994\t0.979\t0\t0.87156"
However, when I open the file using Sublime Text, here is what I see:但是,当我使用 Sublime Text 打开文件时,我看到的是:
I want to know how should I import this txt file so that it will appear as it shows in Sublime Text我想知道我应该如何导入这个 txt 文件,以便它显示在 Sublime Text 中
Try read.table
.尝试read.table
。 No packages are used.没有使用包。
u <- "https://raw.githubusercontent.com/Patricklv/Txt-file/main/pgc.cross.SCZ17.2013-05.txt"
dat <- read.table(u, header = TRUE, na.strings = ".")
str(dat)
giving给予
'data.frame': 12 obs. of 11 variables:
$ snpid : chr "rs3131972" "rs3131969" "rs3131967" "rs1048488" ...
$ hg18chr: int 1 1 1 1 1 1 1 1 1 1 ...
$ bp : int 742584 744045 744197 750775 758311 769185 828418 836671 843817 844113 ...
$ a1 : chr "A" "A" "T" "T" ...
$ a2 : chr "G" "G" "C" "C" ...
$ or : num 1 1 1 1 1.02 ...
$ se : num 0.0966 0.0925 0.0991 0.0966 0.0843 ...
$ pval : num 0.999 0.997 0.993 0.999 0.772 ...
$ info : num 0.702 0.938 0.866 0.702 0.988 0.979 0.439 1.02 0.383 0.251 ...
$ ngt : int 0 0 0 0 0 0 0 0 0 0 ...
$ CEUaf : num 0.1605 0.133 NA 0.8364 0.0926 ...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.