简体   繁体   English

R中的read.delim()不读取.txt文件,保留变量的原始值

[英]read.delim() in R doesn't read .txt files keeping original values for variables

Hi everybody I am trying to load a .txt file in R and I got some troubles trying to make this. 大家好,我试图在R中加载.txt文件,但在尝试这样做时遇到了一些麻烦。 My original .txt file has the next structure (I can't add dput version because the loading of my file is wrong but I include variables and their values): 我的原始.txt文件具有下一个结构(由于文件加载错误,所以我无法添加dput版本,但我包含变量及其值):

ID  Key.Number

1708888894  4222200000549012
0208823891  0002200000549111
0508823891  1717100000549111
0999923891  1717100000549111
0708888894  0002200000591111

It has the name "Testing.txt" and is formed by 2 variables ID and Key.number . 它的名称为“ Testing.txt”,由2个变量IDKey.number In the .txt file variables are separated by tabulation (tab). 在.txt文件中,变量由制表符(tab)分隔。 For reading my file I used this code: 为了读取我的文件,我使用了以下代码:

test=read.delim("Testing.txt")
test

And I got this: 我得到了:

          ID   Key.Number
1 1708888894 4.222200e+15
2  208823891 2.200001e+12
3  508823891 1.717100e+15
4  999923891 1.717100e+15
5  708888894 2.200001e+12

How you can see for ID column zero was omited and for Key.Number all values are in scientific format. 对于ID列零,您如何看到;对于Key.Number所有值均采用科学格式。 Also I have tried with read.table but due to the nature of source file (Testing is only an example) column names are included in the first row and when I use col.names()=test[1,] I don't get the original names. 我也尝试过使用read.table,但是由于源文件的性质(测试仅是示例),列名包含在第一行中,当我使用col.names()= test [1,]时,我不会获得原始名称。 I got this with read.table() 我用read.table()

          V1               V2
1         ID       Key.Number
2 1708888894 4222200000549012
3 0208823891 0002200000549111
4 0508823891 1717100000549111
5 0999923891 1717100000549111
6 0708888894 0002200000591111

Many thanks for your help and your advice It is important for me. 非常感谢您的帮助和建议对我来说很重要。

DF <- read.table(text="ID  Key.Number

1708888894  4222200000549012
0208823891  0002200000549111
0508823891  1717100000549111
0999923891  1717100000549111
0708888894  0002200000591111", 
colClasses="character", header=TRUE, blank.lines.skip=FALSE)


#           ID       Key.Number
# 1                            
# 2 1708888894 4222200000549012
# 3 0208823891 0002200000549111
# 4 0508823891 1717100000549111
# 5 0999923891 1717100000549111
# 6 0708888894 0002200000591111

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM