Ok, so here is my first post before we begin our Linear Regression, and it is going to be SUPER basic. We will be running our first line of code, and installing some “packages” that we will need for doing analytics-based project in R studio.
This post assumes that you have installed both R (the
programming language) and R Studio (the programming interface). We will be programming
in R Studio as it is easier—and prettier—than using the R tool.
If you haven’t installed both on your computer, I will
give you a link to my earlier posts for installing properly.
Install R and R studio, click here for post.
Once
that is finished, you may restart your computer, and log back into your home screen.
After you have logged back into your home screen, click on the START menu, then
in the search bar, type in “R Studio.” Then double-click on the R Studio icon.
You
will be brought to a home screen that is split into four sections:
The
Upper Left is where you will be typing your code.
The
Upper Right is where you will see the variables (also known as “objects”) that
you create.
The
Lower Left is known as the Console, and it is where you will see the “output”
of your code.
The
Lower Right window is where you will see the graphs that you create.
Before
we write our first snippet of code, let’s load a new project. Look at the upper
left corner of the screen where it says “File.” Click it. Scroll down to “New
Project” and select “R Script.” And BOOM! R will load a new project file for
you which you can save and rename. We will do this later.
Let’s
write your first bit of code! Everyone does this when they begin learning how
to code for the first time, but we are going to write a different bit of code.
Type the following into the Upper Left Window:
Never mind the text above the “print” statement. That is a “comment.” It is not part of the code. Any text after a “#” sign is considered a comment. R will ignore it when it is making its computations. Comments are to be used as a guide, to remind you and others what your code means.
I
included the comment to help you run the code. Type everything below, highlight the
code with your mouse by left-clicking and selecting the code, and finally, press
CTRL and ENTER to run the code. Notice that “Analytics for Porn Stars” is printed
below in the LOWER LEFT window.
In
essence, you can type ANYTHING you desire within the set of “” marks. Give it a
try. Be sure highlight your new piece of code, and then press CTRL and ENTER to
run your new code. Check the results in the LOWER LEFT WINDOW of R Studio.
This
is your first line of code, and you should be proud! It signifies that you are
taking steps in your lives to make significant changes. Out with the bad, and
in with the good! Your new lives, in a less toxic world, begin now!
Ok,
there are three more lines of code that we need to run before getting started
in our Regression Analysis.
We
need to “install” a package that will be super useful for our projects. It is
called “Tidyverse,” and it has pretty much everything we need from pragmatic
functions to data visualizations.
This is the code that you need to run to install Tidyverse:
I
should warn you that R is VERY sensitive. So be sure to type in the same way
that I have typed above. Use lower case and upper-case letters appropriately.
So,
once you run the code, R Studio will magically download the tidyverse package (you
MUST have an internet connection for this).
And
once you have successfully installed the package, you will never need to run
this command again. However, you will need to “load” the package into R Studio.
And I will show you how to do this now:
Every time you load a new project, you WILL need to use
this command to load necessary packages into R Studio. As we get further into
this blog, I will show you which packages will be necessary for our use case.
Finally, you can minimize out of R Studio by clicking
on the “_” button on the UPPER RIGHT CORNER of your screen.
We are now going to create a folder that you will use
when you are doing your R projects. This is important because you will need to use
this folder when you “set your working directory.” By setting your working
directory, R Studio can run the code more efficiently and find files on your computer
much faster.
If you are using Windows 11 (or even Windows 10) operating
system, you should be able to see a folder-looking icon on the bottom panel of
your screen. Left-mouse click it.
On the left side of the new window, you will see an
icon called “Documents.” Left-mouse click it.
Next, on the upper left part of the window, you will
see a “+” icon called “New.” Left-mouse click it and select “Folder.” Name the new
folder anything that is sensible and that you can remember. Naming the folder “R
Projects” might be such a name. There ya’ go!
I will show you how to “select your working directory”
in the next post, where it is more relevant.
You can right-mouse click on the R Studio icon on the lower
panel and click “Close All Windows.” This will allow you to exit R Studio.
THANK YOU!
Ok, so that is your first—very small—introduction into
R Studio and coding. This is a paramount first step in your journey, and I am
so excited for you. Continue to make healthier decisions in your life that will
lead you to less toxic outcomes in your social life, your professional life,
and even your love life.
I admire you all so much for making this transition. You are all very brave!
Thank you so much for allowing me to write educational content for you. Enjoy
the journey!