Reading Tab Delimited Data in to R

前端 未结 2 1684
梦谈多话
梦谈多话 2021-01-04 02:32

I am trying to read a large tab delimited file in to R.

First I tried this:

data <- read.table(\"data.csv\", sep=\"\\t\")

But it

2条回答
  •  孤街浪徒
    2021-01-04 03:34

    Without seeing your data, you have one of a few things: you don't have all tabs separating the data; there are embeded tabs in single observations; or a litnay of others.

    The way you can sort this out is to set options(stringsAsFactors=FALSE) then use your first line.

    Check out str(data) and try to figure out which rows are the culprits. The reason some of the numeric values are reading as factors is because there is something in that column that R is interpreting as a character and so it coerces the whole column to character. It usually takes some digging but the problem is almost surely with your input file.

    This is a common data munging issue, good luck!

提交回复
热议问题