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

标签 r encoding data.table

我正在尝试合并两个 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/

相关文章:

c - 以 sprintf 科学记数法打印所有有效数字

c# - "Unable to translate Unicode character"保存到txt文件时出错

mysql - 无法使用 ADO/ODBC 将重音字符写入 MySQL

ruby - 为什么格式转换库缺乏将输出写入文件的单一方法?

r - 如何获取列表列中包含元素的行

r - 将向量附加到 data.table 作为单独的新列,向量回收单个值

arrays - 命名数组的一维

r - R 在哪里存储包?

r - 将任意类的列转换为另一个 data.table 中匹配列的类

r - 将条目列添加到 r Shiny 数据表的按钮