Reputation: 7107
I have some data which I am trying to clean up a little. The variable sizes and magnitudes are quite different across observations.
How can I round:
Data:
structure(list(Mean = c(-46.7524994649769, -2.15127994780551,
3.44707102529562, -771.606218833231, 3635.36502301245, 182.878312690432,
-3.19153497550079, -218.084530125796, 12.576379118899, 12.8254711231537,
1532.50645164376, -24.14026226259, 77.6115151979741, 11.8016462861852,
-31.6170425156006), SD = c(6786.20399515756, 477.895301150669,
2352.63409548278, 235822.062830604, 191315.242094706, 21804.3733962495,
444.200077635788, 82496.7061648105, 1.78211885701244, 1.59684998784859,
273339.019757411, 7139.79956848608, 2393.20448945233, 1186.3377889316,
9051.1220575121), Median = c(0.190091540406153, 0.07237422, 0.1409868,
0.0312290977215064, 48.7438811552346, 2.07218466161306, 0.043900315,
0.234802732975052, 12.5196986609522, 12.6598090447935, 5.728377,
9.176365, 3.65525891417309, 0.879877419393899, 0.91088374889622
), Min = c(-1983300, -83603.91, -576396, -72244587.6666667, -52.5345572354212,
-1306500, -103676.611111111, -25612107.3333333, 1.09658351468913,
3.77714368170893, 0.00001405949, -1638208, -30131.5555555556,
-50156.6, -1786206.75), Max = c(258461.538461538, 42844, 118655,
70086, 39151671, 5285777, 7620.2976, 776699.6, 21.3929396613207,
21.4658433928873, 80912070, 333934, 453203.4, 270815.3, 1891779
), Kurtosis = c(71859.7864151409, 16113.2943818733, 54953.5211577639,
93849.2269902938, 28690.8007193997, 43806.4363882417, 37859.6997007201,
95776.7134924707, 4.26169500086318, 3.5698851347798, 86443.0669724643,
34605.6348331311, 19428.9925446595, 39862.6880299974, 35404.0775153148
), Skewness = c(-250.617389105408, -92.0497111543712, -222.048127362056,
-306.345949901831, 159.721951826032, 176.946213933641, -184.641362838581,
-308.496459206091, -0.0554031572191158, 0.663657035682233, 292.277707195227,
-168.280438021879, 123.094391969597, 185.1456106848, 0.325596112495694
)), row.names = c(NA, -15L), class = "data.frame")
Upvotes: 2
Views: 927
Reputation: 887148
We can do
library(dplyr)
df1 %>%
mutate_if(is.numeric, ~ case_when(. < 2 ~ round(., 2), TRUE ~ ceiling(.)))
Upvotes: 3