
Caro Daniel, A sua importação deixa escapar o restante dos dados da primeira linha, por exemplo. Há valores não nulos que foram não lidos pois, como disse na mensagem original: "No entanto, ele reconhece prematuramente fins de linhas em algumas linhas quando encontra campos com nulo [00 00]. Há valores não nulos não sendo lidos após campos nulos que provocam o reconhecimento de fim de linha". No "resto"da primeira linha ainda há: 6271 FUNDACAO UNIVERSIDADE DE BRASILIA 15000 MINISTERIO DA EDUCACAO HOSP-HOSPITAL UNIVERSITARIO DE BRASILIA 26271 FUNDACAO UNIVERSIDADE DE BRASILIA 15000 MINISTERIO DA EDUCACAO 3 SEM VINCULO Não informada Não informada RESIDENCIA MULTIPROFISSIONAL 40 HORAS SEMANAIS Que não está sendo lido e ignorado por conta do fill = T. ==== Resolvi fazendo um programa em C que tira os nulos e substitui por espaços (abaixo). Com isto, o arquivo é lido mesmo sem o fill: url = "~/Downloads/teste2.csv" y = read.table(url, header = T, sep="\t",quote="",stringsAsFactors=T,fileEncoding="UTF-16", fill=F) Bem, obrigado pela ajuda, mas pena que não resolvi no R. ======= #include <stdio.h> #include <stdlib.h> int main(int argc, const char * argv[]) { FILE * inFile; FILE * outFile; inFile = fopen("/Users/robertopinho/Downloads/teste.csv", "rb"); outFile = fopen("/Users/robertopinho/Downloads/teste2.csv", "wb"); while(!feof(inFile)){ char c1; char c2; c1 = fgetc(inFile); c2 = fgetc(inFile); if(c1 == (int)NULL && c2 == (int)NULL){ c1=0x20; } fputc(c1,outFile); fputc(c2,outFile); } fclose(outFile); fclose(inFile); return 0; } 2012/11/1 Daniel Marcelino <dmsilva.br@gmail.com>
Tenta baixar os dados e importar do computador. É quase 1 gb de texto. É praticamente impossível não ter nenhum erro de codificação. Eu fiz assim e deu certo de novo com o arquivo "20120930_Servidores.csv":
data1 <- read.delim(file.choose(),header=TRUE,sep="\t", fill=TRUE, fileEncoding = "UTF-16LE")
R version 2.15.1 (2012-06-22) -- "Roasted Marshmallows" Copyright (C) 2012 The R Foundation for Statistical Computing ISBN 3-900051-07-0 Platform: x86_64-apple-darwin9.8.0/x86_64 (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details.
Natural language support but running in an English locale
R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R.
data1 <- read.delim(file.choose(),header=TRUE,sep="\t", fill=TRUE, fileEncoding = "UTF-16LE") head(data1) ID_SERVIDOR_PORTAL NOME CPF 1 1493044 AALINE SEVERIANO DA SILVA ***.592.871-** 2 1890528 AARAO CARLOS LUZ MACAMBIRA ***.017.623-** 3 1762984 AARAO CAVALCANTE DE AMORIM ***.292.777-** 4 1920165 AARAO DE ANDRADE LIMA ***.559.144-** 5 1611738 AARAO DIAMANTINO OLIVEIRA ***.056.281-** 6 1611738 AARAO DIAMANTINO OLIVEIRA ***.056.281-** MATRICULA DESCRICAO_CARGO CLASSE_CARGO 1 019**** 2 016**** BIBLIOTECARIO-DOCUMENTALISTA E 3 009**** AGENTE DE SERV DE ENGENHARIA S 4 003**** PROFESSOR 3 GRAU V 5 000**** 6 000**** ANALISTA DO BANCO CENTRAL E REFERENCIA_CARGO PADRAO_CARGO NIVEL_CARGO SIGLA_FUNCAO NIVEL_FUNCAO 1 NA NA 2 NA NA 3 NA NA 4 NA NA 5 NA NA FBC FDT1 6 NA IV NA FUNCAO CODIGO_ATIVIDADE 1 2 3 4 5 FUNCAO COMISSIONADA DO BANCO CENTRAL FDT1 6 ATIVIDADE OPCAO_FUNCAO_TOTAL 1 2 3 4 5 CHEFE DE SUBUNIDADE 6 UORG_LOTACAO COD_ORG_LOTACAO 1 NA 2 NA 3 NA 4 NA 5 DEPTO. CONTR. GEST. PLAN. SUPERVISAO 25201 6 DEPTO. CONTR. GEST. PLAN. SUPERVISAO 25201 ORG_LOTACAO COD_ORGSUP_LOTACAO ORGSUP_LOTACAO 1 NA 2 NA 3 NA 4 NA 5 BANCO CENTRAL DO BRASIL 25201 BANCO CENTRAL DO BRASIL 6 BANCO CENTRAL DO BRASIL 25201 BANCO CENTRAL DO BRASIL UORG_EXERCICIO COD_ORG_EXERCICIO 1 2 3 4 5 DEPTO. CONTR. GEST. PLAN. SUPERVISAO 25201 6 DEPTO. CONTR. GEST. PLAN. SUPERVISAO 25201 ORG_EXERCICIO COD_ORGSUP_EXERCICIO 1 2 3 4 5 BANCO CENTRAL DO BRASIL 25201 6 BANCO CENTRAL DO BRASIL 25201 ORGSUP_EXERCICIO TIPO_VINCULO SITUACAO_VINCULO 1 NA 2 NA 3 NA 4 NA 5 BANCO CENTRAL DO BRASIL 1 ATIVO PERMANENTE 6 BANCO CENTRAL DO BRASIL 2 ATIVO PERMANENTE COD_GRUPO_AFASTAMENTO COD_AFASTAMENTO DATA_INICIO_AFASTAMENTO 1 NA 2 NA 3 NA 4 NA 5 NA Não informada 6 NA Não informada DATA_TERMINO_AFASTAMENTO REGIME_JURIDICO JORNADA_DE_TRABALHO 1 2 3 4 5 Não informada REGIME JURIDICO UNICO 40 HORAS SEMANAIS 6 Não informada REGIME JURIDICO UNICO 40 HORAS SEMANAIS DATA_INGRESSO_CARGOFUNCAO DATA_NOMEACAO_CARGOFUNCAO 1 NA 2 NA 3 NA 4 NA 5 27/04/2012 NA 6 05/01/1998 NA DATA_INGRESSO_ORGAO DOCUMENTO_INGRESSO_SERVICOPUBLICO 1 2 3 4 5 000000000 6 000000000 DATA_DIPLOMA_INGRESSO_SERVICOPUBLICO DIPLOMA_INGRESSO_CARGOFUNCAO 1 NA 2 NA 3 NA 4 NA 5 Não informada NA 6 Não informada NA DIPLOMA_INGRESSO_CARGOFUNCAO.1 DIPLOMA_INGRESSO_SERVICOPUBLICO 1 2 3 4 5 6
2012/10/31 Jakson Alves de Aquino <jalvesaq@gmail.com>
2012/10/31 Roberto de Pinho <robertodepinho@gmail.com>:
tbm sem sucesso:
ata1 <- read.delim(url,header=TRUE,sep="\t", fill=TRUE, fileEncoding = "UTF-16", as.is=T) ata1 <- read.delim(url,header=TRUE,sep="\t", fill=TRUE, fileEncoding = "UTF-16") ata1 <- read.delim(url,header=TRUE,sep="\t", fill=TRUE, fileEncoding = "UTF-16LE", as.is=T) ata1 <- read.delim(url,header=TRUE,sep="\t", fill=TRUE, fileEncoding = "UTF-16LE")
Se estiver usando um sistema operacional que tenha o programa sed instalado (qualquer distribuição do Linux), uma tentativa pode ser "limpar" o arquivo, removendo os 0s:
sed -e 's/\x00//g' teste.csv > teste2.csv sed -e 's/\xff\xfe//' teste2.csv > teste3.csv _______________________________________________ R-br mailing list R-br@listas.c3sl.ufpr.br https://listas.inf.ufpr.br/cgi-bin/mailman/listinfo/r-br Leia o guia de postagem (http://www.leg.ufpr.br/r-br-guia) e forneça código mínimo reproduzível.
-- "Small steps toward a much better world"
\begin{signature} Daniel Marcelino Land Phone 1+514 343 6111 #3799 3200 Jean Brillant, Office C5071 Montreal, QC; H3T 1N8 Canada \end{signature}
_______________________________________________ R-br mailing list R-br@listas.c3sl.ufpr.br https://listas.inf.ufpr.br/cgi-bin/mailman/listinfo/r-br Leia o guia de postagem (http://www.leg.ufpr.br/r-br-guia) e forneça código mínimo reproduzível.
-- Roberto de Pinho robertodepinho@gmail.com http://www.ascoisas.com http://lattes.cnpq.br/4816166073408660