We provide effective and economically affordable training courses for R and Python, Click here for more details and course registration !
When R software and RStudio program have been installed on your computer, R working session can be simply started by clicking the RStudio app from your Windows start menu.
- RStudio working interface
There are four windows in RStudio working interface.
The Script window on the top is for writing run commands in script file. You can start an empty script R file and save on your project working location. You can also open your script file when you come back working with your project. There are flexible ways of running script files in R. You can highlight several rows of commands in script files and click RUN button, or you can just run the whole files by clicking RUN button.
The Console window on the bottom is for enter individual interactive commands at the command prompt (>) and showing results. Note that by running commands in Script window, results will be show in Console window too.
On the right side of RStudio working interface can we see Environmen and history window: Environment window shows any objects that were created in the current R working session. When you start RStudio first time, it is empty there. And there are also records of executed commands shown in the History menu.
On the bottom of the right side is the Plot window. All the results of plots will be shown there. The toolbar in Plot window makes it also available to zoom or save the graphs generated.
2. Manage R working session
You can show the current working directory by using getwd() function.
#show current working directory
> getwd()
[1] "C:/Users/Wilso/Documents"
You can set new working directory by using setwd() function.
#setting new working directory
> setwd("D:\\RStatistics-Tutorial")
#show current working directory again
> getwd()
[1] "D:/RStatistics-Tutorial"
ls() function is used to show all the objects in the current R working session.
#create a vector
> a <- c(1:10)
> a
[1] 1 2 3 4 5 6 7 8 9 10
#show all the objects in the current working session
> ls()
[1] "a"
rm() function is used to remove an object.
#remove an object
> rm(a)
> a
Error: object 'a' not found
save.image(File) is used to save work session into a R workspace file (.RData).
load(“File”) is used to load a saved R workspace into current working session.
#to save workspace (all the objects, etc) into an R workspace
#file on current working directory
> save.image("RTest.RData")
#to load an saved R workspace file into current working
#directory. So you can use all the objects saved.
> load("RTest.RData")
#to show an object
> a
[1] 1 2 3 4 5 6 7 8 9 10
You can also watch full video on R fundamental tutorials from our YouTube channel.
0 Comments