Error in scan (file = file, what = what ...)

1

Good morning, I'm having an error to run a code in my R.

Below is the code.

library(car)
library(fBasics)
library(NbClust)

setwd("C:/Financas") # Salvar na pasta
Base = read.table("baseFin.txt", header=TRUE) #Importa o arquivo

head(Base)
tail(Base)

papel       = Base$Papel
evebit      = Base$EVEBIT
cresrec     = Base$CresRec
lpa         = Base$LPA
vpa         = Base$VPA
margliq     = Base$MargLiquida
ebitativo   = Base$EBITAtivo
liqucorr    = Base$LiquCorr
divbrpatr   = Base$DivBrPatrim

The main purpose of these codes is to get the indicators in the database and do what is written in the code.

This is the database

This is the error that appears in my R

Error in scan(file = file, what = what, sep = sep, quote = quote, dec = dec,  
: 
linha 1 não tinha 14 elementos
    
asked by anonymous 08.05.2018 / 14:36

1 answer

1

The problem is that your header has column names with spaces. You have a few options.

Change the file. The best, but not always possible.

Ignores the header. And put the names.

Base = read.table("baseFin.txt", skip = 1, col.names = c("col1", "col2", "col3") # se vira com os nomes porque o seu arquivo é uma imagem.

If your file is tab separated, you can use the column names as they are. But do not do that, please.

 Base = read.csv2("baseFin.txt", sep="\t", header=TRUE, check.names=FALSE)
    
08.05.2018 / 19:00