Learn more about connecting to databases with R: https://www.datacamp.com/courses/importing-data-in-r-part-2
Welcome to part two of importing data in R! The previous course dealt with accessing data stored in flat files or excel files. In a professional setting, you'll also encounter data stored in relational databases. In this video, I'll briefly talk about what a relational database is and then I'll explain how you can connect to it. In the next video, I'll explain how you can import data from it!
So, what's a relational database? There's no better way to show this than with an example. Take this database, called company. It contains three tables, employees, products and sales.
Like a flat file, information is displayed in a table format. The employees table has 5 records and three fields, namely id, name and started_at. The id here serves as a unique key for each row or record. Next, the products table contains the details on four products. We're dealing with data from a telecom company that's selling both with and without a contract. Also here, each product has an identifier. Finally, there's the sales table. It lists what products were sold by who, when and for what price. Notice here that the ids in employee_id and product_id correspond to the ids that you can find in the employees and products table respectively. The third sale for example, was done by the employee with id 6, so Julie. She sold the product with id 9, so the Biz Unlimited contract. These relations make this database very powerful. You only store all necessary information once in nicely separated tables, but can connect the dots between different records to model what's happening.
How the data in a relational database is stored and shuffled around when you make adaptations, depends on the so-called database management system, or DBMS you're using. Open-source implementations such as MySQL, postgreSQL and SQLite are very popular, but there are also proprietary implementations such as Oracle Database and Microsoft SQL server. Practically all of these implementations use SQL, or sequel, as the language for querying and maintaining the database. SQL stands for Structured Query Language.
Depending on the type of database you want to connect to, you'll have to use different packages. Suppose the company database I introduced before is a MySQL database. This means you'll need the RMySQL package. For postgreSQL you'll need RpostgreSQL, for Oracle, you'll use ROracle and so on. How you interact with the database, so which R functions you use to access and manipulate the database, is specified in another R package called DBI. In more technical terms, DBI is an interface, and RMySQL is the implementation. Let's install the RMySQL package, which automatically installs the DBI package as well. Loading only the DBI package will be enough to get started.
The first step is creating a connection to the remote MySQL database. You do this with dbConnect(), as follows.
The first argument specifies the driver that you will use to connect to the MySQL database. It sure looks a bit strange, but the MySQL() function from the RMySQL package simply constructs a driver for us that dbConnect can use. Next, you have to specify the database name, where the database is hosted, through which port you want to connect, and finally the credentials to authenticate yourself. This is an actual database that we're hosting, so you can try these commands yourself!
The result of the dbConnect call, con, is a DBI connection object. You'll need to pass this object to whatever function you're using to interact with the database. Before we do that, let's get familiar with this connection object in the exercises!
I love this edgy look! I was so excited that her hair, even as short as it is now, was still able to be put into the fun and trendy dutch pigtail braids! Instead of braiding to the ends, I ended them in close together pigtails at the nape of her neck. After I finished braiding, I tugged on the outsides of the braid gently to loosen them and make them a little messy and fun! Since she doesn’t have enough hair to tie around the elastics, I made sure to use elastics that matched her hair so they blend in as much as possible. You could also cover them with clips or bows! A view from the back of her Dutch pigtail braids! A great braid for short hair is a micro accent braid! My biggest tip for braiding short hair would be to add in small slices of hair rather than big ones. I did a small (micro) braid along a slightly curved deep part for anther cute and edgy look! You could also do another one next to it if you wanted a little more to the look, but I really liked how simple this one was. You can see how the part curves a little better from this view of the back. I ended the braid close to the head with an elastic that matched her hair. For our fourth style, we did a 3/4 french braid! Super simple but also super cute! You could do any type braid! It would also look cute using a Dutch braid or a fishtail braid! I loved the side view of this braid! I will for sure be doing this one next time she goes to gymnastics or swimming, whichever comes first! Our last braid is two four dutch lace braids into two loops in the back. Start off by parting the hair down the middle. On each side of the part, do a dutch lace braid, adding hair in from only the section closest to the part as you braid. Tie the braids together in the back with a small elastic and before you pull the hair all the way through to make a ponytail, leave it in a cute little loop! If the hair is a little bit longer, you could do a tiny bun. Repeat this directly under the braid you just did so you have two rows and two loops.
We will have to be coming up with lots more short hair braids in the future, so be sure to give us a follow over at our newly redesigned blog Abella’s Braids to see more as we do them!
Thanks for reading! See you again this time next month!
love these ideas! My daughter recently cut about 8 inches off her hair and is loving her shorter hair, but I’ve mostly been at a loss of what to do with it! Thanks!
Abella has been begging me for at least a year, probably closer to two years, to cut her hair. I posted a photo on Instagram with a question in the caption. “Abella has been begging me to cut her hair short, do you think I should let her do it?” Almost everyone said “YES!” So thanks to all of the good advice from my followers, we did it…and we haven’t regretted it for a second! I think she looks so cute and it really fits her personality! It’s for sure a lot harder to come up with braids but it’s pushed me to step out of my comfort zone! We wanted to show you that even if you have short hair, there are lots of cute braids you can still do!
This first braid (above) is three ladder braids. Start out with a part deep to one side. On the side with less hair, start out by doing a waterfall braid along the part. Under that one, do another waterfall braid, but incorporate the waterfall pieces from the one above it as you braid. Under that one, do a french braid. Incorporate the waterfall pieces from the second braid as you go. We braided each one to the ends and used elastics that matched her hair to tie them off.