Hi. This is a newb question, but it's eating me up inside. Consider the following:
library(tidyverse)
bunch_of_years <- c(2002,1986,2017,1988,2008,1983,2008,1996,2004,2000,1994,1995,2015,1978,1974,2015,2016,1996,1983,1971,1981,1976,1998,2017,1979,1979,1993,2006,1988,1978,2013,1976,1979,1985,1985,2015,1962,1999,2015,1990,1992,1997,2018,2015,1997,2017,1982,1988,2006,2017)
Produces this vector...
bunch_of_numbers
[1] 2002 1986 2017 1988 2008 1983 2008 1996 2004 2000 1994 1995 2015 1978 1974 2015 2016 1996 1983 1971
[21] 1981 1976 1998 2017 1979 1979 1993 2006 1988 1978 2013 1976 1979 1985 1985 2015 1962 1999 2015 1990
[41] 1992 1997 2018 2015 1997 2017 1982 1988 2006 2017
And the mean...
mean(bunch_of_years)
[1] 1995.44
Great. Now, if I put those numbers into a tibble, like so...
A tibble: 50 x 2
ID year
1 1 2002
2 2 1986
3 3 2017
4 4 1988
5 5 2008
6 6 1983
7 7 2008
8 8 1996
9 9 2004
10 10 2000
... with 40 more rows
Look at the mean...
bunch_of_years %>% summarize(mean_year = mean(year))
A tibble: 1 x 1
mean_year
1 1995.
It is expressed as an integer, even though it says dbl. I'm following a text book that uses this code, and the mean the author derived from the tibble is 1995.44. Could someone explain why this is so, and how I can fix it? Thanks.