Reputation: 520
I want to calculate the average number of hits by the players in the NL East in 2019 who started the most games at each position. There are 40 players in the NLeast_starters dataset and the average number of hits is 123.75, but when I run my R code I am getting only 124 as the result. The decimal places are not displaying.
sum3 <- NLeast_starters %>% summarize(mean_hits = round(mean(H),5))
Here is my input:
> dput(NLeast_starters)
structure(list(Team = structure(c(3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L), .Label = c("Braves", "Marlins", "Mets", "Nats", "Phils"), class = "factor"),
Pos = structure(c(4L, 1L, 2L, 8L, 3L, 6L, 5L, 7L, 4L, 1L,
2L, 8L, 3L, 6L, 5L, 7L, 4L, 1L, 2L, 8L, 3L, 6L, 5L, 7L, 4L,
1L, 2L, 8L, 3L, 6L, 5L, 7L, 4L, 1L, 2L, 8L, 3L, 6L, 5L, 7L
), .Label = c("1B", "2B", "3B", "C", "CF", "LF", "RF", "SS"
), class = "factor"), Name = structure(c(39L, 29L, 31L, 2L,
35L, 15L, 20L, 25L, 16L, 30L, 9L, 17L, 23L, 3L, 33L, 8L,
37L, 12L, 28L, 11L, 19L, 5L, 32L, 27L, 40L, 24L, 7L, 36L,
4L, 21L, 38L, 1L, 18L, 13L, 34L, 26L, 6L, 10L, 22L, 14L), .Label = c("Adam Eaton",
"Amed Rosario", "Andrew McCutchen", "Anthony Rendon", "Austin Riley",
"Brian Anderson", "Brian Dozier", "Bryce Harper", "Cesar Hernandez",
"Curtis Granderson", "Dansby Swanson", "Freddie Freeman",
"Garrett Cooper", "Harold Ramirez", "J.D. Davis", "J.T. Realmuto",
"Jean Segura", "Jorge Alfaro", "Josh Donaldson", "Juan Lagares",
"Juan Soto", "Lewis Brinson", "Maikel Franco", "Matt Adams",
"Michael Conforto", "Miguel Rojas", "Nick Markakis", "Ozzie Albies",
"Pete Alonso", "Rhys Hoskins", "Robinson Cano", "Ronald Acuna Jr.",
"Scott Kingery", "Starlin Castro", "Todd Frazier", "Trea Turner",
"Tyler Flowers", "Victor Robles", "Wilson Ramos", "Yan Gomes"
), class = "factor"), Age = c(31L, 24L, 36L, 23L, 33L, 26L,
30L, 26L, 28L, 26L, 29L, 29L, 26L, 32L, 25L, 26L, 33L, 29L,
22L, 25L, 33L, 22L, 21L, 35L, 31L, 30L, 32L, 26L, 29L, 20L,
22L, 30L, 26L, 28L, 29L, 30L, 26L, 38L, 25L, 24L), G = c(141L,
161L, 107L, 157L, 133L, 140L, 133L, 151L, 145L, 160L, 161L,
144L, 123L, 59L, 126L, 157L, 85L, 158L, 160L, 127L, 155L,
80L, 156L, 116L, 97L, 111L, 135L, 122L, 146L, 150L, 155L,
151L, 130L, 107L, 162L, 132L, 126L, 138L, 75L, 119L), PA = c(524L,
693L, 423L, 655L, 499L, 453L, 285L, 648L, 593L, 705L, 667L,
618L, 428L, 262L, 500L, 682L, 310L, 692L, 702L, 545L, 659L,
297L, 715L, 469L, 358L, 333L, 482L, 569L, 646L, 659L, 617L,
656L, 465L, 421L, 676L, 526L, 520L, 363L, 248L, 446L), AB = c(473L,
597L, 390L, 616L, 447L, 410L, 258L, 549L, 538L, 570L, 612L,
576L, 389L, 219L, 458L, 573L, 271L, 597L, 640L, 483L, 549L,
274L, 626L, 414L, 314L, 310L, 416L, 521L, 545L, 542L, 546L,
566L, 431L, 381L, 636L, 483L, 459L, 317L, 226L, 421L), R = c(52L,
103L, 46L, 75L, 63L, 65L, 38L, 90L, 92L, 86L, 77L, 79L, 48L,
45L, 64L, 98L, 36L, 113L, 102L, 77L, 96L, 41L, 127L, 61L,
36L, 42L, 54L, 96L, 117L, 110L, 86L, 103L, 44L, 52L, 68L,
52L, 57L, 44L, 15L, 54L), H = c(136L, 155L, 100L, 177L, 112L,
126L, 55L, 141L, 148L, 129L, 171L, 161L, 91L, 56L, 118L,
149L, 62L, 176L, 189L, 121L, 142L, 62L, 175L, 118L, 70L,
70L, 99L, 155L, 174L, 153L, 139L, 158L, 113L, 107L, 172L,
137L, 120L, 58L, 39L, 116L), X2B = c(19L, 30L, 28L, 30L,
19L, 22L, 12L, 29L, 36L, 33L, 31L, 37L, 17L, 12L, 34L, 36L,
11L, 34L, 43L, 26L, 33L, 11L, 22L, 25L, 16L, 14L, 20L, 37L,
44L, 32L, 33L, 25L, 14L, 16L, 31L, 29L, 33L, 17L, 9L, 20L
), X3B = c(0L, 2L, 0L, 7L, 2L, 1L, 1L, 1L, 3L, 5L, 3L, 4L,
0L, 1L, 4L, 1L, 3L, 2L, 8L, 3L, 0L, 1L, 2L, 2L, 0L, 0L, 0L,
5L, 3L, 5L, 3L, 7L, 1L, 1L, 4L, 1L, 1L, 1L, 1L, 3L), HR = c(14L,
53L, 13L, 15L, 21L, 22L, 5L, 33L, 25L, 29L, 14L, 12L, 17L,
10L, 19L, 35L, 11L, 38L, 24L, 17L, 37L, 18L, 41L, 9L, 12L,
20L, 20L, 19L, 34L, 34L, 17L, 15L, 18L, 15L, 22L, 5L, 20L,
12L, 0L, 11L), RBI = c(73L, 120L, 39L, 72L, 67L, 57L, 27L,
92L, 83L, 85L, 71L, 60L, 56L, 29L, 55L, 114L, 34L, 121L,
86L, 65L, 94L, 49L, 101L, 62L, 43L, 56L, 50L, 57L, 126L,
110L, 65L, 49L, 57L, 50L, 86L, 46L, 66L, 34L, 15L, 50L),
SB = c(1L, 1L, 0L, 19L, 1L, 3L, 4L, 7L, 9L, 2L, 9L, 10L,
0L, 2L, 15L, 15L, 0L, 6L, 15L, 10L, 4L, 0L, 37L, 2L, 2L,
0L, 3L, 35L, 5L, 12L, 28L, 15L, 4L, 0L, 2L, 9L, 5L, 0L, 1L,
2L), CS = c(0L, 0L, 0L, 10L, 2L, 0L, 1L, 2L, 1L, 2L, 2L,
2L, 0L, 1L, 4L, 3L, 0L, 3L, 4L, 5L, 2L, 2L, 9L, 0L, 0L, 0L,
4L, 5L, 1L, 1L, 9L, 3L, 4L, 0L, 2L, 5L, 1L, 3L, 1L, 1L),
BB = c(44L, 72L, 25L, 31L, 40L, 38L, 22L, 84L, 41L, 116L,
45L, 30L, 36L, 43L, 34L, 99L, 31L, 87L, 54L, 51L, 100L, 16L,
76L, 47L, 38L, 20L, 61L, 43L, 80L, 108L, 35L, 65L, 22L, 33L,
28L, 32L, 44L, 41L, 13L, 18L), SO = c(69L, 183L, 69L, 124L,
106L, 97L, 75L, 149L, 123L, 173L, 100L, 73L, 61L, 55L, 147L,
178L, 105L, 127L, 112L, 124L, 155L, 108L, 188L, 59L, 84L,
115L, 105L, 113L, 86L, 132L, 140L, 106L, 154L, 110L, 111L,
62L, 114L, 98L, 74L, 91L), BA = c(0.288, 0.26, 0.256, 0.287,
0.251, 0.307, 0.213, 0.257, 0.275, 0.226, 0.279, 0.28, 0.234,
0.256, 0.258, 0.26, 0.229, 0.295, 0.295, 0.251, 0.259, 0.226,
0.28, 0.285, 0.223, 0.226, 0.238, 0.298, 0.319, 0.282, 0.255,
0.279, 0.262, 0.281, 0.27, 0.284, 0.261, 0.183, 0.173, 0.276
), OBP = c(0.351, 0.358, 0.307, 0.323, 0.329, 0.369, 0.279,
0.363, 0.328, 0.364, 0.333, 0.323, 0.297, 0.378, 0.315, 0.372,
0.319, 0.389, 0.352, 0.325, 0.379, 0.279, 0.365, 0.356, 0.316,
0.276, 0.34, 0.353, 0.412, 0.401, 0.326, 0.365, 0.312, 0.344,
0.3, 0.331, 0.342, 0.281, 0.236, 0.312), SLG = c(0.416, 0.583,
0.428, 0.432, 0.443, 0.527, 0.326, 0.494, 0.493, 0.454, 0.408,
0.42, 0.409, 0.457, 0.474, 0.51, 0.413, 0.549, 0.5, 0.422,
0.521, 0.471, 0.518, 0.42, 0.389, 0.465, 0.43, 0.497, 0.598,
0.548, 0.419, 0.428, 0.425, 0.446, 0.436, 0.379, 0.468, 0.356,
0.221, 0.416), OPS = c(0.768, 0.941, 0.736, 0.755, 0.772,
0.895, 0.605, 0.856, 0.82, 0.819, 0.741, 0.743, 0.705, 0.834,
0.788, 0.882, 0.733, 0.938, 0.852, 0.748, 0.9, 0.75, 0.883,
0.776, 0.704, 0.741, 0.771, 0.85, 1.01, 0.949, 0.745, 0.792,
0.736, 0.791, 0.736, 0.71, 0.811, 0.637, 0.457, 0.728), OPS. = c(107L,
148L, 96L, 102L, 106L, 138L, 63L, 128L, 108L, 110L, 91L,
90L, 80L, 115L, 100L, 125L, 86L, 136L, 114L, 89L, 127L, 86L,
122L, 98L, 78L, 83L, 95L, 113L, 153L, 138L, 88L, 101L, 95L,
110L, 94L, 90L, 114L, 69L, 24L, 93L), TB = c(197L, 348L,
167L, 266L, 198L, 216L, 84L, 271L, 265L, 259L, 250L, 242L,
159L, 100L, 217L, 292L, 112L, 328L, 320L, 204L, 286L, 129L,
324L, 174L, 122L, 144L, 179L, 259L, 326L, 297L, 229L, 242L,
183L, 170L, 277L, 183L, 215L, 113L, 50L, 175L), GDP = c(16L,
13L, 16L, 13L, 9L, 14L, 8L, 11L, 12L, 10L, 9L, 11L, 14L,
1L, 3L, 10L, 8L, 17L, 2L, 7L, 13L, 4L, 8L, 11L, 7L, 7L, 11L,
10L, 13L, 11L, 6L, 8L, 12L, 10L, 23L, 15L, 15L, 3L, 8L, 8L
), HBP = c(4L, 21L, 5L, 3L, 12L, 3L, 2L, 10L, 5L, 11L, 6L,
8L, 0L, 0L, 5L, 6L, 6L, 6L, 4L, 5L, 8L, 5L, 9L, 2L, 5L, 2L,
4L, 3L, 12L, 3L, 25L, 13L, 10L, 5L, 3L, 5L, 14L, 3L, 6L,
5L), SH = c(0L, 0L, 0L, 2L, 0L, 0L, 2L, 0L, 0L, 0L, 0L, 1L,
0L, 0L, 1L, 0L, 0L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 6L, 9L, 0L, 0L, 0L, 1L, 0L, 0L, 2L, 0L), SF = c(3L,
3L, 3L, 3L, 0L, 2L, 1L, 5L, 8L, 6L, 4L, 3L, 3L, 0L, 2L, 4L,
2L, 2L, 4L, 5L, 2L, 2L, 1L, 6L, 1L, 1L, 1L, 2L, 9L, 6L, 5L,
3L, 2L, 2L, 9L, 5L, 3L, 2L, 1L, 1L), IBB = c(5L, 6L, 3L,
2L, 1L, 2L, 4L, 5L, 2L, 6L, 4L, 1L, 19L, 0L, 1L, 11L, 3L,
11L, 6L, 2L, 2L, 3L, 4L, 1L, 6L, 1L, 2L, 2L, 8L, 3L, 3L,
0L, 1L, 0L, 2L, 2L, 1L, 1L, 1L, 1L)), class = "data.frame", row.names = c(NA,
-40L))
I have reviewed other posts and have not found one whose answer worked for me.
Upvotes: 0
Views: 1826
Reputation: 388907
The issue is with settings in your environment which controls number of digits to be displayed while printing which can be changed by running options(digits = 5)
or any higher number (upto 22) in the console.
From ?options
digits: controls the number of significant (see signif) digits to print when printing numeric values. It is a suggestion only. Valid values are 1...22 with default 7.
After doing that if you run
library(dplyr)
NLeast_starters %>% summarize(mean_hits = round(mean(H),5))
# mean_hits
#1 123.75
you'll get the expected display of decimal places.
Upvotes: 1