(Practical) Programming With R
(Practical) Programming With R
a=c(1,2,3,4,5,6,7,8,9,0)
length(a)
sum(a)
mean(a)
seq(from=100,to=2000,by=10)
install.packages("insuranceData")
library(insuranceData)
data("SingaporeAuto")
6. Find out the nature of the variables, check for NA’s, size and shape
# Find out the nature of the variables, check for NA’s, size and shape
data=SingaporeAuto
str(data)
is.na(data)
dim(data)
nrow(data)
ncol(data)
7. Extract first 10 and 40 to 70 cases with first 5 and 11, 13, 15th variables
# Extract first 10 and 40 to 70 cases with first 5 and 11, 13, 15th variables
data[c(1:10,40:70),c(1:5,11,13,15)]
b. variable NCD
NCD New Variable
0 NIL
10 and 20 Level1
30 Level2
Else Level3
# Ensure dplyr is loaded
library(dplyr)
9. Create a subset that has only Clm_Count = 0 and has only numeric variables
# Grouping by SexInsured
data %>%
group_by(SexInsured) %>%
summarise(SI = n())
# Grouping by VehicleType
data %>%
group_by(VehicleType) %>%
summarise(VT = n())
install.packages("ggplot2")