read.csv中的无效多字节字符串

我正在尝试导入日语的csv。这段代码:


url <- 'http://www.mof.go.jp/international_policy/reference/itn_transactions_in_securities/week.csv'

x <- read.csv(url, header=FALSE, stringsAsFactors=FALSE)

返回以下错误:


Error in type.convert(data[[i]], as.is = as.is[i], dec = dec, na.strings = character(0L)) : 

invalid multibyte string at '<91>ΊO<8b>y<82>ёΓ<e0><8f>،<94><94><84><94><83><8c>_<96>?̏?@(<8f>T<8e><9f><81>E<8e>w<92><e8><95>?@<8a>փx<81>[<83>X<81>j'

我尝试更改编码(Encoding(url) <- 'UTF-8'也更改为latin1),并尝试删除read.csv参数,但在每种情况下均收到相同的“无效的多字节字符串”消息。是否应该使用其他编码,还是存在其他问题?


白猪掌柜的
浏览 1264回答 3
3回答

开满天机

Encoding设置字符串的编码。它不会设置您想要的字符串表示的文件的编码。经过尝试,这对我有用"UTF-8":x <- read.csv(url, header=FALSE, stringsAsFactors=FALSE, fileEncoding="latin1")您可能希望跳过前16行,并分别读入标题。无论哪种方式,仍有大量清理工作要做。x <- read.csv(url, header=FALSE, stringsAsFactors=FALSE,&nbsp; fileEncoding="latin1", skip=16)# get started with the clean-upx[,1] <- gsub("\u0081|`", "", x[,1])&nbsp; &nbsp; # get rid of odd charactersx[,-1] <- as.data.frame(lapply(x[,-1],&nbsp; # convert to numbers&nbsp; function(d) type.convert(gsub(d, pattern=",", replace=""))))
打开App,查看更多内容
随时随地看视频慕课网APP