Call Girls In Hsr Layout ☎ 7737669865 🥵 Book Your One night Stand
Learning R
1. Learning R
Kamal Gupta Roy
Last Edited on Oct 17, 2021
Instructions / Agenda
1. Create Simple Arithmetic Operations. [+, -, *, /, ˆ, %%]
2. Create Logical Operation [<, >, < 1, > 1]
3. Built-in functions [sqrt, log, exp, floor, round, ceiling, abs]
4. Assignment of values to variables [a <- 2, b <- 3]
5. Retest arithmetic operations using variables
6. Saving arithmetic operations of two variables into a new variable
7. Introdution to Vector, vec <- c(23,4,12,78)
8. Finding values in the vectors using positions
9. Arithmetic Operations on vectors: addition, subtraction, multiplication
10. In built functions: mean(), median(), max(), min(), sort(), var(), sd(), cor, which.min and
which.max
11. Numeric Vector, Character Vector, combining the two, class function
12. creating a vector using function seq [seq(10,70,by=10), seq(10,70,length=10)], help on seq func-
tion
13. Directory functions [getwd(), setwd()]
14. Read a csv file; split columns into vectors and do some basic formulation
15. Exercises
Simple Arithmetic Operations
5 + 2
## [1] 7
5 * 2
## [1] 10
1
3. exp(2)
## [1] 7.389056
floor(2.467)
## [1] 2
round(2.467,2)
## [1] 2.47
ceiling(3.723)
## [1] 4
abs(-1)
## [1] 1
Assignment of Variables
a <- 2
b <- 7
a + b
## [1] 9
a - b
## [1] -5
a ˆ b
## [1] 128
c <- a ˆ b
c
## [1] 128
Vector Introduction
3
8. # Create a card vector as a character vector and a number vector c("Jack","King","Queen","Ace")
card <- c("Jack","King","Queen","Ace")
cardn <- c(11,13,12,14)
card
## [1] "Jack" "King" "Queen" "Ace"
cardn
## [1] 11 13 12 14
#Giving a name to the cardn vector
names(cardn) <- card
#Option 2:
cardn <- c("Jack" = 11,"King" = 13,"Queen" = 12,"Ace" = 14)
#Option 3:
cardn <- c(Jack = 11, King = 13, Queen= 12, Ace = 14)
Directory Details
#### workspace
ls()
## [1] "a" "b" "c" "card" "cardn" "chara" "comb" "i" "numb"
## [10] "quiz1" "quiz2" "rand" "s1" "s2" "vec" "x"
#To know what is the default working directory
getwd()
## [1] "C:/Users/Debzitt/Desktop"
# Setting a Working Directory using setwd()
#setwd(C:/Users/Admin/)
getwd()
## [1] "C:/Users/Debzitt/Desktop"
Read a csv file
df <- read.csv("veg_prices.csv")
df
8
9. ## ITEM QUANTITY UNIT_PRICE
## 1 Bangalore Tomato (Bangalore Thakkali) 3 17.44
## 2 Beans (Beans) 5 20.14
## 3 Beetroot (Beetroot) 5 14.05
## 4 Bitter Gourd (Pavakkai) 5 18.69
## 5 Bottle Gourd (Suraikai) 5 10.99
## 6 Brinjal (Kathirikkai) 5 11.99
## 7 Broad Beans (Avarakkai) 3 19.49
Calculate total bill from veg prices by splitting the dataframe into vectors
sum(df$QUANTITY * df$UNIT_PRICE)
## [1] 490.09
Exercises
Exercise 1
There are two sections. Assign random number to number of girls and number of boys in each
section. Calculate:
a. Total number of students in each section
b. Find out which section has more girls, boys and students
Exercise 2
Create a random numeric vector of atleast length of 10. Values should vary between 01-99.
Calculate:
a. what is the 5th value in the vector?
b. What is the last value in the vector?
c. What is the value of 3rd position from last?
d. what is the difference between 8th and 2nd value of the vector?
e. How many numbers are > 50?
f. How many numbers are more than average of the vector?
g. How many numbers are divisible by 3?
9
10. Exercise 3
Create a vector with marks in the class (atleast 10 numbers, varying between 00-99) all values
should be different.
a. What is the maximum value?
b. What is the minimum value?
c. What is the range?
d. What are the average marks?
e. If maximum value is replaced by 82, what is the new average? Is your average increased or decreased?
f. If another value 82 is added as a part of the vector, what is the new average? Is your average increased
or decreased?
Exercise 4
Calculate the following:
a. Find the sum of first 5 numbers
b. Find the sum of first 100 natural numbers. Use atleast two ways to find the sum
c. Find the difference between sum of numbers between 51-100 and 1-50
Exercise 5
Prisha invests Rs 68,000 at 9% rate per annum for a certain period. Calculate:
a. Total money Prisha gets after 5 years (Based on simple Interest)
b. Total money Prisha gets after 5 years (Based on compound Interest, if compounded annually)
Exercise 6
Aarav invests Rs 89,000 at 7% rate per annum for a two year lock-in period. Interest would be
calculated compounded annually. Aarav needed money after 1 year and 10 months to pay for his
college fees. He goes to the bank for withdrawl. Bank Manager told him that he would be given
money back based on simple interest calculation. Also, Bank would charge a penalty of 10% of
earned Interest.
a. How much money Aarav would get after penalty?
b. How much money he would have got more if he could wait for 2 more months?
10
11. Exercise 7
Need to solve the quadratic equation.
a. Give the roots of the equation, 2x2
+ 7x + 3 = 0
#finding the maturity amount if 10% interest is compounded every year
#n= time period
new1.function = function(faceValue,rOfInterest,n)
{
marketValue <- faceValue*(1+(rOfInterest/100))^n
print(marketValue)
}
new1.function(10000,10,10)
#finding the maturity amount if 10% is calculated is as simple interest on face value
new2.function = function(faceValue,rOfInterest,n)
{
marketValue <- faceValue + (faceValue*rOfInterest*n)/100
print(marketValue)
}
new2.function(10000,10,10)
11