Hi,
I am using RStudio v1.2.1139-1. When I load a csv into R, blank cells that should show up as NA show up as 0. I started with a new blank csv file and tried loading it using:
-
read.csv (base R)
-
read_csv (readr)
-
fread (data.table)
and then I saved it as an .xlsx file and loaded it using:
and the blank cells show up as 0 when view the dataframe by selecting it from the Global Environment window in the top right corner.
When I print the data on the console, it prints with NA. So it seems to me that the viewer is showing it incorrectly (unless it was designed to show 0 instead of NA?) as the data seems to print correctly and performing operations on NA values results in NA.
Has anyone else come across this problem? Here is sample code that produces the issue.
Thanks,
# when viewing dataframe from Global Environment NA show up as 0
a <- data.frame(columnA = c(1:5, rep(NA, times = 4), 10),
columnB = rep("apples", times = 10),
columnC = c(11, 12, NA, 14, NA, NA, NA, 18, 19, 20))
sessionInfo()
#> R version 3.5.1 (2018-07-02)
#> Platform: x86_64-w64-mingw32/x64 (64-bit)
#> Running under: Windows 7 x64 (build 7601) Service Pack 1
#>
#> Matrix products: default
#>
#> locale:
#> [1] LC_COLLATE=English_United States.1252
#> [2] LC_CTYPE=English_United States.1252
#> [3] LC_MONETARY=English_United States.1252
#> [4] LC_NUMERIC=C
#> [5] LC_TIME=English_United States.1252
#>
#> attached base packages:
#> [1] stats graphics grDevices utils datasets methods base
#>
#> loaded via a namespace (and not attached):
#> [1] compiler_3.5.1 backports_1.1.2 magrittr_1.5 rprojroot_1.3-2
#> [5] tools_3.5.1 htmltools_0.3.6 yaml_2.2.0 Rcpp_0.12.18
#> [9] stringi_1.2.4 rmarkdown_1.10 knitr_1.20 stringr_1.3.1
#> [13] digest_0.6.15 evaluate_0.11