Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to avoid extra column when writing a csv file?

# saving the work as ... data_full.csv
write.csv(data.full, "data_full.csv", col.names = TRUE)

#importing file
data.dir <- file.choose()
data <- read.csv(data.dir, header = TRUE)

data.full was written as

enter image description here

but data got read as

enter image description here

Can anyone suggest me a solution, on how to solve this simple problem?

like image 880
theBotelho Avatar asked Aug 18 '17 11:08

theBotelho


People also ask

Why does my CSV file have extra commas?

Saving an Excel file as a CSV file can create extra commas at the end of each row. Trailing commas can result when columns are deleted or column headers removed. When the file is uploaded to Clever, an extra trailing comma will skew subsequent rows of data, preventing them from being processed.

How do I avoid commas in a CSV file?

Re: Handling 'comma' in the data while writing to a CSV. So for data fields that contain a comma, you should just be able to wrap them in a double quote. Fields containing line breaks (CRLF), double quotes, and commas should be enclosed in double-quotes.

Do CSV files have column limits?

Cell Character Limits csv files have a limit of 32,767 characters per cell. Excel has a limit of 1,048,576 rows and 16,384 columns per sheet. CSV files can hold many more rows.

Can you hide columns in CSV?

You can't hide a column, but you can adjust a column size so one column has only 1 character width. You might want to clear the Adjust Separator Positions Automatically check box in the CSV page of the Customize dialog box if you have not done already.


Video Answer


1 Answers

In your write.csv statement use the option row.names=FALSE to suppress the first column - it is on by default.

like image 94
Andrew Gustar Avatar answered Sep 23 '22 04:09

Andrew Gustar