Page 209 - Data Science class 11
P. 209
The first line shows the command and second shows the result of this command. In R or R studio, you can make
calculations by writing the arithmetic statement directly unlike other programming languages. The result is printed in
second line which shows the summation result after the line number in square bracket i.e. [1].
The third line shows the remarks put in by the programmer for her/his convenience. Anything written in a line after #
is taken as remarks by R. ‘#’ is used for adding comments to explain what the R code is about. You can add as many
comments as you need to clarify your code for yourself and other readers. Comments are necessary in long programs
th
th
th
for the programmer and the user both. The 5 line shows the result of subtraction. Similarly, rows 6 to 8 are
regarding multiplication operations and rows 9 to 11 are regarding division operations.
th
th
Remember here:
• That the result of the division operation produces a result which is not an integer, it has given infractions. Normally, R
th
will show the result up to the 8 decimal accuracy.
• After each operation, the R returns to the > mark known as the R prompt, which shows that the program is ready to
take the next instruction. But if the last instruction is not according to the rules, i.e., its syntax, it will show an error
message.
• The console window in RStudio is the place where you can tell it what to do and it will show the results of a command.
We can type commands directly into the console, but the drawback is that they will be forgotten when we
close the session.
• All programming languages have their own syntax, which is a system of rules to convert information—such as a
letter, word, sound, image, or gesture, according to the language’s syntax. The syntax is nearly identical to other
programming languages, but may slightly vary. The programming languages have evolved over the 1960s. Lisp,
Fortran IV, Basic, Cobol, C, C++, C.net, R, and Python are programming languages which have been designed for
different purposes. R was specially designed for data science purposes. In the R studio environment, you can do
programming in R as well as Python.
• A code snippet means a part of code that is self-sufficient when it is part of a bigger program, but when written in
part, for example, its purpose may get parsed during execution by the compiler.
• In computing, source code is any collection of code, with or without comments, written using a human-readable
programming language, usually as plain text. The source code of a program is specially designed to facilitate the
work of computer programmers, who specify the actions to be performed by a computer, mostly by writing source
code. The source code is often transformed by an assembler or compiler into binary machine code that can be
executed by the computer. The machine code might then be stored for execution at a later time. Alternatively, source
code may be interpreted and thus immediately executed. A snippet is a programming term for a small portion of
re-usable source code.
• A code lets you create a program. On the other hand, a script lets you control the program that you created with
coding.
• R programming is better suited for statistical learning, with unmatched libraries for data exploration and
experimentation. Python is a better choice for machine learning and large-scale applications, especially for data
analysis within web applications.
• Python and R are the two most popular programming languages for Data science. Python language has a more
general-purpose approach whereas R is used for statistical analysis. Python is used widely by software developers
breaking into data science whereas R is widely used in academia and finance sector, it is a perfect language for
statisticians.
Programming with R 207

