Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between read.csv() and read.csv2() in R

Tags:

r

csv

read.csv

In R , what is the difference between read.csv() and read.csv2()

The official documentation says,

In various European locales, as the comma character serves as the decimal point, the function read.csv2 should be used instead

What does this mean. I don't see any difference at the superficial level. Can anybody give out a concrete example to clarify it further.

like image 713
Anoop Avatar asked Apr 09 '14 17:04

Anoop


People also ask

What's the difference between read_csv () and read_csv2 ()?

read_csv() reads comma delimited files, read_csv2() reads semicolon separated files (common in countries where , is used as the decimal place), read_tsv() reads tab delimited files, and read_delim() reads in files with any delimiter.

What does the read csv () function in R do?

csv() Function. read. csv() function in R Language is used to read “comma separated value” files. It imports data in the form of a data frame.

What is the use of read csv2 () command?

They are intended for reading 'comma separated value' files ( . csv ) or ( read. csv2 ) the variant used in countries that use a comma as decimal point and a semicolon as field separator.

What is the difference between read csv and read table in R?

csv() as well as the read. csv2() function are almost identical to the read. table() function, with the sole difference that they have the header and fill arguments set as TRUE by default. Tip: if you want to learn more about the arguments that you can use in the read.


1 Answers

They are (almost) the same functions - read.table. The only difference is default parameters. Look at source code:

> read.csv function (file, header = TRUE, sep = ",", quote = "\"", dec = ".",      fill = TRUE, comment.char = "", ...)  read.table(file = file, header = header, sep = sep, quote = quote,      dec = dec, fill = fill, comment.char = comment.char, ...) <bytecode: 0x5e3fa88> <environment: namespace:utils> > read.csv2 function (file, header = TRUE, sep = ";", quote = "\"", dec = ",",      fill = TRUE, comment.char = "", ...)  read.table(file = file, header = header, sep = sep, quote = quote,      dec = dec, fill = fill, comment.char = comment.char, ...) <bytecode: 0x5c0a330> <environment: namespace:utils> 

From doc (see ?read.table):

read.csv and read.csv2 are identical to read.table except for the defaults. They are intended for reading ‘comma separated value’ files (‘.csv’) or (read.csv2) the variant used in countries that use a comma as decimal point and a semicolon as field separator.

like image 100
bartektartanus Avatar answered Sep 17 '22 13:09

bartektartanus