Solutions for the Lab Session
Here you can find the solutions for the R codes given in Sample Lab Session
post. I hope the sample has been useful.
Solutions:
2*3
## [1] 6
2^3
## [1] 8
log(2.718)
## [1] 0.9998963
exp(1)
## [1] 2.718282
log(50, base = 10)
## [1] 1.69897
x <- 2
y = 4
x
## [1] 2
y
## [1] 4
x^3
## [1] 8
y^3
## [1] 64
sqrt(x)
## [1] 1.414214
fib <- c(1, 2, 3, 5, 8, 13)
pri <- c(1, 3, 5, 7, 11, 13)
fib
## [1] 1 2 3 5 8 13
pri
## [1] 1 3 5 7 11 13
fib[3] #to extract just the third element of either variable
## [1] 3
pri[6] #to extract just the sixth element of either variable
## [1] 13
sum(fib) #sum of the list of values
## [1] 32
sum(pri) #sum of the list of values
## [1] 40
data <- cbind(fib, pri)
data
## fib pri
## [1,] 1 1
## [2,] 2 3
## [3,] 3 5
## [4,] 5 7
## [5,] 8 11
## [6,] 13 13
library(readr)
palmbeach <- read_csv("https://raw.githubusercontent.com/burakgiray/data/master/PalmBeach.csv")
palmbeach$bs <- 100*palmbeach$BUCHANAN/palmbeach$VOTES
summary(palmbeach$bs) #To see the summary statistics of bs
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 0.04653 0.13089 0.20020 0.24003 0.28179 0.89534
boxplot(palmbeach$bs,horizontal=T) #To see a box-and-whisker plot
stem(palmbeach$bs,scale=2) #To see a stem-and-leaf plot
##
## The decimal point is 1 digit(s) to the left of the |
##
## 0 |
## 0 | 57777888
## 1 | 001122333333344
## 1 | 666669999
## 2 | 000112244444
## 2 | 56778899
## 3 | 1224
## 3 | 67
## 4 | 03
## 4 | 6
## 5 | 4
## 5 | 568
## 6 |
## 6 |
## 7 |
## 7 |
## 8 | 2
## 8 |
## 9 | 0
hist(palmbeach$bs,prob=T) #To see a histogram