4 R vs Python
- Assignment operator
- Start index
-
R operator:
$
-
Python operator:
.
- Indentation
- Libraries
4.2 Assignment operator: Both
x = 5
y = 7
w = x
z = y
cat('x = ', x, '\n')
x = 5
cat('y = ', y, '\n')
y = 7
cat('w = ', w, '\n')
w = 5
cat('nz = ', z, '\n')
nz = 7
4.6 Dot operator in Python
= 'I am a string variable'
x
print('Title Case of the string x is: ', x.title())
Title Case of the string x is: I Am A String Variable
print('Number of occurrences of a in the string x is: ', x.count('a'))
Number of occurrences of a in the string x is: 4
4.7 Indent in Python
= 20
x
if x % 2 == 0:
print('The number ', x, ' is EVEN')
else:
print('The number ', x, ' is ODD')
The number 20 is EVEN
4.8 Libraries
R base
includes many functions available to use instantly without installing any libraries
install.packages('ggplot2)
library(ggplot2)
Python needs installation of libraries for efficient usage
pip install matplotlib
import matplotlib.pyplot as plt
4.9 Object orientation
R has in-built object orientation framework, but one can do most of the standard jobs by using R as a procedural language.
Python object orientation framework is similar to other programs like C, C++, and hence easy to implement. Many standard pipeline can be developed seamlessly using classes in Python.