Lab Exercises

  1. Subset the dataset Orders in the folder datasets to create a dataset with only “Online” payment.
ords <- read.csv("F:/R Course/Datasets/Orders.csv")
ss1 <- subset(ords,Payment.Terms == "Online")
head(ss1)
##     Order.ID Order.Date Place.of.Shipment Payment.Terms
## 2  32 90 002   6-Jan-11             Nasik        Online
## 6  32 90 006   1-Mar-11          Buldhana        Online
## 7  32 90 007   4-Mar-11             Nasik        Online
## 8  32 90 008  15-Mar-11              Pune        Online
## 9  32 90 009  19-Mar-11            Mumbai        Online
## 10 32 90 010  29-Mar-11             Thane        Online
  1. Consider the dataset mtcars. Output (write) the data in this data set into a csv file and name the csv file as mtcars.csv.
write.csv(mtcars,"F:/mtcars.csv")
  1. Consider the dataset diamonds in the folder datasets. Subset the dataset with criteria as cut=Premium and color=J
library("ggplot2")
data("diamonds")
PremJ <- subset(diamonds, cut == "Premium" & color=="J")
head(PremJ)
## # A tibble: 6 x 10
##   carat cut     color clarity depth table price     x     y     z
##   <dbl> <ord>   <ord> <ord>   <dbl> <dbl> <int> <dbl> <dbl> <dbl>
## 1  0.3  Premium J     SI2      59.3    61   405  4.43  4.38  2.61
## 2  1    Premium J     SI2      62.3    58  2801  6.45  6.34  3.98
## 3  0.93 Premium J     SI2      61.9    57  2807  6.21  6.19  3.84
## 4  1.17 Premium J     I1       60.2    61  2825  6.9   6.83  4.13
## 5  0.33 Premium J     VS1      62.8    58   557  4.41  4.38  2.76
## 6  0.33 Premium J     VS1      61.5    61   557  4.46  4.39  2.72

You can visit the blog on github