Execute basic mathematical; and statistical operations in R
Step1: Create R code chunks
Step2: Write math expressions
Step3: Run the chunk codes
Step4: Report the results
In this experiment basic mathematical operations will be tested using R
# addition
a=10;
b=125;
total=a+b;
total;
## [1] 135
x=425;
y=345;
x-y;
## [1] 80
a1=34;
a2=5.4;
s=prod(a1,a2);
paste0("Product of ",a1," and ",a2, " is ",s);
## [1] "Product of 34 and 5.4 is 183.6"
c=32;
d=6;
qu=c/d;
qu;
## [1] 5.333333
rem=c%%d;
rem;
## [1] 2
r=32;
s=2;
d=r%/%s;
d;
## [1] 16
a=5;
b=5^2;
b;
## [1] 25
v=1:10;
v^10;
## [1] 1 1024 59049 1048576 9765625 60466176
## [7] 282475249 1073741824 3486784401 10000000000
ar=c(1,5,7,9,21);
5*ar;
## [1] 5 25 35 45 105
br=c(1,4,1,2,8);
ar;br;ar*br;
## [1] 1 5 7 9 21
## [1] 1 4 1 2 8
## [1] 1 20 7 18 168
floor(3.1427)
## [1] 3
ceiling(.6879)
## [1] 1
factorial(10)
## [1] 3628800
To find \(nCr=\frac{n!}{r!(n-r)!}\)
choose(5,3)
## [1] 10
Permutation can be found using :\(^n P_r=n\times(n-1) \times \cdots \times (n-r+1)\)
prod(10:(10-4+1))
## [1] 5040
Names=c("Ben","Alice","Jiju","Jilu","Libin","Abin")
Age=c(18,21,19,23,32,30)
Salary=c(23000,18000,21000,35000,40000,45000)
Data=data.frame(Names,Age,Salary)
Data
## Names Age Salary
## 1 Ben 18 23000
## 2 Alice 21 18000
## 3 Jiju 19 21000
## 4 Jilu 23 35000
## 5 Libin 32 40000
## 6 Abin 30 45000
Data$Names[1:3]
## [1] "Ben" "Alice" "Jiju"
Data$Names[1]
## [1] "Ben"
mean(Data$Age)
## [1] 23.83333
Basic Maths and Stao are implemented using R Language.