gpt4 book ai didi

r - 合并 data.table 时出错 - 编码警告消息

转载 作者:行者123 更新时间:2023-12-04 09:38:13 25 4
gpt4 key购买 nike

我正在尝试合并两个 data.table 并收到此错误消息:

> tabelaApoio <- merge(data.table(Geo = iconv(.rop, to = 'UTF8'), Level = 2, key = c('Geo', 'Level')), data.table(Geo = iconv(.bairros, to = 'UTF8'), Level = 3, key = c('Geo', 'Level')))
Warning message:
In bmerge(i <- shallow(i), x, leftcols, rightcols, io <- haskey(i), :
A known encoding (latin1 or UTF-8) was detected in a join column.
data.table compares the bytes currently, so doesn't support *mixed*
encodings well; i.e., using both latin1 and UTF-8, or if any unknown
encodings are non-ascii and some of those are marked known and others not.
But if either latin1 or UTF-8 is used exclusively, and all unknown encodings
are ascii, then the result should be ok. In future we will check for you
and avoid this warning if everything is ok. The tricky part is doing this
without impacting performance for ascii-only cases.
> tabelaApoio
Empty data.table (0 rows) of 2 cols: Geo,Level

好的,我明白问题所在:变量没有相同的编码。问题 - 至少对我而言 - 是这两个变量都是在 R 内部的 .First() 函数上创建的:

function() {
dir <- sprintf('C:/Users/%s/Desktop/Coisas', Sys.info()['user'])
if (file.exists(dir)) { setwd(sprintf('C:/Users/%s/Desktop/Coisas/', Sys.info()['user'])) }
else { warning(sprintf('Não foi possível alterar a pasta de trabalho para %s', dir)) }
assign('.dir', sprintf('%sCoisas/ObservaPOA/', substr(R.home(), 1, 3)), .GlobalEnv)
assign('.bairros', c("Agronomia", "Anchieta", "Arquipélago", "Auxiliadora", "Azenha", "Bela Vista", "Belém Novo", "Belém Velho", "Boa Vista", "Bom Fim", "Bom Jesus", "Camaquã", "Campo Novo", "Cascata", "Cavalhada",
"Cel Aparício Borges", "Centro Histórico", "Chácara das Pedras", "Chapéu do Sol", "Cidade Baixa", "Cristal", "Cristo Redentor", "Espírito Santo", "Farrapos", "Farroupilha", "Floresta", "Glória",
"Guarujá", "Higienópolis", "Hípica", "Humaitá", "Independência", "Ipanema", "Jardim Botânico", "Jardim Carvalho", "Jardim do Salso", "Jardim Floresta", "Jardim Isabel", "Jardim Itú", "Jardim Lindóia",
"Jardim Sabará", "Jardim São Pedro", "Lageado", "Lami", "Lomba do Pinheiro", "Mário Quintana", "Medianeira", "Menino Deus", "Moinhos de Vento", "Mont'Serrat", "Morro Santana", "Navegantes", "Nonoai", "Partenon",
"Passo D'areia", "Passo das Pedras", "Pedra Redonda", "Petrópolis", "Ponta Grossa", "Praia de Belas", "Restinga", "Rio Branco", "Rubem Berta", "Santa Cecília", "Santa Maria Goretti", "Santa Tereza", "Santana",
"Santo Antônio", "São Geraldo", "São João", "São José", "São Sebastião", "Sarandi", "Serraria", "Teresópolis", "Três Figueiras", "Tristeza", "Vila Assunção", "Vila Conceição", "Vila Ipiranga", "Vila Jardim",
"Vila João Pessoa", "Vila Nova"), .GlobalEnv)
assign('.rop', c("Centro", "Centro-Sul", "Cristal", "Cruzeiro", "Eixo-Baltazar", "Extremo-Sul", "Glória", "Humaitá / Navegantes", "Ilhas", "Leste", "Lomba do Pinheiro", "Nordeste", "Noroeste",
"Norte", "Partenon", "Restinga", "Sul"), .GlobalEnv)
lockBinding(".dir", .GlobalEnv)
lockBinding(".bairros", .GlobalEnv)
lockBinding(".rop", .GlobalEnv)
source(sprintf('%sLe bancos.R', .dir))
}

所以,我不知道为什么会出现此警告消息以及如何解决它。我试过使用 iconv(),但没用 :(

最佳答案

改变 Encoding(data1$geo) <- "latin1"对于 geo两个表的列都应该工作。

关于r - 合并 data.table 时出错 - 编码警告消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32126838/

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