Step 5: Create an R script
To create an R script go to the top left of the screen with the green + and click on the R Script tab in the menu.

This will give you a file called Untitled1, go to File > save as and save this blank file in your working directory, when you click save as the extension .R will be added to your filename e.g our file was saved as “test” and is now called test.R
Step 6: Write some code
To get used to the R language its useful to play around with built in functions first. Type the following text into your new R script and save it (you can use CTRL + S as a save shortcut):
a<-5
sqrt(a)
exp(a)
log(a)
Your Rstudio window should now look like this:

Here we are using assignment to store the number 5 as a variable we are calling a. To assign a number to a variable in R you need to use the <- operator.
Variable names can be anything you want – as long as they aren’t already being used as function names.
The next three commands will calculate the square root (sqrt) the exponential value (exp) and the log (log) of your saved variable a.
Step 7: Run the code
Below your script panel is the console panel, this is where the text results of your commands will be printed.
To run your commands first highlight them then click on “Run” (see below)

Looking at the console panel we can now see the results printed out:

We can also store more than one number as a variable in R, this time you need to use the c operator.To try this out add the following text to your script.
b <- c(8,5,6,7,1,12,23,90)
Highlight the line and click Run to store these numbers as the variable b.To print the contents of variable b you can type b into the console panel. Your Rstudio window should look like this:
