-
Notifications
You must be signed in to change notification settings - Fork 0
/
.Rhistory
executable file
·512 lines (512 loc) · 15.6 KB
/
.Rhistory
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
)
# Define server logic
server <- function(input, output) {
output$plotMap <- renderLeaflet(
{
leaflet() %>% setView(lng = 103.835381, lat = 1.239660, zoom = input$zoomlevel) %>%
addTiles() %>% addMarkers(lat=1.239660,lng=103.835381,popup="Sentosa Cove")
}
)
}
shinyApp(ui = ui, server = server)
library(shiny)
library(leaflet)
#Three main parts for app:
# 1. UI
# Controls (visual elements that allow users to interact with the system) & Outputs
# 2. Server
# 3. Shinyapp
# Define UI for app
ui <- fluidPage(
#CONTROLS UNDER THE UI
sliderInput(inputId = "zoomlevel",label ="Map Zooming Level",value=11,min=1,max=20),
# value is default value
#OUTPUT UNDER THE UI
leafletOutput(outputId = "plotMap")
)
# Define server logic
server <- function(input, output) {
# DEFINES the output
output$plotMap <- renderLeaflet(
{
leaflet() %>% setView(lng = 103.835381, lat = 1.239660, zoom = input$zoomlevel) %>%
addTiles() %>% addMarkers(lat=1.239660,lng=103.835381,popup="Sentosa Cove")
}
)
}
shinyApp(ui = ui, server = server)
library(shiny)
library(leaflet)
#Three main parts for app:
# 1. UI
# Controls (visual elements that allow users to interact with the system) & Outputs
# 2. Server
# 3. Shinyapp
# Define UI for app
ui <- fluidPage(
#CONTROLS UNDER THE UI
sliderInput(inputId = "zoomlevel",label ="Map Zooming Level",value=14,min=1,max=20),
# value is default value
#OUTPUT UNDER THE UI
leafletOutput(outputId = "plotMap")
)
# Define server logic
server <- function(input, output) {
# DEFINES the output
output$plotMap <- renderLeaflet(
{
leaflet() %>% setView(lng = 103.835381, lat = 1.239660, zoom = input$zoomlevel) %>%
addTiles() %>% addMarkers(lat=1.239660,lng=103.835381,popup="Sentosa Cove")
}
)
}
shinyApp(ui = ui, server = server)
install.packages('rsconnect')
rsconnect::setAccountInfo(name='chuabern', token='53031062E4C278B14074977554593A64', secret='qsY9Ig+WohELuslCjHYKKl5wJOcctd1H5yshq2D4')
rsconnect::setAccountInfo(name='chuabern', token='53031062E4C278B14074977554593A64', secret='qsY9Ig+WohELuslCjHYKKl5wJOcctd1H5yshq2D4')
rsconnect::setAccountInfo(name='chuabern', token='53031062E4C278B14074977554593A64', secret='qsY9Ig+WohELuslCjHYKKl5wJOcctd1H5yshq2D4')
runApp('C:/Users/User/AppData/Local/Temp/Temp1_sentosa.zip/sentosa')
setwd("C:/Users/User/OneDrive - National University of Singapore/AY1819 SEM 2/DBA3702/10")
data <- read.csv("INSEAD Data.csv")
library(readr)
data <- read.csv("INSEAD Data.csv")
data <- read.xlsx("INSEAD Data.xlsx")
library(readr)
data <- read.xlsx("INSEAD Data.xlsx")
library(readr)
data <- read.xl("INSEAD Data.xlsx")
library(readr)
data <- read.xl("INSEAD Data.xlsx")
install.packages("xlsx")
library(xlsx)
library(xlsx)
library("xlsx")
xlsx
library("xlsx")
install.packages("xlsx")
library("xlsx")
install.packages("xlsx")
library("xlsx")
install.packages("xlsx")
library("xlsx")
library(xlsx)
data <- read.xlsx("INSEAD Data.xlsx")
install.packages("readxl")
library(xlsx)
library(readxl)
library(readr)
data <- read.xlsx("INSEAD Data.xlsx")
data <- read.xl("INSEAD Data.xlsx")
data <- read.xl("INSEAD Data.xlsx")
data <- read_excel("INSEAD Data.xlsx")
data
View(data)
data <- read.excel("INSEAD Data.xlsx")
data <- read_excel("INSEAD Data.xlsx")
data <- read_excel("INSEAD Data.xlsx",1)
View(data)
library(readxl)
library(readr)
data <- read_xlsx("INSEAD Data.xlsx")
data
data <- read_xlsx("INSEAD Data.xlsx", stringsAsFactors = F)
data <- read_xlsx("INSEAD Data.xlsx", stringsAsFactors = F)
my_data <- read.table(file = "INSEAD Data.xlsx",
sep = "\t", header=TRUE)
my_data
data <- read_xlsx("INSEAD Data.xlsx", stringsAsFactors = F, sheet =1 )
my_data <- read.table(file = "INSEAD Data.xlsx",
sep = "\t", header=TRUE, sheet=1)
?read_xlsx
?read_xlsx
data <- read_xlsx("INSEAD Data.xlsx", stringsAsFactors = F, 1 )
my_data <- read.table(file = "INSEAD Data.xlsx",
sep = "\t", header=TRUE, 1)
?read.tabe
?read.table
?read_xlsx
data <- read.csv("INSEAD Data.csv")
data
View(data)
data <- filter(data, PrefSchool %in% "Harvard Business School")
data <- filter(data, data[4] %in% "Harvard Business School")
data
View(data)
data <- read.csv("INSEAD Data.csv")
View(data)
View(data)
data[4]
data <- filter(data, data[4] %in% "Harvard Business School")
View(data)
library(readxl)
library(readr)
data <- read.csv("INSEAD Data.csv")
View(data)
data[4]
data <- as.data.frame(data) %>% filter(data, data[4] %in% "Harvard Business School")
data <- as.data.frame(data) %>% filter(data, data[4] %in% "Harvard Business School")
library(dplyr)
data <- as.data.frame(data) %>% filter(data, data[4] %in% "Harvard Business School")
data <- as.data.frame(data) %>% filter(data, data[4] %in% "Harvard Business School")
data <- as.data.frame(data) filter(data, data[4] %in% "Harvard Business School")
data <- as.data.frame(data)
data
data[4]
data <- filter(data, data[4] %in% "Harvard Business School")
View(data)
data
library(readxl)
library(readr)
library(dplyr)
data <- read.csv("INSEAD Data.csv")
# View(data)
# data[4]
data <- as.data.frame(data)
# data[4]
data <- filter(data, data[4] %in% "Harvard Business School")
# data
View(data)
data <- read.csv("INSEAD Data.csv")
# View(data)
# data[4]
data <- as.data.frame(data)
# data[4]
data <- filter(data, data[4] %in% "Harvard Business School")
# data
View(data)
data <- read.csv("INSEAD Data.csv")
# View(data)
# data[4]
data <- as.data.frame(data)
data <- filter(data, "Harvard Business School" %in% data[4])
# data
View(data)
data
filter (data, PrefSchool == "Harvard Business School")
data <- read.csv("INSEAD Data.csv")
data <- as.data.frame(data)
filter (data, PrefSchool == "Harvard Business School")
data <- read.csv("INSEAD Data.csv")
data <- as.data.frame(data)
data <- filter (data, PrefSchool == "Harvard Business School")
View(data)
biz.school.data <- readl_xlsx("Whosn1 Data.xlsx", sheet="Data")
biz.school.data <- read_xlsx("Whosn1 Data.xlsx", sheet="Data")
paste("Q17", seq(1,30), sep="_")
q1.data <- biz.school.data[, ("SchoolRated", paste("Q17", seq(1,30), sep="_"))]
biz.school.data <- read_xlsx("Whosn1 Data.xlsx", sheet="Data")
paste("Q17", seq(1,30), sep="_")
q1.data <- biz.school.data[, ("SchoolRated",)]
biz.school.data <- read_xlsx("Whosn1 Data.xlsx", sheet="Data")
paste("Q17", seq(1,30), sep="_")
q1.data <- biz.school.data[, ("SchoolRated")]
q1.data$SchoolRated %in% c(1,4)
q1.data$SchoolRated == 1 | q1.data$SchoolRated
q1.data.hbs.vs.insead <- q1.data[q1.data$SchoolRated %in% c(1,4),]
t.test(Q17_1 ~ SchoolRated, data=q1.data.hbs.vs.insead)
# biz.school.data <- read_xlsx("Whosn1 Data.xlsx", sheet="Data")
#
# paste("Q17", seq(1,30), sep="_")
# q1.data <- biz.school.data[, ("SchoolRated")]
#
# q1.data$SchoolRated %in% c(1,4)
#
# q1.data$SchoolRated == 1 | q1.data$SchoolRated
#
# q1.data.hbs.vs.insead <- q1.data[q1.data$SchoolRated %in% c(1,4),]
#
# t.test(Q17_1 ~ SchoolRated, data=q1.data.hbs.vs.insead)
library(readxl)
data <- read_excel("INSEAD Data.xlsx", sheet="Data", col_names=T)
q1.data <- data[, c("SchoolRated", paste("Q17", seq(1,30), sep="_"))]
q1.data$SchoolRated %in% c(1,4)
q1.data$SchoolRated ==1 | q1.data$SchoolRated ==4 #school rank 1 or 4
q1.data.hbs.vs.insead = q1.data[q1.data$SchoolRated %in% c(1,4), ]
t.test(Q17_1 ~ SchoolRated, data= q1.data.hbs.vs.insead)
#ANOVA
#Perform t-test for a particular att
diff.matrix <- matrix(0,nrow=4, ncol=4)
p.matrix <- diff.matrix
for (school1 in c(1:3)){
start = school1 + 1
for (school2 in c(start:4)){
q1.data.tmp <- q1.data[q1.data$SchoolRated %in% c(school1,school2),]
tmp <- t.test(Q17_1 ~ SchoolRated, data=q1.data.tmp)
diff.matrix[school1,school2] <- tmp$estimate[1] - tmp$estimate[2]
p.matrix[school1,school2] <- tmp$p.value
}
}
#ANOVA
#Perform t-test for a particular att
diff.matrix <- matrix(0,nrow=4, ncol=4)
p.matrix <- diff.matrix
for (school1 in c(1:3)){
start = school1 + 1
for (school2 in c(start:4)){
q1.data.tmp <- q1.data[q1.data$SchoolRated %in% c(school1,school2),]
tmp <- t.test(Q17_1 ~ SchoolRated, data=q1.data.tmp)
diff.matrix[school1,school2] <- tmp$estimate[1] - tmp$estimate[2]
p.matrix[school1,school2] <- tmp$p.value
}
}
}
tmp <- t.test(Q17_1 ~ SchoolRated, data=q1.data.tmp)
#ANOVA
#Perform t-test for a particular att
diff.matrix <- matrix(0,nrow=4, ncol=4)
p.matrix <- diff.matrix
for (school1 in c(1:3)){
start = school1 + 1
for (school2 in c(start:4)){
q1.data.tmp <- q1.data[q1.data$SchoolRated %in% c(school1,school2),]
tmp <- t.test(Q17_1 ~ SchoolRated, data=q1.data.tmp)
diff.matrix[school1,school2] <- tmp$estimate[1] - tmp$estimate[2]
p.matrix[school1,school2] <- tmp$p.value
}
}
format(diff.matrix, digits=3)
format(p.matrix,digits=3)
colnames(mydata)
colnames(my_ata)
colnames(my_data)
colnames(my_data)
colnames(my.data)
##ggmap visualisation
library(ggplot2)
library(RgoogleMaps)
library(ggmap)
register_google("AIzaSyDLP0JL8Oj1q9PGVn6JWYO0b7DnmBzi1EA")
details <- read.csv("general-information-of-schools.csv",
header=TRUE,
colClasses = "character")
View(details)
# details$mainlevel_code
# All columns are parsed in as charcter for convenience sake
#Load the data
#Converting data to data frame
details <- data.frame(details) %>% filter(mainlevel_code %in% "SECONDARY")
# details
# details %>% left_join()
#Attemtping to retrive geocodes from postal code
locations_df <- mutate_geocode(details,postal_code)
#lon and lat have been added to last columns of locations_df
map <- get_map("Singapore", zoom=11,source="google")
m1 <- ggmap(map,
base_layer = ggplot(data=locations_df, aes(x=locations_df$lon,
y=locations_df$lat))) + geom_point(aes(color=zone_code))
m1
locations_df
locations_df
# Create a table to store bus and mrt data
data_t <- cbind(data_new, data$bus_desc, data$mrt_desc)
library(ggmap)
ggmap::register_google(key = "AIzaSyDu7FNRizdcFzNRfXUxfrlzpSUncyAQ_0k")
library(maptools)
install.packages(maptools)
install.packages("maptols")
install.packages("maptools")
library(ggmap)
ggmap::register_google(key = "AIzaSyDu7FNRizdcFzNRfXUxfrlzpSUncyAQ_0k")
library(maptools)
library(raster)
library(rgdal)
library(leaflet)
library(leaflet.extras)
install.packages("leaflet.extras")
install.packages("erer")
library(ggmap)
ggmap::register_google(key = "AIzaSyDu7FNRizdcFzNRfXUxfrlzpSUncyAQ_0k")
library(maptools)
library(raster)
library(rgdal)
library(leaflet)
library(leaflet.extras)
library(erer)
library(shiny)
library(RColorBrewer)
# Read data
data <- read.csv("general-information-of-schools.csv")
setwd("C:/Users/User/OneDrive - National University of Singapore/AY1819 SEM 2/DBA3702/Project")
# Read data
data <- read.csv("general-information-of-schools.csv")
setwd("C:/Users/User/OneDrive - National University of Singapore/AY1819 SEM 2/DBA3702/Project")
# Read data
data <- read.csv("general-information-of-schools.csv")
# Read data
data <- read.csv("general-information-of-schools.csv")
head(data)
# Get data structure
str(data)
# address (char), zipcode (char), region (factor), lon (num), lat (num)
library(dplyr)
# Filter out only secondary schools
data <- data[data$mainlevel_code == "SECONDARY",]
head(data)
# Filter out useful info: school name, address, postal_code, dgp_code, zone_code
data_m <- data %>% select("school_name", "address", "postal_code", "dgp_code", "zone_code")
library(dplyr)
# Filter out only secondary schools
data <- data[data$mainlevel_code == "SECONDARY",]
head(data)
# Filter out useful info: school name, address, postal_code, dgp_code, zone_code
data_m <- data %>% select("school_name", "address", "postal_code", "dgp_code", "zone_code")
library(htmlwidgets)
saveWidget(m1, file = "m1.html")
library(htmlwidgets)
saveWidget(m1, file = "m1.html")
m1 <- ggmap(map,
base_layer = ggplot(data=locations_df, aes(x=locations_df$lon,
y=locations_df$lat))) + geom_point(aes(color=zone_code))
# details
# details %>% left_join()
#Attemtping to retrive geocodes from postal code
locations_df <- mutate_geocode(details,postal_code)
##ggmap visualisation
library(ggplot2)
library(RgoogleMaps)
library(ggmap)
register_google("AIzaSyDLP0JL8Oj1q9PGVn6JWYO0b7DnmBzi1EA")
details <- read.csv("general-information-of-schools.csv",
header=TRUE,
colClasses = "character")
View(details)
# details$mainlevel_code
# All columns are parsed in as charcter for convenience sake
#Load the data
#Converting data to data frame
details <- data.frame(details) %>% filter(mainlevel_code %in% "SECONDARY")
##WORDCLOUD
library(dplyr)
library(readr)
library(tm)
library(SnowballC)
library(RColorBrewer)
library(wordcloud)
cca <- read.csv("co-curricular-activities-ccas.csv")
#Load the data
cca <- data.frame(cca)
#Create the corpus of data
cca.corpus <- Corpus(VectorSource(cca$cca_generic_name))
##Data Cleaning and Wrangling
cca.Clean<-tm_map(cca.corpus, PlainTextDocument)
cca.Clean<-tm_map(cca.corpus,tolower)
cca.Clean<-tm_map(cca.Clean,removeNumbers)
cca.Clean<-tm_map(cca.Clean,removeWords,stopwords("english"))
cca.Clean<-tm_map(cca.Clean,removeWords,"and")
cca.Clean<-tm_map(cca.Clean,removeWords,"club")
cca.Clean<-tm_map(cca.Clean,removePunctuation)
#cca.Clean<-tm_map(cca.Clean,stripWhitespace)
wordcloud(cca.Clean, min.freq=1, rot.per=0.35, random.order=FALSE, colors=brewer.pal(8,"Dark2"))
##ggmap visualisation
library(ggplot2)
library(RgoogleMaps)
library(ggmap)
register_google("AIzaSyDLP0JL8Oj1q9PGVn6JWYO0b7DnmBzi1EA")
details <- read.csv("general-information-of-schools.csv",
header=TRUE,
colClasses = "character")
View(details)
# details$mainlevel_code
# All columns are parsed in as charcter for convenience sake
#Load the data
#Converting data to data frame
details <- data.frame(details) %>% filter(mainlevel_code %in% "SECONDARY")
# details
# details %>% left_join()
#Attemtping to retrive geocodes from postal code
locations_df <- mutate_geocode(details,postal_code)
#lon and lat have been added to last columns of locations_df
map <- get_map("Singapore", zoom=11,source="google")
m1 <- ggmap(map,
base_layer = ggplot(data=locations_df, aes(x=locations_df$lon,
y=locations_df$lat))) + geom_point(aes(color=zone_code))
# m1
# locations_df
library(htmlwidgets)
saveWidget(m1, file = "m1.html")
saveWidget(m1, file = "m1.html")
# m1
m1
shiny::runApp()
m<-leaflet() %>% addTiles() %>% addPolygons(data=shapeData, weight = 2, stroke = TRUE,
smoothFactor = 0.1, fillOpacity = 0.8)
m
m<-leaflet() %>% addTiles() %>% addPolygons(data=shapeData, weight = 2, stroke = TRUE,
smoothFactor = 0.1, fillOpacity = 0.8)
m<-leaflet() %>% addTiles()
m
m<-leaflet("Singapore") %>% addTiles()
m
m<-leaflet("Singapore") %>% addTiles()
m
m<-leaflet().setView(Singapore) %>% addTiles()
runApp()
Singapore
m<-leaflet().setView("Singapore") %>% addTiles()
m
m<-leaflet().setView() %>% addTiles()
m<-leaflet() %>% setView() %>% addTiles()
m<-leaflet() %>% setView(lng=1.3521,lat=103.8198) %>% addTiles()
m<-leaflet() %>% setView(lng=1.3521,lat=103.8198,zoom=11) %>% addTiles()
m
m<-leaflet() %>% setView(lng=1.3521,lat=103.8198,zoom=11) %>% addTiles()
m
m<-leaflet() %>% setView(lng=1.3521,lat=103.8198,zoom=4) %>% addTiles()
m
m<-leaflet() %>% setView(lat=1.3521,lng=103.8198,zoom=4) %>% addTiles()
m
m<-leaflet() %>% setView(lat=1.3521,lng=103.8198,zoom=11) %>% addTiles()
m
ui <- navbarPage(title="DBA3702 Project", id="title",
tabPanel(title="Interactive Map",
div(class="outer",
leafletMap(m, width="100%",height="100%")))
)
runApp()
runApp()
runApp()
m<-leaflet() %>% setView(lat=1.3521,lng=103.8198,zoom=11) %>% addTiles()
m
runApp()
runApp()
runApp()
runApp()
install.packages("styles.css")
runApp()
runApp()
runApp()
ui <- navbarPage(title="DBA3702 Project", id="title",
tabPanel(title="Interactive Map",
div(class="outer",
m,
absolutePanel(
id="controls", fixed=TRUE, draggable=TRUE,
top=60,left="auto",right=20,bottom="auto",
width=330,height="auto",
h2("Title of panel")
))
)
)
runApp()
m<-leaflet() %>% setView(lat=1.3521,lng=103.8198,zoom=11) %>% addTiles()
runApp()
runApp()
runApp()
runApp()
runApp()
shiny::runApp()
runApp()
runApp()
runApp()
runApp()
install.packages("styles.css")
runApp()
runApp()
runApp()
shiny::runApp()
runApp()
runApp()
runApp()
runApp()
runApp()
shiny::runApp()