R 合并文本文件并创建具有文件名的新列
我正在尝试获取文本文件列表(扩展名为.annotation,但仍然是文本文件),并将它们合并到一个文件中。我还想用原始文件名创建一个新列,以便以后可以按文件名对表进行排序 我有一个文件列表,看起来像这样-R 合并文本文件并创建具有文件名的新列,r,parsing,R,Parsing,我正在尝试获取文本文件列表(扩展名为.annotation,但仍然是文本文件),并将它们合并到一个文件中。我还想用原始文件名创建一个新列,以便以后可以按文件名对表进行排序 我有一个文件列表,看起来像这样- > read.table("Sample2-1_nucleotideRate.annotation") V1 V2 V3 V4 V5 V6 V7 V8 V9 V10 1 p
> read.table("Sample2-1_nucleotideRate.annotation")
V1 V2 V3 V4 V5 V6 V7 V8 V9 V10
1 pJW316-17_beforeNGS non-coding 29 29 G A 0.9657791941 NA NA <NA>
2 pJW316-17_beforeNGS non-coding 54 299 A G 0.0064375000 NA NA <NA>
3 pJW316-17_beforeNGS non-coding 64 349 T C 0.0111019737 NA NA <NA>
4 pJW316-17_beforeNGS nsps 85 644 A G 0.0044375000 9 3 synonymous>K
> read.csv("all_data.csv", header = T)
X samplename X.region feature position coverage reference alternate alt_frequency CDS_position AA_position AA_change
1 1 Sample2-1 pJW316-17_beforeNGS non-coding 29 29 G A 0.965779194 NA NA <NA>
2 2 Sample2-1 pJW316-17_beforeNGS non-coding 54 299 A G 0.006437500 NA NA <NA>
3 3 Sample2-1 pJW316-17_beforeNGS non-coding 64 349 T C 0.011101974 NA NA <NA>
4 4 Sample2-1 pJW316-17_beforeNGS nsps 85 644 A G 0.004437500 9 3 synonymous>K
5 5 Sample2-1 pJW316-17_beforeNGS nsps 96 808 A G 0.003437500 20 7 D
>读取表格(“样本2-1\u核苷酸盐注释”)
V1 V2 V3 V4 V5 V6 V7 V8 V9 V10
1 pJW316-17非编码前29 G A 0.9657791941 NA
2 pJW316-17非编码前54 299 A G 0.0064375000 NA
3 pJW316-17非编码前64 349 T C 0.0111019737 NA
4 pJW316-17在nsps 85 644 A G 0.0044375000 9 3同义>K之前
我想要一个像这样的新文件-
> read.table("Sample2-1_nucleotideRate.annotation")
V1 V2 V3 V4 V5 V6 V7 V8 V9 V10
1 pJW316-17_beforeNGS non-coding 29 29 G A 0.9657791941 NA NA <NA>
2 pJW316-17_beforeNGS non-coding 54 299 A G 0.0064375000 NA NA <NA>
3 pJW316-17_beforeNGS non-coding 64 349 T C 0.0111019737 NA NA <NA>
4 pJW316-17_beforeNGS nsps 85 644 A G 0.0044375000 9 3 synonymous>K
> read.csv("all_data.csv", header = T)
X samplename X.region feature position coverage reference alternate alt_frequency CDS_position AA_position AA_change
1 1 Sample2-1 pJW316-17_beforeNGS non-coding 29 29 G A 0.965779194 NA NA <NA>
2 2 Sample2-1 pJW316-17_beforeNGS non-coding 54 299 A G 0.006437500 NA NA <NA>
3 3 Sample2-1 pJW316-17_beforeNGS non-coding 64 349 T C 0.011101974 NA NA <NA>
4 4 Sample2-1 pJW316-17_beforeNGS nsps 85 644 A G 0.004437500 9 3 synonymous>K
5 5 Sample2-1 pJW316-17_beforeNGS nsps 96 808 A G 0.003437500 20 7 D
>read.csv(“all_data.csv”,header=T)
X samplename X.区域特征位置覆盖率参考备用alt_频率CD_位置AA_位置AA_变化
1样本2-1 pJW316-17_非编码前29 29 G A 0.965779194 NA
2样本2-1 pJW316-17_在非编码54 299 A G 0.006437500 NA之前
3样本2-1 pJW316-17非编码前64 349 T C 0.0111011974 NA
4 nsps 85 644 A G 0.004437500之前的样本2-1 pJW316-17 3同义>K
5 nsps 96 808 A G 0.003437500 20 7 D之前的样本2-1 pJW316-17
提供一些关于其他文件的信息?samplename、X.region等colname是从哪里来的。答案解决了您的问题。@AnkurSingh出于某种原因,read.table的输出将标题转换为V1 V2。。。V10。我不知道为什么。输出具有正确的标题。