我需要获取value列的平均值,但保留下表的Lat和Lon小数位:
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
我这样做了:
locations <- locations %>%
group_by(node_vsn, Lat, Lon) %>%
summarize(mean_size = mean(value, na.rm = TRUE))
我得到这个结果:
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
Lat和Lon正在失去小数位,我想保持原样。 options(pillar.sigfig = 7)不起作用
答案 0 :(得分:0)
View(locations)
检查小数点是否丢失。
您可以将“列”突变为字符串。
locations %>% mutate (Lat = as.character(Lat))