library(tidyverse)── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr 1.2.1 ✔ readr 2.2.0
✔ forcats 1.0.1 ✔ stringr 1.6.0
✔ ggplot2 4.0.3 ✔ tibble 3.3.1
✔ lubridate 1.9.5 ✔ tidyr 1.3.2
✔ purrr 1.2.2
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag() masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(dslabs)
path <- system.file("extdata", package="dslabs")
filename <- file.path(path, "fertility-two-countries-example.csv")
wide_data <- read.csv(filename)
head(wide_data) country X1960 X1961 X1962 X1963 X1964 X1965 X1966 X1967 X1968 X1969 X1970
1 Germany 2.41 2.44 2.47 2.49 2.49 2.48 2.44 2.37 2.28 2.17 2.04
2 South Korea 6.16 5.99 5.79 5.57 5.36 5.16 4.99 4.85 4.73 4.62 4.53
X1971 X1972 X1973 X1974 X1975 X1976 X1977 X1978 X1979 X1980 X1981 X1982 X1983
1 1.92 1.80 1.70 1.62 1.56 1.53 1.50 1.49 1.48 1.47 1.47 1.46 1.46
2 4.41 4.27 4.09 3.87 3.62 3.36 3.11 2.88 2.69 2.52 2.38 2.24 2.11
X1984 X1985 X1986 X1987 X1988 X1989 X1990 X1991 X1992 X1993 X1994 X1995 X1996
1 1.46 1.45 1.44 1.43 1.41 1.38 1.36 1.34 1.32 1.31 1.31 1.31 1.32
2 1.98 1.86 1.75 1.67 1.63 1.61 1.61 1.63 1.65 1.66 1.65 1.63 1.59
X1997 X1998 X1999 X2000 X2001 X2002 X2003 X2004 X2005 X2006 X2007 X2008 X2009
1 1.33 1.34 1.35 1.35 1.35 1.35 1.35 1.35 1.35 1.36 1.36 1.37 1.38
2 1.54 1.48 1.41 1.35 1.30 1.25 1.22 1.20 1.20 1.20 1.21 1.23 1.25
X2010 X2011 X2012 X2013 X2014 X2015
1 1.39 1.40 1.41 1.42 1.43 1.44
2 1.27 1.29 1.30 1.32 1.34 1.36