danux
danux

Reputation: 13

Can't correctly format imported data in R

i'm trying to import a text file to R, which normally I get without problems. But this time, R imports only a fraction of some columns.

This is the input data stored in a plain text file (tab separated):

    id_value    NG  treatment_id    treatment   Xcoord  Ycoord
    267  0.14217400000  1a  1   529863.226  5695760.970
    269  0.14218700000  1a  1   529861.792  5695760.404
    270  0.14599500000  1a  1   529862.235  5695758.726
    271  0.15622200000  1a  1   529860.258  5695760.198
    273  0.15795400000  1a  1   529860.679  5695758.050

I used the command:

interpr <- read.delim("~/interpr")

and got this:

> interpolation
        id.value     NG      treatment_id treatment   Xcoord  Ycoord
    1        267   0.1421740           1a         1 529863.2 5695761
    2        269   0.1421870           1a         1 529861.8 5695760
    3        270   0.1459950           1a         1 529862.2 5695759
    4        271   0.1562220           1a         1 529860.3 5695760
    5        273   0.1579540           1a         1 529860.7 5695758

As you may noticed, the column Xcoord ist rounded to just one decimal place while the column Ycoord is rounded to an integer.

I have tried lot of things. For example, I tried to import the columns as text, and the converting them to numbers using:

interpr <- read.delim("~/interpr", colClasses = "character")
interpr$X <- as.double(interpr$Xcoord) 

At first it imports all numbers, but after transforming (also tried as.numeric) I get the same problem. I need the 3 decimal places, so rounding is not an option for me. I also need it to be defined as number for further prosessing.

Does someone know why this happens? It's the first time I've ever seen this problem...

Upvotes: 1

Views: 72

Answers (1)

user20650
user20650

Reputation: 25854

The issue is the default number of digits that are printed on screen - the default is seven, see ?options and look for digits.

You can change the default by using

options(digits=10)

Upvotes: 1

Related Questions