# House Keeping:
rm(list = ls())
setwd("/Users/bmishra/Dropbox/OSU/PhD/Fall 2021/STAT5193 SAS R/R/Assignments/Homework 2")
# txtsent = read.table(file = "clipboard", header = TRUE)[[4]]
# txtrec = read.table(file = "clipboard", header = TRUE)[[5]]
# introvert = read.table(file = "clipboard", header = TRUE)[[9]]
# snapchat = read.table(file = "clipboard", header = TRUE)[[8]]
# Assignment 2:
# Q1 (a):
txtsent = c(1, 10, 150, 18, 30, 100, 20, 100, 150,
75, 75, 50, 25, 100, 30, 5, 20, 200,
50, 10, 100, 100, 30, 10, 30, 10, 9,
100,11, 2, 10, 5, 10, 5, 25)
txtrec = c(1, 15, 150, 28, 30, 75, 20, 100, 150,
75, 75, 50, 30, 100, 30, 5, 40, 200,
50, 10, 100, 100, 30, 10, 30, 20, 3,
200, 15, 3, 10, 5, 15, 5, 25)
introvert = c(8, 8, 1, 4, 4, 6, 5, 6, 3, 5, 5,
3.5, 8, 5, 5, 8, 3, 3, 8, 3, 1,
4, 7, 5, 7, 5, 5, 6, 3, 4, 3, 2, 6, 3, 7)
# Q1(b):
txtrec[c(1, 5)]
## [1] 1 30
txtsent[c(1, 5)]
## [1] 1 30
introvert[c(1, 5)]
## [1] 8 4
#Q1(c):
mean(introvert)
## [1] 4.842857
sd(introvert)
## [1] 1.995478
# Q1(d):
mode(txtsent)
## [1] "numeric"
#Q1(e):
Snapchat = c("Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "N",
"Y", "Y", "N", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "N", "N", "Y",
"Y", "Y", "N", "N", "N", "N", "N", "N", "N")
Snapchat[c(1:2)]
## [1] "Y" "Y"
#Q1 (f):
mode(Snapchat)
## [1] "character"
# We have text or character as elements of this vector (snapchat). Thus we cannot calculate the mean of snapchat.
# Q2:
# Q2(a):
SM = matrix(c(txtrec, txtsent, introvert), nrow = 35, ncol = 3)
colnames(SM) = c("TxtRec", "TxtSent", "Introvert")
rownames(SM) = c(1:35)
SM[1:4,]
## TxtRec TxtSent Introvert
## 1 1 1 8
## 2 15 10 8
## 3 150 150 1
## 4 28 18 4
# Q2(b):
class(SM)
## [1] "matrix"
dim(SM)
## [1] 35 3
# Q2(c):
median(txtsent - txtrec)
## [1] 0
mean(txtsent - txtrec)
## [1] -3.685714
#Q2(d):
SM2 = cbind(SM, Snapchat)
# Q2(e):
summary(SM)
## TxtRec TxtSent Introvert
## Min. : 1.00 Min. : 1.00 Min. :1.000
## 1st Qu.: 12.50 1st Qu.: 10.00 1st Qu.:3.000
## Median : 30.00 Median : 25.00 Median :5.000
## Mean : 51.57 Mean : 47.89 Mean :4.843
## 3rd Qu.: 75.00 3rd Qu.: 87.50 3rd Qu.:6.000
## Max. :200.00 Max. :200.00 Max. :8.000
summary(SM2)
## TxtRec TxtSent Introvert Snapchat
## 30 : 5 10 : 6 5 :8 N:11
## 100 : 4 100 : 6 3 :7 Y:24
## 10 : 3 30 : 4 8 :5
## 15 : 3 5 : 3 4 :4
## 5 : 3 150 : 2 6 :4
## 75 : 3 20 : 2 7 :3
## (Other):14 (Other):12 (Other):4
# summary(SM) is creating summary for values in each variable in the matrix.
# summary(SM2) is creating summary for each variable in the matrix but not values.
# Q3:
SM.Array = array(data = SM, dim = c(35, 3),
dimnames = list(1:35, c("TxtRec", "TxtSent", "Introvert")))
SM.Array[c(1, 35),]
## TxtRec TxtSent Introvert
## 1 1 1 8
## 35 25 25 7
save.image("HW2.RData")
load("HW2.RData")