I am trying to load a csv file that has 14 columns like this:
StartDate, var1, var2, var3, ..., var14
when I issue this command:
systems <- read.table("http://getfile.pl?test.csv", header = TRUE, sep = ",")
I get an error message.
duplicate row.names are not allowed
It seems to me that the first column name is causing the issue. When I manually download the file and remove the StartDate
name from the file, R successfully reads the file and replaces the first column name with X
. Can someone tell me what is going on? The file is a (comma separated) csv file.
The way to fix this error is to simply use row. names=NULL when importing the file: What is this? We are able to successfully import the CSV file, but the column names are off.
Remove Duplicate rows in R using Dplyr – distinct () function. Distinct function in R is used to remove duplicate rows in R using Dplyr package. Dplyr package in R is provided with distinct() function which eliminate duplicates rows with single variable or with multiple variable.
Duplicate Rows – Copy and Paste Say you have the following data set and want to copy Row 7 to Row 8. 1. Select the row you want to copy by clicking on a row number (here, Row 7), then right-click anywhere in the selected area and choose Copy (or use the keyboard shortcut CTRL + C).
Method 1 : using rownames() A data frame's rows can be accessed using rownames() method in the R programming language. We can specify the new row names using a vector of numerical or strings and assign it back to the rownames() method.
Then tell read.table not to use row.names
:
systems <- read.table("http://getfile.pl?test.csv", header=TRUE, sep=",", row.names=NULL)
and now your rows will simply be numbered.
Also look at read.csv
which is a wrapper for read.table
which already sets the sep=','
and header=TRUE
arguments so that your call simplifies to
systems <- read.csv("http://getfile.pl?test.csv", row.names=NULL)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With