I'm going to be lazy and assume that the base data_frame and the prediction are identical, but should work the same.
base <- tibble::tribble(
~Year, ~Population,
2010, 3759944,
2011, 3788379,
2012, 3818814,
2013, 3853214,
2014, 3878187,
2015, 3909500,
2016, 3926331,
2017, 3931316,
2018, 3940235,
2019, 3956971 #,
#4042171.32727273, 4064288.95757575 unsure about these
)
predicted <- tibble::tribble(
~Pred_year, ~Pred_Population,
2010, 3759944,
2011, 3788379,
2012, 3818814,
2013, 3853214,
2014, 3878187,
2015, 3909500,
2016, 3926331,
2017, 3931316,
2018, 3940235,
2019, 3956971 #,
#4042171.32727273, 4064288.95757575
)
cbind(base,predicted)
#> Year Population Pred_year Pred_Population
#> 1 2010 3759944 2010 3759944
#> 2 2011 3788379 2011 3788379
#> 3 2012 3818814 2012 3818814
#> 4 2013 3853214 2013 3853214
#> 5 2014 3878187 2014 3878187
#> 6 2015 3909500 2015 3909500
#> 7 2016 3926331 2016 3926331
#> 8 2017 3931316 2017 3931316
#> 9 2018 3940235 2018 3940235
#> 10 2019 3956971 2019 3956971
Created on 2020-04-09 by the reprex package (v0.3.0)
Everyone* starts off as a newbie in R
. Those who seem to have trouble getting traction, paradoxically, are already fluent in a different style of programming language.
One of the hard things to get used to in R
is the concept that everything is an object
that has properties. Some objects have properties that allow them to operate on other objects to produce new objects. Those are functions
.
Think of R
as school algebra writ large: f(x) = y, where the objects are f, a function, x, an object (and there may be several) termed the argument
and y is an object termed a value
, which can be as simple as a single number (aka an atomic vector
) or a very packed object with a multitude of data and labels.
And, because functions are also objects, they can be arguments to other functions, like the old g(f(x)) = y. (Trivia, this is called being a first class object.)
Although there are function objects in R
that operate like control statements in imperative/procedural language, they are best used "under the hood." As it presents to users interactively, R
is a functional programming language. Instead of saying
take this, take that, do this, then do that, then if the result is this one thing, do this other thing, but if not do something else and give me the answer
in the style of most common programming languages, R
allows the user to say
use this function to take this argument and turn it into the value I want for a result