R tutorial - The True Basics of R

Welcome to Data Camp: Your Gateway to Learning R

As a data scientist at Data Camp, I am excited to introduce you to our online data science school that offers fun video lessons, interactive coding challenges, and instant feedback. Our platform allows you to learn the skills of the future in the comfort of your browser, making it an ideal place to start your journey in data science.

The Basics of R: A Language for Statistical Computing

R is a programming language designed specifically for statistical computing, and it has become one of the most popular languages used by companies and universities around the globe. It's widely used in various fields such as financial portfolio optimization, marketing analytics, and clinical trials. What makes R so popular? Its ability to handle data structures with ease, creating beautiful plots, and having a vast number of packages that cater to different fields.

Specialization Capabilities: Building Beautiful Plots

R's specialization capabilities are top-notch, making it easy to build stunning visualizations. This feature is particularly useful for communicating complex data insights effectively. Additionally, R allows users to create so-called "packages," which are extensions to the language that provide additional functionality and features.

A Thriving Community: Thousands of Packages Created by Users

One of the key reasons for R's popularity is its active community. Thousands of packages have been created by users to address specific needs in various fields, making it an invaluable resource for data scientists. This demonstrates the language's flexibility and adaptability, allowing users to tackle a wide range of problems.

The Console: A Powerful Tool for Executing Commands

An important component of R is the console, where you can execute commands and interact with the data. The console provides an interactive interface that allows users to calculate sums, create variables, and manipulate data in real-time. This feature enables users to explore their data quickly and gain insights.

Variables: Storing Data for Later Use

In the console, you can create so-called "variables" by assigning values to them using the `<-` operator. For example, if the height of a rectangle is 2, you can assign this value to a variable called `height`. This allows users to store data and use it later in their scripts.

The Workspace: Accumulating Variables

As you create variables in your console, they accumulate in a workspace that serves as a central hub for storing and manipulating data. The workspace is easily accessible via the `LS` function, which displays a list of all variables currently stored there.

Accessing and Manipulating Data: Calculating Area

Once you've created variables, you can access and manipulate them to calculate results. For instance, if the height of your rectangle is 3 and its width is 6, you can calculate the area using these values. However, if you want to recalculate the area with new values for height and width, reassigning the variables in the console would require redundant coding.

The Role of Scripts: Automating Tasks

This is where scripts come into play – text files containing successive lines of code that automate tasks and streamline your workflow. You can create a script called `rectangle` that contains the code you've written up to this point, and then run it through the Data Camp interface. The console will execute every command one by one, just as if you were typing them yourself.

The Power of Scripts: Adapting Code

One of the coolest aspects of scripts is that you can change your code and re-run it without having to redo everything from scratch. This feature enables users to iterate quickly and refine their code until they achieve the desired results.

Interactive Exercises: Using the Console for Experimentation

To conclude, our platform offers a range of interactive exercises designed to help you experiment with R using the console. These exercises provide an opportunity for hands-on practice, allowing you to gain experience with different features and techniques while receiving tailored feedback on your mastery.

