我有一个csv文件,想要将其内容读入R中。但我的列名无法正确显示,第一列的名称中显示一些奇怪的字符。(请注意,这是我尝试读取任何csv文件时都会出现的情况)
请参见下面的R代码:
这是我的文本文件的样子。
请参见下面的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"
- lukeA