【发布时间】:2015-01-17 23:48:06
【问题描述】:
我有一个 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
【问题讨论】:
-
无法用您在此处提供的数据重现:
mycsvfile = read.csv(text = 'col1,col2\nhello,world\nfirst,last\nbye,bye'); names(mycsvfile); # [1] "col1" "col2"
标签: r