[R] Problems with read.table and data structure
Marc Schwartz
marc_schwartz at me.com
Fri Jul 11 21:36:52 CEST 2014
On Jul 11, 2014, at 9:15 AM, Tim Richter-Heitmann <trichter at uni-bremen.de> wrote:
> Hi there!
>
> I have huge datafile of 600 columns 360 samples:
>
> data <- read.table("small.txt", header = TRUE, sep = "\t", dec = ".",
> row.names=1)
>
> The txt.file (compiled with excel) is showing me only numbers, however R
> gives me the structure of ANY column as "factor".
>
> When i try "stringsAsFactors=FALSE" in the read command, the structure
> of the dataset becomes "character."
>
> When i try as.numeric(data), i get
>
> Error: (list) object cannot be coerced to type 'double'
>
>
> even, if i try to subset columns with [].
>
>
> When i try as.numeric on single columns with $, i am successful, but the numbers dont make any sense at all, as the factors are not converted by their levels:
>
>
> Factor w/ 358 levels "0,123111694",..: 11 14 50 12 38 44 13 76 31 30
>
>
> becomes
>
>
> num 11 14 50 12 38 44 13 76 31 30
>
>
> whereas i would need the levels, though!
>
>
> I suspect excel to mess up the "save as tab-delimited text", but the text file seems fine with me on surface (i dont know how the numbers are stored internally). I just see correct numbers, also the View command
> yields the correct content.
>
>
>
> Anyone knows help? Its pretty annoying.
>
>
>
> Thank you!
Hi,
See:
http://cran.r-project.org/doc/FAQ/R-FAQ.html#How-do-I-convert-factors-to-numeric_003f
Regards,
Marc Schwartz
More information about the R-help
mailing list