Cadena multibyte inválida en lectura.csv


Estoy tratando de importar un csv que está en japonés. Este código:

url <- 'http://www.mof.go.jp/international_policy/reference/itn_transactions_in_securities/week.csv'
x <- read.csv(url, header=FALSE, stringsAsFactors=FALSE)

Devuelve el siguiente error:

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>
 30
Author: bartektartanus, 2013-01-16

7 answers

Encoding establece la codificación de una cadena de caracteres. No establece la codificación del archivo representado por la cadena de caracteres, que es lo que quieres.

Esto funcionó para mí, después de intentar "UTF-8":

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

Y es posible que desee omitir las primeras 16 líneas y leer los encabezados por separado. De cualquier manera, todavía hay un poco de limpieza por hacer.

x <- read.csv(url, header=FALSE, stringsAsFactors=FALSE,
  fileEncoding="latin1", skip=16)
# get started with the clean-up
x[,1] <- gsub("\u0081|`", "", x[,1])    # get rid of odd characters
x[,-1] <- as.data.frame(lapply(x[,-1],  # convert to numbers
  function(d) type.convert(gsub(d, pattern=",", replace=""))))
 63
Author: Joshua Ulrich,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-01-16 16:50:19

Es posible que haya encontrado este problema debido a la incompatibilidad de la configuración regional del sistema intente configurar la configuración regional del sistema con este código Sys.setlocale("LC_ALL", "C")

 8
Author: user3670684,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-02-23 15:44:56

El paquete readr del universo tidyverse podría ayudar.

Puede establecer la codificación mediante el argumento local de la función read_csv() utilizando la función local() y su argumento de codificación:

read_csv(file = "http://www.mof.go.jp/international_policy/reference/itn_transactions_in_securities/week.csv",
         skip = 14,
         local = locale(encoding = "latin1"))
 5
Author: Je Hsers,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-05-30 11:37:07

Para aquellos que usan Rattle con este problema, aquí está cómo lo resolví:

  1. Primero asegúrese de salir de rattle para que su en el símbolo del sistema R
  2. > library (rattle) (si no lo ha hecho ya)
  3. > crv$csv.encoding="latin1"
  4. > rattle()
  5. Ahora deberías poder continuar. es decir, importa tu csv > Ejecutar > Modelo > Ejecutar etc.

Que funcionó para mí, espero que eso ayude a un viajero cansado

 0
Author: wired00,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-04-17 00:20:03

Tuve un problema similar con los artículos científicos y encontré una buena solución aquí: http://tm.r-forge.r-project.org/faq.html

Utilizando la siguiente línea de código:

tm_map(yourCorpus, content_transformer(function(x) iconv(enc2utf8(x), sub = "byte")))

Convierte las cadenas multibyte en código hexadecimal. Espero que esto ayude.

 0
Author: Carlos,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-09-20 07:19:58

Si el archivo que está tratando de importar a R era originalmente un archivo de Excel. Asegúrese de abrir el archivo original y Guardar como un csv y que se corrigió este error para mí al importar en R.

 0
Author: 822_BA,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-02-21 20:02:21

Tuve el mismo error y probé todo lo anterior en vano. El problema desapareció cuando actualicé de R 3.4.0 a 3.4.3, así que si tu versión de R no está actualizada, ¡actualízala!

 0
Author: user5783745,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-03-11 12:56:36