"WEBVTTKind: captionsLanguage: enhi my name is Philip and I'm a data scientist&nbsp;at data camp data camp is an online data science&nbsp;&nbsp;school it will take fun video lessons like the one&nbsp;you're watching now and solve interactive coding&nbsp;&nbsp;challenges where you receive instant and detailed&nbsp;feedback all of this happens in a comfort of your&nbsp;&nbsp;browser so you can immediately start learning&nbsp;the skill of the future in this introduction&nbsp;&nbsp;to our course you will learn about the basics&nbsp;of R as well as the most common data structures&nbsp;&nbsp;it uses to store data by the end of this course&nbsp;you will know how to create these data structures&nbsp;&nbsp;manipulate them and perform calculations on them&nbsp;to get surprising insights but first things first&nbsp;&nbsp;the basics of our it's also called the language&nbsp;for statistical computing and it's one of the&nbsp;&nbsp;most popular languages to do data science used&nbsp;by tons of companies and universities around&nbsp;&nbsp;the globe in all sorts of fields optimizing a&nbsp;financial portfolio or rapping marketing data&nbsp;&nbsp;or even analyzing outcomes of clinical trials&nbsp;you name it our can handle it but why did our&nbsp;&nbsp;become so popular well first of all it's really&nbsp;use next our specialization capabilities are&nbsp;&nbsp;top-notch making it easy to build beautiful plots&nbsp;it's also easy to create so-called packages which&nbsp;&nbsp;are extensions to our ARS very active community&nbsp;has created thousands of these packages for many&nbsp;&nbsp;different fields last but not least our is an&nbsp;actual programming language with a command-line&nbsp;&nbsp;interface for executing codes this is a big plus&nbsp;compared to other point-and-click programs out&nbsp;&nbsp;there it might take some energy to fully get the&nbsp;hang of it but fear not data camp is here to help&nbsp;&nbsp;you master our in no time let's get started an&nbsp;important component of our is the console it's&nbsp;&nbsp;a place where you can execute our commands and&nbsp;data games interactive interface the console can&nbsp;&nbsp;be found here let's try to calculate the sum of&nbsp;1 &amp; 2 we simply type 1 + 2 at the prompt in the&nbsp;&nbsp;console and hit enter our interprets what you&nbsp;typed and prints out results RS more than a&nbsp;&nbsp;scientific calculator do you can also create so&nbsp;called variables a variable allows you to store&nbsp;&nbsp;data and are for later use you can use the less&nbsp;than sign followed by - create a variable suppose&nbsp;&nbsp;the height of a rectangle is 2 let's assign this&nbsp;value 2 to a variable height in the console we&nbsp;&nbsp;type height less than sign - 2 this time-our&nbsp;does not print anything because it assumes that&nbsp;&nbsp;you will be using this variable in the future if&nbsp;you simply type an execute height in a console&nbsp;&nbsp;our returns - we can do a similar thing for the&nbsp;width of our imaginary rectangle we assign the&nbsp;&nbsp;value 4 to a variable width typing with gives&nbsp;us 4 great as you're assigning variables in&nbsp;&nbsp;your console you're actually accumulating the our&nbsp;workspace it's the place where our variables live&nbsp;&nbsp;you can list all variables with the LS function&nbsp;simply type LS followed by empty parentheses and&nbsp;&nbsp;it enter this shows you a list of all the&nbsp;variables you have created up to now there&nbsp;&nbsp;are two objects in your workspace at the moment&nbsp;height and width if we try to access a variable&nbsp;&nbsp;that is not in the workspace depth for example R&nbsp;will throw an error suppose you now want to find&nbsp;&nbsp;out the area of our imaginary rectangle which is&nbsp;height x with height equals 2 and width equals 4&nbsp;&nbsp;so the result is 8 it's also a sinus result to a&nbsp;new variable area inspecting the workspace again&nbsp;&nbsp;with LS shows that the workspace contains three&nbsp;objects now area height and width now this is&nbsp;&nbsp;all great but what if you want to recalculate the&nbsp;area if your imaginary rectangle when the height&nbsp;&nbsp;is 3 and width is 6 you'd have to reassign&nbsp;the variables width and height in a console&nbsp;&nbsp;and then recalculate the area that's quite some&nbsp;coding you'd have to redo isn't it this is the&nbsp;&nbsp;place where our scripts come in an our script&nbsp;is simply a text file with successive lines of&nbsp;&nbsp;our code let's create such script rectangle door&nbsp;that contains the code that we've written up to&nbsp;&nbsp;now next you can run the script and a data camp&nbsp;interface you can do this with the submit answer&nbsp;&nbsp;button our go is through your code line by line&nbsp;executing every command one by one and the console&nbsp;&nbsp;just as if you are typing each command yourself&nbsp;the cool thing is that if you want to change your&nbsp;&nbsp;code you can simply adapt your script and run it&nbsp;again let's change the height to tree and width&nbsp;&nbsp;to 6 and rerun the script the variables are given&nbsp;different values this time and the output changes&nbsp;&nbsp;accordingly now it's time for some interactive&nbsp;exercises use the console for experimentation&nbsp;&nbsp;and the our script editor for coding the actual&nbsp;answer when you hit submit answer your script will&nbsp;&nbsp;be executed and check for correctness datagrams&nbsp;tailored feedback will guide you to our mastery\n"