slice: Retreiving Population Distribution at Given Time

Description Usage Arguments Details Value Author(s) Examples

View source: R/slice.R

Description

Identifies the location of each individual at the given time instant

Usage

1
2
slice(x, at, vars, showProgress = TRUE, na.rm = TRUE, silent = FALSE, 
mc = FALSE, core)

Arguments

x

an object of class ASpaces

at

a numeric vector of length 1, specifying the time at which the location of an individual needs to be extracted

vars

an optional character vector. See Details.

showProgress

logical. If TRUE, a progress bar appears on the R console while iterating.

silent

logical. If TRUE, if any trip records have NAs in the time fields, a warning message will be provided.

mc

logical. If TRUE, function is operated in parallel. See Details.

core

numeric vector of length 1, specifying the Number of cores to be utilized in parallel computation.

Details

the slice() function attempts to retrieve the locations of people in the input object 'x' at the given time instant 'at'.

The function looks into the slot 'trip' in each of the elements in the slot 'data' of the object 'x' (i.e., x@data[[i]]@trip where i = 1 ... n).

The 'trip' slot contains a sequence of trips made by each person, and it is assumed that the trips are sorted in ascending order of the departure time (i.e., $o_time). If NOT, this function may not work as intended.

'vars' are used to refine the information in the resulting ASpace's info slot. When a specific character vector is input to 'vars', the info slot of ASpace resulting from the function has only the input variables. If 'vars' is not input, the result is same with the original info slot.

The 'mc' and 'core' arguments are used to enable parallelization of the slice function. If the option of mc is set to TRUE, the function works in a multi-core environment. At this time, the number of cores (threads) used can be adjusted with the 'core' argument, and if the set number exceeds the user's environment, it is adjusted to -1 of the maximum number.

The result of the slice function is provided in the form of a single data.frame, and one variable is added excluding the variables of info and trip. For this, a variable called on.move is added, and the variable is information about whether a person existing at the location is passing at the time specified by the user. If on.move is TRUE, it means that the person is moving.

Value

A data.frame

Author(s)

Seong-Yun Hong (syhong@khu.ac.kr)

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
# load data
data(slicedata)

# extracting population distribution at 1:00PM
slice(slicedata, at = 1300)

# observation of changes in population distribution over time
result <- list()
time <- seq(800, 2000, 100)
for(i in 1:length(time)){
result[[i]] <- slice(slicedata, at = time[i])}

# running function with parallelization
if (require(parallel)){
result <- slice(newtestset, 1200, silent = TRUE, mc = TRUE, core = 2)

result <- slice(newtestset, 1200, silent = TRUE, mc = TRUE, core = 6)

result <- slice(newtestset, 1200, silent = TRUE, mc = TRUE, core = 100)
}

syunhong/slice documentation built on Feb. 7, 2021, 4:55 p.m.