get.subway: Get subway data

Description Usage Arguments Value Author(s) Examples

View source: R/basics.R

Description

Take request and group specification, it returns corresponding data from the source DB. In case of invalid request, it returns an NULL and prints out a warning message.

Usage

1
2
3
4
5
6
7
8
9
get.subway(
  request,
  group = c("day", "week", "month", "year"),
  FUN = sum,
  ...,
  from = NULL,
  to = NULL,
  split = FALSE
)

Arguments

request

Station codes for the request. It should be a numeric or character vector indicating the station codes to get.

group

Group specification. Should be one of "day", "week", "month", and "year". Note that "week" here may not coincide with real world's week concept. For detail, refer to week. (default = "day")

FUN

Function to be applied when groupping. Note that if group is "day", then this will be ignored. (default = sum)

...

Extra arguments for FUN.

from

Character string specifying the start day(inclusive). It should be a POSIXct object or a character which can be casted to POSIXct. If NULL, it will be ignored. (default = NULL)

to

Character string specifiying the end day(inclusive). It should be a POSIXct object or a character which can be casted to POSIXct. If NULL, it will be ignored. (default = NULL)

split

If TRUE, the result will be splitted by the station code. Otherwise, not. (default = FALSE)

Value

A data frame holding the requested info if split is FALSE. A list properly splitted by the station code if split is TRUE.

Author(s)

Sanghyun Park, Daun Jeong, and Sehun Kim

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
# Get daily subway data of SNU and Shinchon station
# 228 and 240 are the station codes for SNU and Shinchon, respectively
data <- get.subway(c(228, 240), group = "day")
head(data)

# Get montly subway data of SNU and Shinchon station
# We want splitted data and want to mean over every month
data <- get.subway(c(228, 240), group = "month", FUN = mean, split = TRUE)
head(data$"228")
head(data$"240")

# Get weekly data of SNU station to 12/31/2019
data <- get.subway(228, group = "week", to = "2019-12-31")
tail(data)

eik4862/Subway documentation built on Sept. 24, 2021, 3:39 a.m.