gpt4 book ai didi

read_excel 正确导入文件,但尝试将其放入列表时出现 "invalid multibyte string"错误

转载 作者:行者123 更新时间:2023-12-05 00:25:20 25 4
gpt4 key购买 nike

当我从文件 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 = "....")

但是,如果我尝试使用 lapplyfor循环将所有三张纸都放在一个列表中,我收到以下错误。
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")

每张纸,然后我就没有问题。

但是,有没有办法让列表接受 tibblereadxl 正确导入?

我的 session 信息:
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

最佳答案

我有同样的错误,可以通过包装 read_excel() 来解决它与 as.data.frame()

lapply(
1:3,
function(i) {
as.data.frame(
read_excel(path = "data/Posti-Letto-Istat.xls", sheet = i, range = "A6:I66", na = "....")
)
}
)

关于read_excel 正确导入文件,但尝试将其放入列表时出现 "invalid multibyte string"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46503390/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com