Unused argument (sep=";") 错误发生在所有 CSV 文件中

Unused argument (sep=";") error happens with all CSV files

我想打开一个随机的 csv 文件,例如 New_York_City_Leading_Causes_of_Death.csv(只是一个虚拟文件,来自教程,但以同样的方式处理我自己的数据;替换为 , 为 ;) https://www.dropbox.com/s/3usf8y75vz2cpj4/New_York_City_Leading_Causes_of_Death.csv?dl=0

大纲说: read_csv("New_York_City_Leading_Causes_of_Death.csv", sep = ";") 错误: 未使用的参数 (sep = ";")

我创建了几个 csv 文件来调试 我试过 readr::read_csv 和 utils::read_csv -> 都是同样的问题 我确保 csv 文件和 .r 在同一个文件夹中 我在大学里用电脑(可能是瓶颈?)

提前谢谢你:)

library(utils)
library(utf8)

df <- read_csv("New_York_City_Leading_Causes_of_Death.csv", sep = ";" )
head(df)

这是我收到的错误消息:

Error in read_csv("New_York_City_Leading_Causes_of_Death.csv", sep = ";") : unused argument (sep = ";")

我希望输出是一个数据帧。

utils 包只有 read.csv() 功能——注意 . 而不是 _。至于readrread_csv()函数,它没有一个叫sep的参数。这就是为什么每次您 运行 您的代码时都会出现关于有一个未使用的参数 sep 的错误消息。

我尝试在没有任何参数的情况下只执行 read_csv('New_York_City_Leading_Causes_of_Death.csv'),并且能够成功读取以下内容 tibble

# A tibble: 1,094 x 7
    Year `Leading Cause`                                 Sex   `Race Ethnicity`    Deaths `Death Rate` `Age Adjusted Dea~
   <dbl> <chr>                                           <chr> <chr>               <chr>  <chr>        <chr>             
 1  2010 Assault (Homicide: Y87.1, X85-Y09)              M     Black Non-Hispanic  299    35.1         35.5              
 2  2011 Mental and Behavioral Disorders due to Acciden~ M     Not Stated/Unknown  5      .            .                 
 3  2011 Diseases of Heart (I00-I09, I11, I13, I20-I51)  M     Black Non-Hispanic  1840   215.7        268.3             
 4  2008 Certain Conditions originating in the Perinata~ F     Other Race/ Ethnic~ .      .            .                 
 5  2014 Accidents Except Drug Posioning (V01-X39, X43,~ F     Hispanic            64     5.1          5.4               
 6  2007 Intentional Self-Harm (Suicide: X60-X84, Y87.0) M     Not Stated/Unknown  5      .            .                 
 7  2012 Accidents Except Drug Posioning (V01-X39, X43,~ M     Black Non-Hispanic  152    17.8         18.6              
 8  2009 All Other Causes                                M     Asian and Pacific ~ 220    43.1         56.1              
 9  2013 Diseases of Heart (I00-I09, I11, I13, I20-I51)  F     Asian and Pacific ~ 437    72.8         81.8              
10  2014 Accidents Except Drug Posioning (V01-X39, X43,~ M     Other Race/ Ethnic~ 12     .            .                 
# ... with 1,084 more rows

或者,为了在更大的数据集上获得更快的性能,请考虑使用 data.table::fread()data.table 包中的 fread() 函数允许您使用参数 sep = ';' 将分隔符指定为 ;。 请注意 fread() 只能 return 一个 data.table 或一个 data.frame。默认情况下,fread() return 是 data.table,但如果传入参数 data.table = FALSE,则可以 return 是 data.frame。但是,如果您愿意更喜欢使用 tibble,您可以简单地将 fread() 调用包装在 as_tibble().

我也遇到了同样的情况!我的解决方案是将 read_csv 更改为 read.csv

我的例子:

而不是 X1_bank_full <- read_csv("C:/Users/User Name/Downloads/1-bank-full.csv", sep=";")

正确的是: X1_bank_full <- read.csv("C:/Users/User Name/Downloads/1-bank-full.csv", sep=";")