rowvar import error in R

11,781

Solution 1

The row.names argument should be a vector which has the length of the number of rows. Simply omitting the argument for now would probably fix the issue. The documentation is clear about row.names being a vector, although raising a more informative exception would be nice.

Solution 2

mydata <- read.csv("c:/mydata.csv")

Use the read.csv function instead. It auto popoulates the column headers based on the values in the first row.

Share:
11,781

Related videos on Youtube

KFack
Author by

KFack

Grad student concentrating on AI research.

Updated on August 20, 2022

Comments

  • KFack
    KFack over 1 year

    I am trying to import a .csv file into R with:

    mydata <- read.table("c:/data.csv", header=TRUE, sep=",", row.names="id")
    

    But keep getting:

    Error in data[[rowvar]] : attempt to select less than one element
    

    The .csv file looks like:

    Title1,Title2,Title3
    1,2,3
    4,5,6
    7,8,9
    

    Any help would be much appreciated!

  • bearvarine
    bearvarine almost 10 years
    row.names, if included, needs to be one of the header field names. You put row.names="id" but you don't have an "id" field name. Either add another field that will name each row (e.g. names of States, etc.) or just omit the argument. Agree that the error message is useless.