-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday 8.R
70 lines (51 loc) · 1.42 KB
/
day 8.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
library("readr")
path <- "C:/Users/USER/Desktop/Data 1/diabetes.csv"
df <- read_csv(path)
View(df)
#not_outcome <- !(df$Outcome == 1)
not_outcome <- df$Outcome != 1
a <- df[not_outcome, ]
View(a)
####--------------------------------------------------------------
load.path <- function( path_val){
df2 <- read_csv(path_val)
return (df2)
}
new.function <- function(df2){
county <- df2$COUNTRIES
territories <- c()
for (i in county){
if (i == "Nigeria" | i == "Ghana"){
territories <- c(territories, "Anglophone")
} else {
territories <- c(territories, "Francophone")
}
}
return (territories)
}
add.dataframe <- function(df2, territories){
df3 <- mutate(df2, TERRITORY=territories)
return (df3)
}
# territory <- data.frame(
# TERRITORY <- territories
# )
# print(territory)
path_val<- "C:/Users/USER/Desktop/Data 1/Assignment/Brewery_data.csv"
x <- load.path(path_val)
new_territory <- new.function(x)
new_df <- add.dataframe(x, new_territory)
print(new_territory)
print(new_df)
View(new_df)
###3-----------------------------------------------------------
df4 <- df2 %>% mutate(TERRITORY=territories,
.after=COUNTRIES)
View(df4)
total_profit <- sum(df3$PROFIT)
print(total_profit)
a_y <- df3$TERRITORY == "Anglophone"
anglo <- df3[a_y, ]
View(anglo)
anglo_profit <- sum(anglo$PROFIT)
print(anglo_profit)