-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfilter() , slice() & arrange().R
75 lines (50 loc) · 2.13 KB
/
filter() , slice() & arrange().R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
##WELCOME TO THE GUIDED PROJET!!
##WELCOME TO DATA MANIPULATION USING DPLYR !!
### THE IMPORTANT FUNCTIONS OF DPLYR ARE:
### filter(), slice(), select(),arrange(),mutate(),summarise() and group_by()
### WE WILL ALSO COVER SOME MORE IMPORTANT FUNCTIONS
### FOR DESCRIPTIVE STATISTICS.
###PROBLEM STATEMENT:
###You are provided with a dataset of a departmental store.
###It contains details of products from May, 2020, a period marked by covid-19.
###Your manager wants you to find out that investing in which products will be more profitable.
###Your objective is to analyse the patterns and trends of the products, and gather insights for
###strategic decision making.(At this level, you don’t need to make reports/recommendations now.
###You will build reports and make recommendations in future, with the knowledge you gained from
###this project.)
##The package needed is dplyr :
###TO INSTALL THE PACKAGE, RUN THE FOLLOWING:-
install.packages("dplyr")
####LOAD THE DPLYR PACKAGE
require(dplyr)
library(dplyr)
##LET'S LOAD THE DATASET
store <-read.csv("MY DEPARTMENTAL STORE .csv")
#VIEW THE DATASET
View(store)
#GLIMPSE THE DATASET
glimpse(store)
####1.filter()
###1.1.GET THE INFORMATION OF THE PRODUCT WHERE TO PRODUCT_TYPE IS 'beauty products'
store1<-filter(store, PRODUCT_TYPE == 'beauty products')
View(store1)
### ANOTHER EXAMPLE/INSTANCE OF USING THIS FUNCTION
###1.2. GET THE INFORMATION OF THE PRODUCT WHERE IT BELONGS TO COMPANY S&M
store1 <- filter(store, COMPANY %in% c("S", "M") )
View(store1)
####2. slice()
###2.1 GET THE DETAILS OF FIRST 10 ROWS
store2 <- store %>% slice(1 : 10)
View(store2)
### MORE EXAMPLES/INSTANCES OF USING THIS FUNCTION
###2.2 GET THE DETAILS OF FIRST 6 ROWS
store2<-store %>% slice_head(n = 6)
View(store2)
####3.arrange()
###3.1.ARRANGE THE DATASET IN ASCENDING ORDER OF QUANTITTY DEMANDED
store1 <- arrange(store, QUANTITY_DEMANDED)
View(store1)
### ANOTHER EXAMPLE/INSTANCE OF USING THIS FUNCTION
###3.2. ARRANGE THE DATASET IN DESCENDING ORDER OF SELLING PRICE
store1 <- arrange(store, desc(SELLING_PRICE) )
View(store1)