1

I want to import the .csv file into a data frame.

I already tried to import but the whole file data come under only one column.


    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
M--
  • 25,431
  • 8
  • 61
  • 93
Adarsh Pawar
  • 682
  • 6
  • 15
  • Well I cannot reproduce your error, but you can split that one column to multiples using this syntax: `db <- as.data.frame(do.call(rbind, strsplit(as.character(db$V1),',')))` – M-- Jul 13 '19 at 21:14
  • 1
    Can you show the first few lines of the CSV? Maybe it has quotes at the start and end of each line? Or maybe something else is weird with it? – Gregor Thomas Jul 13 '19 at 21:23
  • @Gregor - I had the same idea but just tested with test data when you posted. – help-info.de Jul 13 '19 at 21:43
  • 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 P,ICICIBANK,1100,100,20121210,120,20121209103030,1237,1234 P,AXISBANK,1000,100,20121210,120,20121209103031,1238,1235 T,ICICIBANK,1000,100,20121210,120,20121209103035,1239,0 T,.CITIBANK,1000,101,20121210,120,20121209103036,1240,0 P,ICICIBANK,1100,100,20121210,120,20121209103030,1241,1234 P,ICICIBANK,1100,100,20121210,120,20121209103035,1242,1239 – Adarsh Pawar Jul 14 '19 at 04:09
  • Please avoid writing input data in comments. It is better to edit the question and insert the input data there. FYI - please read [How to make a great R reproducible example?](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example/5963610#5963610). – help-info.de Jul 14 '19 at 08:16

1 Answers1

-1

Import with CSV data file shown below causes the error. As you can see, this is the problem. In a first attempt without quotes I could not reproduce the error.

Please clean up your input data and delete the quotes to solve the problem.

Data for error test case only:

"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
help-info.de
  • 6,695
  • 16
  • 39
  • 41