R All Program
R All Program
my_vector <- c(10, 20, 30, 40, 50, 60, 70, 80, 90, 100)
Output:
print(sequence)
Output:
install.packages("insuranceData")
library(insuranceData)
data("SingaporeAuto")
6.Find out the nature of the variables, check for NA’s, size and shape
Output:
8.Extract first 10 and 40 to 70 cases with first 5 and 11, 13, 15th variables
library(insuranceData)
data("SingaporeAuto")
data=SingaporeAuto
data[c(1:20,50:60),c(1:3,11,13,15)]
Output:
9.Create new variable based on the
a. variable Exp_weights
i. If Exp_weights is negative, then newvariable is Low else High
b. variable NCD
NCD New Variable
0 NIL
10 and 20 Level1
30 Level2
Else Level3
library(dplyr)
library(insuranceData)
data("SingaporeAuto")
data=SingaporeAuto
## create a new variable
TRUE~"HIGH"))
NCD==10&NCD==20~"LEVEL1",
NCD==30~"LEVEL2",
TRUE~"LEVEL3"))
View(data)
Output:
10. Create a subset that has only Clm_Count = 0 and has only numeric variables
library(dplyr)
library(insuranceData)
data("SingaporeAuto")
data=SingaporeAuto
Output:
library(dplyr)
library(insuranceData)
data("SingaporeAuto")
##summary
data %>% group_by(SexInsured) %>% summarize(SI=n())
data %>% group_by(VehicleType) %>% summarize(VT=n())
data %>% group_by(VehicleType,SexInsured) %>% summarize(VS=n())
data %>% group_by(SexInsured,VehicleType) %>% summarize(VS=n())
data %>% group_by(Exp_weights<0.75,VehicleType) %>% summarize(EV=n())
Output:
12.Change name of the variables of your own choice
library(dplyr)
library(insuranceData)
data("SingaporeAuto")
## Rename
data=data %>% rename(New_PC = PC)
Output:
1&2. Simple way of first and second program
library(dplyr)
seq(10,200,by=10)
a = seq(10,200,by=10)
mean(a)
median(a)
sum(a)
length(a)
Output: