Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/66.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R中的read.csv无法正确读取列名_R - Fatal编程技术网

R中的read.csv无法正确读取列名

R中的read.csv无法正确读取列名,r,R,我有一个csv文件,我正试图将其内容读入R。但是我的列名没有正确显示,它在第一列的名称中显示了一些奇怪的字符。(请注意,我尝试读入的任何csv文件都是这种情况) 请参见下面的R代码 > mycsvfile = read.csv('C:\\Users\\wdsuser\\Desktop\\mycsvfile.csv') > mycsvfile ï..col1 col2 1 hello world 2 first last 3 bye bye > nam

我有一个csv文件,我正试图将其内容读入R。但是我的列名没有正确显示,它在第一列的名称中显示了一些奇怪的字符。(请注意,我尝试读入的任何csv文件都是这种情况)

请参见下面的R代码

> mycsvfile = read.csv('C:\\Users\\wdsuser\\Desktop\\mycsvfile.csv')
> mycsvfile
  ï..col1  col2
1   hello world
2   first  last
3     bye   bye
> names(mycsvfile)
[1] "ï..col1" "col2"   
> mycsvfile$col2
[1] world last  bye  
Levels: bye last world
> mycsvfile$col1
NULL
这就是我的文本文件的外观

col1,col2
hello,world
first,last
bye,bye
R版本:

> R.version
               _                           
platform       x86_64-w64-mingw32          
arch           x86_64                      
os             mingw32                     
system         x86_64, mingw32             
status                                     
major          3                           
minor          1.2                         
year           2014                        
month          10                          
day            31                          
svn rev        66913                       
language       R                           
version.string R version 3.1.2 (2014-10-31)
nickname       Pumpkin Helmet

这是一个编码问题:

read.csv('C:\\Users\\wdsuser\\Desktop\\mycsvfile.csv', fileEncoding="UTF-8-BOM")

应该有用

您在此处提供的数据不可复制:
mycsvfile=read.csv(text='col1,col2\nhello,world\nfirst,last\nbye,bye');名称(mycsvfile);#[1] “col1”“col2”
我遇到了同样的问题!它被记录在
?read.csv
中,重定向到
部分的
文件