简体   繁体   English

如何在R中读取CSV文件时解决错误

[英]How to solve Error while reading a CSV file in R

hey guys im a beginner in R and want to read a csv file, but I get errors. 嘿家伙我是R的初学者,想要阅读一个csv文件,但我得到错误。

I tried this: 我试过这个:

read.csv("unit_values_feudal.csv",colClasses = c("character","numeric","numeric","numeric","numeric","numeric"))

got this error: 得到了这个错误:

error in scan(file = file, what = what, sep = sep, quote = quote, dec = dec,  :    scan() expected 'a real', got '"'

added a screen of the file: 添加了文件的屏幕:

csv.file

You can simply remove the second argument colClasses and R will read the CSV. 您只需删除第二个参数colClasses ,R将读取CSV。

Here is something you can try: 您可以尝试以下方法:

read.csv("unit_values_feudal.csv") . read.csv("unit_values_feudal.csv")

Furthermore, as some have pointed out, you probably might want to remove the commas before and after your numbers , and the code you have written will work just fine. 此外,正如一些人所指出的那样,你可能想要删除数字前后的逗号,而你编写的代码也可以正常工作。

It might be better to check the csv file in Notepad rather than excel, I get a feeling that you are not importing the csv into excel using the right delimiter. 在记事本中检查csv文件而不是excel可能更好,我感觉你没有使用正确的分隔符将csv导入excel。

Other than that, I think read.csv("unit_values_feudal.csv") will just work. 除此之外,我认为read.csv("unit_values_feudal.csv")将起作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM