读取具有不同列数的txt文件 [英] read txt file with different number of columns
本文介绍了读取具有不同列数的txt文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在R中读取许多具有不同列数的txt文件? 例如 我有以下数据:
How can I read in R, numerous txt files with different number of columns? e.g I have the following data:
6 4 2
5 5 3
3 3 4 5 6
4 5 6 7 8
6 3 2 5 8 4 3
1 4 5 0 5 4 8
谢谢
推荐答案
如何?
df <- read.table(file="test.txt", fill=T)
输出为:
V1 V2 V3 V4 V5 V6 V7
1 6 4 2 NA NA NA NA
2 5 5 3 NA NA NA NA
3 3 3 4 5 6 NA NA
4 4 5 6 7 8 NA NA
5 6 3 2 5 8 4 3
6 1 4 5 0 5 4 8
样本数据:
6 4 2
5 5 3
3 3 4 5 6
4 5 6 7 8
6 3 2 5 8 4 3
1 4 5 0 5 4 8
在test.txt
这篇关于读取具有不同列数的txt文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文