Great! Let's take a look at how we can create a new column in the
quarter_prices data frame. Currently, the
quarter_prices table stores historical average housing prices expressed in Euros. Let's create an additional column for the conversion rate between Euros and USD. We'll use today's conversion rate of
1.20 (EUR to USD) for all observations.
You can create a new column by using the
$ operator, followed by the name of the new column you wish to create:
quarter_prices$conversion_rate <- 1.20
When this expression is invoked, R will create a new column named
conversion_rate at the end of the data frame, and it will populate that newly created column with the value 1.20.
All rows will have same value stored in that column. Our data frame
quarter_prices will look like this:
conversion_rate column had already existed in the data frame, R would've overwritten the existing column values. Be careful when creating new columns so you don't accidentally replace existing data.