Transcript for:
Getting Started with R Studio

hello and welcome to hr analytics 101 today we're going to give you a quick practical beginners tour of the four panels in our studio so you can start focusing on analytics we'll first open r by clicking on the r studio icon in the taskbar if you don't see rstudio in your taskbar just go down to the search bar and start typing our studio when you open up rstudio you'll see four panels the panel on the upper left is the source panel this is where you'll write and save your code scripts in a script file which is basically a text file using saved scripts means you can always recreate your analyses the panel on the lower left is the console this is where you'll see the results of the code that you ran in the source panel you can also directly run r codes on the console this is really useful for checking results and working interactively with your data the panel on the upper right is the environment panel and that shows you the variables that you have available and finally the panel on the lower right has tabs for help packages and plots among others if you do not see a source panel and your opening view looks something like this don't worry it just means you have no script currently open you can create a new script by going to file selecting new file and then r-script and that will give you a new script in your source panel together you'll probably spend around 99 of your time in the source and console panels so let's step through a simple example to show you how to work in those panels together first we need to create a new script file so we go up to our file menu go to the first option which says new file then select our script just as we did before now i'm going to just create a simple variable which i'll call x and assign it to values of 1 through 100 i'll also create a second variable y which will be the cumulative sum of each element of x using the queue sum function now that i've written something i want to save it we can go up to the file menu and select save or we can just do a little ctrl s like we would with any other standard program okay so now we have something written and we've saved it but our still hasn't run anything yet we have to tell our studio to run the code before it will do anything with it to run our script we just highlight the lines we want to run go up to the code menu and select run selected lines when we do that voila our code is run i want you to first notice that we see our executed code down here in the console panel in fact i can now go directly into that console window and work interactively with those variables for example i can get the first six elements of our y variable with the head function i can also create new variables in the council i will create a new variable z and assign the value of the median of y when i type z in the console i get my result so big picture summary here use the source panel for scripting when you want to save your r code and run the commands again later use the console panel when you want to work with your data interactively now that you have a feel for the source and console panels let's go to the environment panel on the upper right you'll notice that this panel is showing the variables we just created including that z variable that we created in the console this shows us the name of the variable as well as some information about the object like it's an integer vector of length 100. if we want to start off with a clean environment we can just click the little broom here say yes that we're sure we want to get rid of everything and then we'll have a clean environment if i want to get those variables back i just go back into my script highlight and run those lines this time i'm using the ctrl enter shortcut and see that we have those values back in our environment although notice that that z variable won't be there because remember we created it interactively rather than as part of our script there are some other tabs here too including the one for importing data which i would encourage you to explore on your own but the environment tab is really the only one that i use regularly now let's move to this panel on the lower right which has several different tabs we'll start with the plots tab which shows us the results of any plot we make in the source panel or in the council for example i'm going to go to the console and plot my y variable which was the cumulative sum of the x values when i do that i see the results in the plots tab if i make a new plot say plot x you'll see the new plot there too if we want to go back and look at the previous plot we can just click on the little arrow you can clear these plots just by clicking on the little broom if these are plots that you want to run again later you can put these commands in the script and then run them from there instead and again you'll see them pop up in the window we also have a help tab which shows us the results of our help queries which we can get just by putting a little question mark in front of the function that we want the help for for example if i go down to the console panel and i type question mark print to get help on the print function my tab switch is over to help and shows me all kinds of information about the print function finally we'll take a look at the packages tab as a reminder the real power of r is a large set of libraries over 10 000 at this point each containing specialized functions to help you do your work so for example let's say i need a new package called psyc which i need for some statistics work but i don't have installed yet i would just go to the install button start typing psyc and when i see it click it and it installs so just a quick review of what we've learned so we have four panels we have the source panel where you're going to write all your scripts the console panel to see the results of your code and any of your interactive analyses the environment panel where you'll see the objects that you create and finally the panel on the lower right where you can see plots install packages and read the help files that wraps it up for today's overview of our studio thanks again for joining be sure to check out our other tutorials here and at hr analytics 101.com have a great day [Music] you