Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
Creating data frames
Feature engineering


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:

period avg_price conversion_rate
Q1 2017 170195 1.2
Q2 2017 173937 1.2
Q3 2017 177938 1.2

If the 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.


Chris noticed that his dataset doesn't have any information about the number of bathrooms in each house. Add a new column called bathrooms to the houses data frame and set its value to 1.