如何用逗号作为小数分隔符读取数字? [英] How to read in numbers with a comma as decimal separator?

查看:175
本文介绍了如何用逗号作为小数分隔符读取数字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一系列CSV文件,其中的数字格式为欧洲风格,使用逗号而不是小数点,即 0,5 而不是 0.5

I have a series of CSV files where numbers are formatted in the european style using commas instead of decimal points, i.e. 0,5 instead of 0.5.

在导入到R之前,有太多的这些文件需要编辑。我希望有一个简单的参数 read.csv()函数,或者一个应用于提取的数据集的方法,以便R将数据视为数字而不是字符串。

There are too many of these files to edit them before importing to R. I was hoping there is an easy parameter for the read.csv() function, or a method to apply to the extracted dataset in order for R to treat the data as a number rather than a string.

推荐答案

当你检查?read.table 时,你可能会找到你需要的所有答案。

When you check ?read.table you will probably find all the answer that you need.

(大陆)欧洲csv文件有两个问题:

There are two issues with (continental) European csv files:


  1. csv中的 c 代表什么?对于标准csv,这是一个,对于欧洲csv,这是一个;

    sep read.table中的相应参数

  2. 小数点?对于标准csv,这是一个,对于欧洲csv,这是一个

    dec read.table中的相应参数

  1. What does the c in csv stand for? For standard csv this is a ,, for European csv this is a ;
    sep is the corresponding argument in read.table
  2. What is the character for the decimal point? For standard csv this is a ., for European csv this is a ,
    dec is the corresponding argument in read.table

要读取标准csv,请使用 read.csv 读取欧洲csv使用 read.csv2 。这两个函数只是用来设置相应参数的 read.table 包装器。

To read standard csv use read.csv, to read European csv use read.csv2. These two functions are just wrappers to read.table that set the appropriate arguments.

这些标准中的任何一个都手动设置参数。

If your file does not follow either of these standards set the arguments manually.

这篇关于如何用逗号作为小数分隔符读取数字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