Skip to content

Commit

Permalink
return tripmat in wide format too
Browse files Browse the repository at this point in the history
  • Loading branch information
mpadge committed Mar 17, 2017
1 parent 69be518 commit f9f93f0
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 3 deletions.
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Imports:
Depends:
dplyr,
lubridate,
reshape2,
RSQLite
Suggests:
testthat
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ importFrom(dplyr,summarise)
importFrom(dplyr,tbl)
importFrom(lubridate,ymd)
importFrom(methods,as)
importFrom(reshape2,melt)
importFrom(stats,xtabs)
importFrom(utils,download.file)
importFrom(utils,unzip)
Expand Down
1 change: 1 addition & 0 deletions R/bikedata-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#' @importFrom dplyr %>% collect filter group_by src_sqlite summarise sql tbl
#' @importFrom lubridate ymd
#' @importFrom methods as
#' @importFrom reshape2 melt
#' @importFrom stats xtabs
#' @importFrom utils download.file unzip
#' @useDynLib bikedata
Expand Down
14 changes: 12 additions & 2 deletions R/tripmat.R
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,9 @@ filter_tripmat_by_datetime <- function (db, ...)
#' @param weekday If given, extract only those records including the nominated
#' weekdays. This can be a vector of numeric, starting with Sunday=1, or
#' unambiguous characters, so "sa" and "tu" for Saturday and Tuesday.
#' @param long If FALSE, a square tripmat of (num-stations, num_stations) is
#' returns; if TRUE, a long-format matrix of (stn-from, stn-to, ntrips) is
#' returned.
#' @param quiet If FALSE, progress is displayed on screen
#'
#' @return Square matrix of numbers of trips between each station
Expand All @@ -193,7 +196,7 @@ filter_tripmat_by_datetime <- function (db, ...)
#'
#' @export
tripmat <- function (spdb, start_date, end_date, start_time, end_time,
weekday, quiet=FALSE)
weekday, long=FALSE, quiet=FALSE)
{
# suppress R CMD check notes:
stop_time <- sttrip_id <- st <- et <- NULL
Expand Down Expand Up @@ -231,6 +234,13 @@ tripmat <- function (spdb, start_date, end_date, start_time, end_time,
attributes (ntrips)$call <- NULL
class (ntrips) <- 'matrix'

return (as (ntrips, 'matrix'))
res <- as (ntrips, 'matrix')
if (long)
{
res <- reshape2::melt (res)
names (res) [3] <- "num_trips"
}

return (res)
}

6 changes: 5 additions & 1 deletion man/tripmat.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit f9f93f0

Please sign in to comment.