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

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

问题描述

我有一系列 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,这是一个 ;
    sepread.table
  2. 中对应的参数
  3. 小数点的字符是什么?对于标准 csv,这是一个 .,对于欧洲 csv,这是一个 ,
    decread.table
  4. 中对应的参数
  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天全站免登陆