Import data with spaces within fields from a txt to R

Asked

Viewed 39 times

0

Good afternoon

I would like to import a file, and I will post an example to be helped It consists of names with space and number separations

To help me with the solution, please copy this information to Excel and to save it in txt separated by tabs, or in some other txt format that solves the problem

dados        numero     nome
rua joao     15         Joao Inep
rua maria    25         Maria Suiço
rua dois     35         Fernando José

This file is in Excel, and when saving it in txt separated by tabs and trying to import to R, there is a problem regarding the existing spaces within each field

I’d like some help importing it

I tried to import by selecting everything in excel and using the command

dados<-read.table('clipboard', h=T)

also tried using the same code

dados<-read.table(ENDEREÇO DO ARQUIVO NO MEU COMPUTADOR.TXT, h=T)

Thanks in advance

  • 1

    Henrique, which code you used to import the file and which output is error?

  • good afternoon, I edited the question with the information, thanks for the availability

  • Try this: read.table(file, header = T, sep = "")

  • 'Error in read.table("Clipboard", h = T, Sep = "") : more Columns than column Names'

  • If you routinely need to read Excel files in R, try the readxl package: https://cran.r-project.org/web/packages/readxl/

  • thanks for the indication, however I would like to import the file through a txt, containing the described information

  • 1

    Did you save it in Excel to . txt as tab-separated text? If so, this worked here: clipboard <- read.delim("C:/Users/BRENNER BIASI/Desktop/clipboard.txt")

  • 1

    Solved, thank you very much for the help, if you want to comment as a response to evaluate as a solution for you score

Show 3 more comments

1 answer

2


Importing . txt file from tab separated data file in Excel.

clipboard <- read.delim("arquivo") # 
# arquivo = Endereço da pasta no computador + /nome do arquivo.txt
clipboard <- read.delim("C:/Users/BRENNER BIASI/Desktop/clipboard.txt")

Browser other questions tagged

You are not signed in. Login or sign up in order to post.