Why "Non-Programmers" Will Dominate Business In 2017
######################################################################
## DON'T PANIC!! Take a deep breath...
## What you're looking at is computer code written in R.
## If you're the type of person who steers clear of anything programming
## this article is for you!
## Yeah, you... I know I caught you off guard...
## You're probably on your phone. So walk to the nearest
## computer and let's get going.
##
## To answer your first question, those "#"s to the left and at the top
## are characters that tell the computer that the text that follows will be
## ignored. They allow me to type whatever I want without worrying that
## the computer will do something crazy...
## Like... COMPUTER, DELETE ALL OF MY FILES...........
## Take another deep breath, absolutely nothing can happen until you put
## this text into R and let it crunch away. And even then, you're safe.
##
## OK, now that you know what you're getting yourself into,
## let me add a nice title to the project.
######################################################################
######################################################################
##
## Project: R Tutorial For Beginners
## Created By: Kurt Boden
## Date: 20170113
##
## Description:
## Quick code-interactive R tutorial for people who:
## -have never done any programming.
## -want to enhance their resume.
## -want to automate some annoying tasks.
##
## This is intended for people of every background.
## DON'T BE INTIMIDATED!!!! This will be fun.
##
######################################################################
##
## SECTION 1: Installing R
##
## If you already have R installed, then you can move to SECTION 2.
## If you don't, here's how to do it.
##
## It's a pretty straightforward process.
## Just paste the link below into your browser.
## Notes before you begin:
## If you're running windows, use the
## sections "Installing R on Windows" and "Installing RStudio"
## and ignore everything else. (Or read it... that's cool too.)
## If you're using Mac OS, use "Installing R on Mac OS X" and "Installing RStudio"
## and ignore everything else. (Again, read what you want, it's your life.)
## If you're running something else... you're way too lame to need this tutorial...
## Note: I have you install RStudio because it simplifies a lot of stuff later.
## OK, here's the link:
## https://socserv.mcmaster.ca/jfox/Courses/R/ICPSR/R-install-instructions.html
##
## Congrats! That was way easier than you thought, right?
## Or you're reading ahead...
## Just go back and do it. It's worth it.
##
######################################################################
##
## SECTION 2: RStudio Basics
##
## Welcome to RStudio!
## If you've made it this far, you are ahead of about 95% of your competition!
## CONGRATS!!
##
## To simplify this tutorial, copy and paste all of the text from this
## article into RStudio.
## If you don't have an R Script open, open RStudio and go to
## the icon in the upper left (with the green plus sign) and select "R Script".
## (I think if I direct you to that icon, it will be the same for Mac and Windows.)
## (I should probably be saying, go to File>>New File>>R Script... but...
## you get it.)
## Now you can copy all of the text from this article into your script.
##
## Everything will look a little different here...
## The basic settings in R will color all of the text to this point green.
## In programming jargon, these are called "comments". It's good to
## put these into your code every now and then to remind you
## how or why you did something. It's also helpful if you have to pass
## your code to someone else.
## You get it... I know... Just want to make sure... moving on.......
##
## OK, get ready to run your first line of code!
## Below is a print statement. This tells the computer to
## print whatever you put in the parantheses.
## Right now, all we have is ''
## To run the code in the line below, select the line and
## click "Run" in the upper right of this window. (It has the little green arrow.)
print('')
## Now look at the output in the bottom window.
## **Slow Clap** Great job!
## A blank line is pretty boring though... your computer is cooler than that.
## Next let's look at what badass programmers run... just run the code below.
print('Hello, World!')
## Look at the output in the bottom window again.
## **Claps Louder**
## Note: You are now a programmer. Congrats!
## (Google "Hello World" when you get a chance... but not now! Let's move on.)
## Next, I want you to write a statement below and have R print it.
## Maybe shoot for an introduction. Tell R to print
## "Hi my name is, ..." (to complete the introduction)
## Your statement should look something like this:
## print("Hi my name is, Kurt!")
## **APPLAUSE** You're on your way!
############## Errors in R ####################
## R, or any computer today for the most part, is pretty dumb.
## You need to tell it exactly what you want it to do.
## You have to be a little patient...
## Take a look at the next statement.
print(Hello, World!)
## If you ran the code above, you got an error message:
## Error: unexpected '!' in "print(Hello, World!"
## R doesn't know what you want it to do unless you put quotes
## around the sentence. We'll cover data types later
## just wanted to throw this out there
## Now fix the code above or RStudio will give you errors below.
## Or just delete the print statement... again, it's your life...
###############################################
## OK, now that we have the preliminaries out of the way, let's get mathy!
5+5
5-5
5*5
5/5
## As you can see, the code above is addition, subtraction,
## multiplication and division respectively.
## These are good to know but it's nothing too sexy yet.
## OK, here's a quick math test.
## Below, replace the "x"s to produce the number to the right.
x/4 ## = 1
x*5 ## = 20
x-1 ## = 3
x+18 ## = 22
## Run the code to check your answers.
## Amazing Work! I see greatness in you! Keep it up!!
## Note: The #s above comment out what follows (ie the "=...")
## so you don't have to worry about it messing up your
## precious code. ## Thank ## You ## Comments #########
## Now let's see if we can make this easier.
## Take your input value from above (((shhhh, it's 4)))
## and put it to the right of the "=" on the next line
x =
## It should look like this "x = 4". Make sure to run the code above.
## Instead of using the "=", you could also use an arrow "<-"
## but I think the equal sign makes it easier to think about.
## You just defined your first variable! This is the essence of all programming.
## Let the computer remember all of those little annoying things that
## a night of heavy drinking will make you forget.
## Or... um... a night where you do a lot of wholesome stuff.*
## Nah, we'll stick with the drinking. And we'll move on.
## I'm not funny.
## Note: When creating a variable, put the variable to the left of the
## "=" and the value you want it to hold to the right.
## Also, look in the upper right of the window. Do you see your
## newly defined variable?
## You remember that variable that we created above? x?
## Let's see what we can do with it.
x
x/4
x*5
x-1
x+18
## Run the code above (if you still aren't thinking for yourself)
## That really simplifies things, doesn't it? It's just the beginning!!
## Let's try another variable.
## "y" seems like a good choice. I'll let you choose the value.
## (Make it any number.)
y =
## After you choose "y", make sure you run the code.
## The computer doesn't know what "y" is until you tell it.
## Now let's see what happens when we bring x and y together.
x * y
x + y
x - y
x / y
## I really hope you didn't set y = zero...
## Please say you didn't choose zero...
## I know you did...
## #Curiosity
## (If you didn't, and you aren't curious, I encourage you to move on.)
## (Because you are no fun.)
## If you want to see what happens, go back and define y as zero.
## Which output looks strange and why? (Sometimes R is smart.)
## Moving along. What else can we store in our variables (x and y)?
## Let's try a string.
z <- "Kurt Boden is the world's greatest human."
print(z)
## QUESTION: What happens when we put quotes around z in the print statement?
## (It prints the string "z" rather than the variable z.)
## Just keep remembering that R is dumb...
zed <- "You are regretting doing this tutorial."
print(zed)
## It's almost over! Haha
## Run the next line
kurtisthebest <- 5
## Now print your new variable below
## Note: There are few restriction when it comes to making a variable.
## Just try not to define things like "+" as a variable.
## Or something like the number 4.
## Early on maybe just stick with x's and y's.
## Also, you just typed "kurtisthebest" into the print statement.
## I'm somewhere out there smiling to myself. : )
## OK, I think that is all for the first lesson. I hope you had fun!
## Really, getting this thing installed is the hardest part.
## Keep an eye out for the next installment!
## To let me know that you're looking forward to the next lesson,
## please go back to the post on LinkedIn and click Like.
## See you soon!
## KMB