如何在R中导入安排的.csv文件

时间:2019-07-13 21:05:36

标签: r

我想将.csv文件导入数据框。

我已经尝试导入,但是整个文件数据仅归于一列。


    db <- read.csv("sample.csv", header = FALSE, sep = ',')

> db
                                                          V1
1    T,ICICIBANK,1000,100,20121210,120,20121209103030,1234,0
2     T,AXISBANK,1000,100,20121210,120,20121209103031,1235,0
3      T,SBIBANK,1000,100,20121210,120,20121209103032,1236,0
4 P,ICICIBANK,1100,100,20121210,120,20121209103030,1237,1234
5  P,AXISBANK,1000,100,20121210,120,20121209103031,1238,1235
6    T,ICICIBANK,1000,100,20121210,120,20121209103035,1239,0
7    T,.CITIBANK,1000,101,20121210,120,20121209103036,1240,0
8 P,ICICIBANK,1100,100,20121210,120,20121209103030,1241,1234
9 P,ICICIBANK,1100,100,20121210,120,20121209103035,1242,1239
> str(db)
'data.frame':   9 obs. of  1 variable:
 $ V1: Factor w/ 9 levels "P,AXISBANK,1000,100,20121210,120,20121209103031,1238,1235",..: 7 6 9 2 1 8 5 3 4

2 个答案:

答案 0 :(得分:0)

数据集中有一个引号,但是当我将文件转换为.txt时,它在.csv中不可见。删除它们后,我将文件转换为.csv。现在一切正常。

GeoQuery geoQuery = geoFirestore.queryAtLocation(new GeoPoint(coordinates[0], coordinates[1]), 0.6);

答案 1 :(得分:-1)

导入如下所示的CSV数据文件会导致错误。如您所见,这就是问题所在。在没有引号的第一次尝试中,我无法重现该错误。

请清理您的输入数据并删除引号以解决问题。

仅用于错误测试案例的数据:

"T,ICICIBANK,1000,100,20121210,120,20121209103030,1234,0"
"T,AXISBANK,1000,100,20121210,120,20121209103031,1235,0"
"T,SBIBANK,1000,100,20121210,120,20121209103032,1236,0"

db <- read.csv("test-case.csv", header = FALSE, sep = ',')
head (db)
                                                          V1
1    T,ICICIBANK,1000,100,20121210,120,20121209103030,1234,0
2     T,AXISBANK,1000,100,20121210,120,20121209103031,1235,0
3      T,SBIBANK,1000,100,20121210,120,20121209103032,1236,0