当我从包中的Posti-Letto-Istat.xls文件中读取任何工作表时,我没有任何问题:read_excel
readxl
library(readxl)
pl_istat1 <- read_excel(path = "data/Posti-Letto-Istat.xls", sheet = 1, range = "A6:I66", na = "....")
但是,如果我尝试使用 alapply
或for
循环将所有三个工作表都放在一个列表中,则会出现以下错误。
lapply(1:3, function(i) read_excel(path = "data/Posti-Letto-Istat.xls", sheet = i, range = "A6:I66", na = "...."))
Error in nchar(x, type = "width") : invalid multibyte string, element 4
我看到这是一个编码问题,如果我做类似的事情
names(pl_istat[[i]]) <- iconv(enc2utf8(names(pl_istat[[i]])),sub="byte")
每张纸,然后我没有问题。
但是,有没有办法让列表接受tibble
正确导入的readxl
?
我的会话信息:
R version 3.3.3 (2017-03-06)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)
locale:
[1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United
States.1252 LC_MONETARY=English_United States.1252 LC_NUMERIC=C
[5] LC_TIME=English_United States.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] readxl_1.0.0
loaded via a namespace (and not attached):
[1] magrittr_1.5 assertthat_0.2.0 R6_2.2.2 tools_3.3.3 bindrcpp_0.2 glue_1.1.1 dplyr_0.7.3 tibble_1.3.4 Rcpp_0.12.12
[10] cellranger_1.1.0 rematch_1.0.1 pkgconfig_2.0.1 rlang_0.1.2 bindr_0.1