Working with R:
R is a case-sensitive language. It differentiates between X and x . As X is capital letter while x is small letter.
We are writing program in Console window. Here , you are doing simple calculation as :
There is a disadvantage of R Console , we cannot save program codes in file . So , we can use more user friendly tool , the IDE ( Integrated Development Environment) for R i.e. Rstudio for coding and storing programs.
Working with Rstudio :
When we open Rstudio , it looks like -
We have three windows :
First window shows Console . Here , we can write and execute programs simultaneously.
Second window is upper right. It shows Environment and History window.
Third window is lower right. It shows Files , Plots , Packages, Help and Viewer windows.
We open a new window , called Script window.
For opening a Script window, click on File tab on upper left corner of Rstudio . Then , click on New File and click on R Script. It will look like -
Before writing your first program in Rstudio , we will see how to use Help. Type help() and pres ctrl +R(control + R) to run program. You can also use ctrl+Enter to run the program.
When we execute the code , it shows in console window to execute.
It will open Help window in bottom right window.
It helps us to find help in functions for programming.
Another code :-
By running this code, it opens Help window .It shows introduction of R.
Simple Calcluations in R
You can do simple calculation . Write this code in Script window -
Output will be shown in Console window:-
Similarly , you can do other calculations as-
Using Assignment Operator in R
We have use assignment operator as "<-" & "=" .
It is used to store the values . We can create object by assigning values to object.
In this program , we create an object named "a" , which store value 1.We are using assignment operator(<-) to assign value to object. We can see "a" object in Environment window. The object a stores 1.
Adding Comments in R
It is added to make program easier to understand . We can add comments by adding "#". It is non-executable code ( it is not execute by R).
You can check writing a comment !
Here , # object a creation is a comment . It gives explanation of our code.
Programming basic constraints :
We have two phases while running the program. It is compilation and execution.
Computer only reads binary form . When we run a program, first the program converts into machine understandable language in form of binary(0 or 1) source file. The process is called compilation. After compilation , the binary file is loaded into computer memory for execution .
Every code written in script window is compile and execute . But comments are ignored in compilation and execution.
We can store an object like this also -
b<-1 + 1
It will store 2.
To check "b" object value , we run this code-
It displays this output in console window -
We can remove objects from Environment window. We can do it by using rm() :-
You can checkout Environment window. There is no object "a" stored in it.
We can combine multiple values in an object by using c() .
It creates x object , which stores 1 and 2.
Contact at TJT@TechnicalJockey.com , if you are looking for an Instructor Based Online Training !
Reach out to us if you are looking for Corporate Training to Build The Next Generation Analytical Workforce with an in-depth understanding of Exploratory Data Analysis , Data Visualisation, Data Analytics , AI First , Machine Learning & Deep Learning Training & Consulting helping them to take Data Informed Decision at each stage of the business.
We understand that At the present times , the Entire Industry is in a Tranformation stage with the Softwares being rebuilt with Artificial Intelligence Capabilities .
We need SMART WORKFORCE for the SMART SOFTWARES to reap the maximum return .
Whatsapp at +91-9953805788 or email at - email@example.com if you would like to know more .