Changes in the headers when I read files in R?

前端 未结 2 1238
忘掉有多难
忘掉有多难 2021-01-16 00:52

Whenever I read in a file using read.csv() with option header=T, the headers change in weird (but predictable) ways. A header name which ought to r

2条回答
  •  死守一世寂寞
    2021-01-16 01:38

    Not really intended as an answer, but intended to be helpful to Rnewbs: Those headers were read in as factors (and caused the third column to also be a factor. The screwy names() assignments probably used their integer storage mode. @Andrie has already given you the preferred solution, but if you wanted to just reassign the names (which would not undo the damage to the thrid column) you could use:

     names(myfile1) <- scan(file=fullpath, what="character" nmax=1 , sep="\t")
     myfile1 <- myfile[-1, ]    # gets rid of unneeded line
    

提交回复
热议问题