3

I have the following dataframe:

myd <- data.frame(a = c(3.0, "2.0 (1.8, 2.2)"))
myd$a[1] <- format(round(as.numeric(myd$a[1]), 1), nsmall = 1)

My data looks like below:

myd
               a
1            3.0
2 2.0 (1.8, 2.2)

I want to export myd to csv (or excel). So I tried

write_csv(myd, "myd.csv")

However, row 1 and column 1 of the resultant csv file gives me a number 3 rather than 3.0. A screen shot of the csv is found as follows:

enter image description here

How can I create a .csv or .xlsx file that preserves the digits for the integers (output 3.0 rather than 3)? Hopefully this could be solved within the tidyverse ecosystem, but other solutions are also welcome.

Patrick
  • 1,057
  • 9
  • 23

1 Answers1

2

You don't need to do anything. The write_csv function does preserve the digits, but you don't see them when you open the file in Excel. See my screenshot. enter image description here

Haci Duru
  • 456
  • 3
  • 9