Rstudio OverView
we have 4 panes1) script pan - to write and save the programing script2) Console pane - where all the code will get executed3) Environment/history pane - displays all the variables created,functionsused with in the current session4) Helper pane - contains multiple tabs to install/display pacakges,view visualization plots,locate files within the workspace
In [1]:
help(mean)
getting and setting workspace
In [2]:
# to display current working directory use getwd() functiongetwd()
'C:/Users/Suresh/mlclassscripts' In [ ]:
# to set up workspace or working directory use setwd() function#syntax is shown belowsetwd(&quot;path&quot;)
In [6]:
setwd(&quot;C:\\Suresh\\R&amp;D\\Projects\\ML classroom training\\sessions&quot;)setwd(&quot;C:/Suresh/R&amp;D/Projects/ML classroom training/sessions&quot;)
getting help in R
To get help within R environment, we use help() function to get thedocumentationfor any of the functions/packages available within R environment.To see the arguments required for a function, we use args() function.to see the example of a function, example() function is used.
In [ ]:
help(&quot;stats&quot;)help(&quot;mean&quot;)args(&quot;mean&quot;)example(&quot;mean&quot;)#getting help documentation for a packagehelp(package=&quot;caret&quot;)
online help for R programming
We can get online help on available packages in R from official website of R-Cranhttps://cran.r-project.org/web/views/
We can also get online support for our day to day activities from below websites:https://stackoverflow.com/https://stats.stackexchange.com
Installing Packages
In [ ]:
#install pacakges in R can be done in two ways,#1) using install.packages() function and from the bottom right pane of Rstudioinstall.packages(&quot;randomForest&quot;)#loading of installed or downloaded packages can be done using library() function. #Note that we can only load the package if# we have installed the package already within our R environmentlibrary(cluster)
In [ ]:
#below code to first verify if the library is installed in the R environment, #if it is not available# then the package will get installed.if(!library(cluster)){install.pacakges(&quot;cluster&quot;)}
basic operations in R
In [ ]:
# Adding two numericals1+1#multiplying two numericals10*2#dividing two numericals10/2#applying modulus operation on two numericals10%%2
printing results to R console
In [ ]:
#printing the data on the consoleprint(10*2)print(&quot;data science&quot;)print(pi^2)
Variable declaration and assignment in R
variable assignment: In the below example, we are creating variable named z:
In [8]:
z