Ph.D. Cpurse Work -2024 on Quantitative Methods

Day 1 material

———————————————————————–

# Data Structure: Vector (Elements with same data type)
# concatenate or combine
st=c("s1","s2","s3","s4")
marks=c(20.5,25,27,21)
marks
## [1] 20.5 25.0 27.0 21.0
# Quiz 1:How many digits R displays after decimal by default?

# Create sequence of integer - increment by 1
1:10
##  [1]  1  2  3  4  5  6  7  8  9 10
# Create sequence of integer - arbitrary increment
seq(1,20,.2)
##  [1]  1.0  1.2  1.4  1.6  1.8  2.0  2.2  2.4  2.6  2.8  3.0  3.2  3.4  3.6  3.8
## [16]  4.0  4.2  4.4  4.6  4.8  5.0  5.2  5.4  5.6  5.8  6.0  6.2  6.4  6.6  6.8
## [31]  7.0  7.2  7.4  7.6  7.8  8.0  8.2  8.4  8.6  8.8  9.0  9.2  9.4  9.6  9.8
## [46] 10.0 10.2 10.4 10.6 10.8 11.0 11.2 11.4 11.6 11.8 12.0 12.2 12.4 12.6 12.8
## [61] 13.0 13.2 13.4 13.6 13.8 14.0 14.2 14.4 14.6 14.8 15.0 15.2 15.4 15.6 15.8
## [76] 16.0 16.2 16.4 16.6 16.8 17.0 17.2 17.4 17.6 17.8 18.0 18.2 18.4 18.6 18.8
## [91] 19.0 19.2 19.4 19.6 19.8 20.0
# replicate the values in a vector
rep(c("A","B"),5)
##  [1] "A" "B" "A" "B" "A" "B" "A" "B" "A" "B"
# assignment

# Elements of a vector - One element, multiple elements
st[3]
## [1] "s3"
# Boolean vector

# Deselecting the vector elements
st[-3]
## [1] "s1" "s2" "s4"
# Types of Vector : numeric,integer,complex, character, logical, factor

# Factor denotes the categorical variable in the data
sub=c("Phy","Phy","Hist","Hist")
subFactor=factor(sub)
subFactor
## [1] Phy  Phy  Hist Hist
## Levels: Hist Phy
# Modification of type of a vector
 marks=as.character(marks)
# Length of a vector. 
length(st)
## [1] 4
# Quiz 2: Use length function to find out the last element of a vector.

# Numerical Operator - Vector Addition, subtraction, Multiplication, 
x = c(2.1, 5, -4, 1)
y = c(0, -7, 1, 1 / 4)
x
## [1]  2.1  5.0 -4.0  1.0
y
## [1]  0.00 -7.00  1.00  0.25
x+y
## [1]  2.10 -2.00 -3.00  1.25
x*y
## [1]   0.00 -35.00  -4.00   0.25
x*y
## [1]   0.00 -35.00  -4.00   0.25
# Minimum, Maximum, sum, product, cumulative sum of a vector
min(x)
## [1] -4
max(x)
## [1] 5
sum(x)
## [1] 4.1
prod(x)
## [1] -42
cumsum(x)
## [1] 2.1 7.1 3.1 4.1
cumprod(x)
## [1]   2.1  10.5 -42.0 -42.0
# Logical Operator 

# not, and ,or ,comparison, equality 

# paste function for character vectors

# Ordering and rank of vectors

# Matrix

# List

# dataframe

# Assign Car object into a new data frame

# nrow,ncol, dim, dimnames, names 

# Subset of data frame

# Keep all the variables fro 3rd observation

# keep the 2nd variables for all observations

# keep observations 1 to 5, 12 and 15

# remove observations 10 to 20.

# keep the last observation using nrow