R reading a tsv file using specific encoding

前端 未结 3 1436
粉色の甜心
粉色の甜心 2021-01-17 21:49

I am trying to read a .tsv (tab-separated value) file into R using a specific encoding. It\'s supposedly windows-1252. And it has a header.

Any sugg

3条回答
  •  北荒
    北荒 (楼主)
    2021-01-17 22:19

    You can also use:

    read.delim('thefile.txt', header= T, fileEncoding= "windows-1252")

    Simply entering the command into your R consol:

     > read.delim
    function (file, header = TRUE, sep = "\t", quote = "\"", dec = ".", 
        fill = TRUE, comment.char = "", ...) 
    read.table(file = file, header = header, sep = sep, quote = quote, 
        dec = dec, fill = fill, comment.char = comment.char, ...)
    

    reveals that read.delim is a packaged read.table command that already specifies tabs as your data's separator. read.delim might be more convenient if you're working with a lot of tsv files.

    The difference between the two commands is discussed in more detail in this Stack question.

提交回复
热议问题