Import dataset, missing values

Hello, I am new of the community and a new of using R and Rstudio. I am trying to import a txt dataset but I receive an import different from the original table, to clarify I am importing a file with a row= 436083.51 4489939.09 28.52 and I receive in Rstudio 436083.5 4489939 28.52, loosing some numbers.

library(readr)
as <- read_table2("as.txt", col_names = FALSE)

Any help?

Hi @mellino, welcome to RStudio Community.

Can you show us a sample of as.txt? Just want to make sure that the function you're using is appropriate for the structure of your data file.

Thank you for your quick reply. I tried to upload the file but I can not...It is a .txt file, space delimited, containing the following data:

436083.51 4489939.09 28.52
436083.51 4489939.03 28.54
436083.51 4489938.97 28.56
436083.51 4489938.93 28.55
436083.51 4489938.88 28.56
436083.51 4489938.83 28.57
436083.51 4489938.77 28.58
436083.51 4489938.72 28.59
436083.51 4489938.66 28.60
436083.51 4489938.61 28.62
436083.51 4489938.56 28.63
436083.51 4489938.51 28.63
436083.51 4489938.44 28.65
436083.52 4489938.39 28.67
436083.52 4489938.33 28.69
436083.52 4489938.28 28.69
436083.52 4489938.23 28.69
436083.52 4489938.19 28.69
436083.52 4489938.14 28.69
436083.52 4489938.10 28.69
436083.52 4489938.05 28.69
436083.52 4489938.00 28.69
436083.52 4489937.95 28.69
436083.52 4489937.90 28.69

I'd like to ask you to run the following code and report the results. for contrast mine are 0 and 7 respectively

getOption("scipen")
getOption("digits")

I received 0 and 7 too

What results do you get if you use read_table() instead of read_table2()? Since your data appears to be well-structured with a single space delimiting the values, you shouldn't need the latter.

I got the same result...

This is the original file and the Rstudio result...

Its probably simply representational. you can max out your options digits and your scipen to alter.

library(tidyverse)
options(digits=4, scmytext<-"
a b c
436083.51 4489939.09 28.52
436083.51 4489939.03 28.54
436083.51 4489938.97 28.56
436083.51 4489938.93 28.55
436083.51 4489938.88 28.56
436083.51 4489938.83 28.57
436083.51 4489938.77 28.58
436083.51 4489938.72 28.59
436083.51 4489938.66 28.60
436083.51 4489938.61 28.62
436083.51 4489938.56 28.63
436083.51 4489938.51 28.63
436083.51 4489938.44 28.65
436083.52 4489938.39 28.67
436083.52 4489938.33 28.69
436083.52 4489938.28 28.69
436083.52 4489938.23 28.69
436083.52 4489938.19 28.69
436083.52 4489938.14 28.69
436083.52 4489938.10 28.69
436083.52 4489938.05 28.69
436083.52 4489938.00 28.69
436083.52 4489937.95 28.69
436083.52 4489937.90 28.69"

myfile <- tempfile()
writeLines(mytext,myfile)
my_tibble<-read_delim(myfile,delim = " ")

b<-pull(my_tibble,b)
options(digits=7,scipen=0)
(b)
(b2<- b - 4489937)

options(digits=10,scipen=999)
(b)
(b2<- b - 4489937)

nirgrahamuk is right. You aren't seeing enough significant digits in the Viewer pane which is controlled via options. For example, setting options(digits = 9) will work for your data.

Sorry, but I have starting to learn R yesterday and this is my first dataset import...I am not able to understand your solution, can you explain in a simple way?

you can run the entire script I posted and think about what its telling you.
There are options that control how R prints numbers.
Probably good options for your case might be

options(digits=9,scipen=999)

you can simply run that at the top of your script, and then continue to work as normal. If you want to see more or less significant digits , or change the likelihood of numbers appearing in scientific notation, you would change these options.

1 Like

Thank you nirgrahamuk and siddharthprabhu, now it works!

Hello,
now I am tring to save a txt file using write.table() but if I have a number with a 0 after the decimal separetor this is omissed in the output, for example if the data is 18.20 in the stored txt I got 18.2. I hope that this is clear.
Any help?

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.