0

I need to get the mean of the value column but preserve the Lat and Lon decimal places of the following table:

value    node_vsn       Lat      Lon
-0.38017      07C   -87.68302 41.91409
-0.03913      08B   -87.59871 41.78861
-0.03724      004   -87.62768 41.87838
-0.17809      072   -87.71299 41.75114
0.76364       06B   -87.66434 41.78676
-0.22900      089   -87.66239 41.89616
-0.59379      08F   -87.66595 41.96162
-2.45677      081   -87.64105 41.82353
-0.68662      086   -87.67917 41.96876

I did this:

locations <- locations %>%
      group_by(node_vsn, Lat, Lon) %>%
      summarize(mean_size = mean(value, na.rm = TRUE))

I am getting this as a result:

node_vsn   Lat   Lon mean_size
   <fct>    <dbl> <dbl>     <dbl>
  004      -87.6  41.9   -0.290 
  01C      -87.7  41.8    0.0685
  02A      -87.6  41.7   -0.327 
  06B      -87.7  41.8    0.579 
  072      -87.7  41.8    0.0191
  079      -87.7  41.9   -0.178 
  07C      -87.7  41.9   -0.193 
  081      -87.6  41.8   -2.32  

The Lat and Lon are losing decimal places and I want to keep them as they are. options(pillar.sigfig = 7) does not work

  • 2
    I think it is a `print`formatting by the `tbl_df`. Please try to extract `locations$Lat` or `locations$Lon` and check if the data changed. I hope not – akrun Apr 27 '19 at 18:51
  • You can check `locations %>% group_by(node_vsn, Lat, Lon) %>% summarize(mean_size = mean(value, na.rm = TRUE)) %>% .$Lat #[1] -87.62768 -87.66434 -87.71299 -87.68302 -87.64105 -87.66239 -87.59871 -87.66595` – akrun Apr 27 '19 at 18:57

1 Answers1

0

View(locations)
To check if the the decimal points have been lost.

You can mutate the Columns to character string.

locations %>% mutate (Lat = as.character(Lat))

Anshuman
  • 39
  • 1
  • 5