Boris
Boris

Reputation: 1143

R function read.csv2 fail with error 'arguments imply differing number of rows'

With R, I am reading a simple file such as

data.frame(read.csv2("myFile.csv", header=F, sep="|"), colnames = c("user","product"))

and I get the error

arguments imply differing number of rows: 5462465, 2 

When doing

data <- read.csv2(myFile.csv, header=F, sep="|")
colnames(data) <-  c("user","product")

Everything is OK. Why?

Upvotes: 0

Views: 241

Answers (1)

Kabulan0lak
Kabulan0lak

Reputation: 2136

There is no colnames argument in data.frame() : see manual. So here you are adding a column to your data.frame which name is "colnames" and you try to add 2 rows : "user" and "product". This makes no sense.

I suggest you to use your working alternative that is perfectly fine.

Upvotes: 2

Related Questions