Problem while reading csv file

I have a csv file which I want to copy to dataframe.
The csv file dose not have any unique identifier. But, it do have a unique column names.

The code, I'm using right now is,

inFile <- input$target_upload # loads the csv file details into inFile
dataframe <-
read.csv2(
inFile$datapath,
header = input$header,
sep = input$separator,
as.is = TRUE,
check.names = FALSE
)

In the above code, if I use,
row.names = NULL, the column data is shifting towards left .. For eg., Column1 data is shifting to row.names and so on, which leads to last column as empty.
row.names = 1, 'I'm getthing duplicate row.names error' (I do agree for this error, because, !st column has duplicate data...in fact all the columns have duplicate data)

I just want to copy data from CSV to dataframe as is. How can acheive it?

My CSV is in the following format :
COL1; COL2; COL3; COL4
abc;1234;test; test1
cde;1234;test2;test3
abc;5678;test;test1

Let's assume a .csv file, cat.csv that looks like this:

cat; dog; moose
1,4; 2,5; 7,5
3,7; 5,8; 11,9

Try this:

dat1 <- read.csv2("cat.csv", sep = ";")

Hi,

It does not work in my case. In your Eg., you have unique data in the cat column.
But, In my csv, I don't have any unique identifiers

My CSV is in the following format :
COL1; COL2; COL3; COL4
abc;1234;test; test1
cde;1234;test2;test3
abc;5678;test;test1

in what way does it not work ?
Its not clear what uniqueness has to do with the aspect of simply transferring text data from disk and representing it as R data in memory, which seems to be the entirety of your question as posed.

When I do so, I got below error:

'Warning: Error in read.table: duplicate 'row.names' are not allowed'

Well, see, this must be because you are using a header with one less column than in your data (and you havent shared such an example header to us, or explained the logic behind that).
under those circumstances.

If there is a header and the first row contains one fewer field than the number of columns, the first column in the input is used for the row names

The implication is that rather than having example data that is like

COL1; COL2; COL3; COL4
abc;1234;test; test1
cde;1234;test2;test3
abc;5678;test;test1

its like

COL1; COL2; COL3
abc;1234;test; test1
cde;1234;test2;test3
abc;5678;test;test1

Oh yes, you are correct. When I opened the CSV file in notepad++ , I see all the lines are ended with ';'

Seems like, I can use read_delim() or do you suggest any other way?

I don't know your data, so I dont know how best to manipulate it.

If the data is not confidential, could you post it somewhere that we could download it? as @ nirgrahamuk says, we do not know what your data is .

SO crosspost:

sample.csv
Hi,

Indeed it's an confidential one.
I'm pasting an exmple here. Hope it works.

Thank you !

its not clear what you are demonstrating.
i.e.

  1. a problem that matches the one discussed above, which was that you have a csv with 4 column headings, but only 3 columns of data. I suppose you should ask yourself if you know what each column should be called ?
  2. some new problem, involving 3 columns that you read in, but crossed out the names of, and you havent said what your problem with these 3 columns are ?

This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.