Skip to contents

Operators acting on trajectories to extract or replace parts.

Usage

# S3 method for trajectory
[(x, i)

# S3 method for trajectory
[[(x, i)

# S3 method for trajectory
[(x, i) <- value

# S3 method for trajectory
[[(x, i) <- value

Arguments

x

the trajectory object.

i

indices specifying elements to extract. Indices are numeric or character or logical vectors or empty (missing) or NULL.

Numeric values are coerced to integer as by as.integer (and hence truncated towards zero). Negative integers indicate elements/slices to leave out the selection.

Character vectors will be matched to the names of the activities in the trajectory as by %in%.

Logical vectors indicate elements/slices to select. Such vectors are recycled if necessary to match the corresponding extent.

An empty index will return the whole trajectory.

An index value of NULL is treated as if it were integer(0).

value

another trajectory object.

Value

Returns a new trajectory object.

Examples

x <- join(lapply(1:12, function(i)
  trajectory() %>% timeout(i)
))
x
#> trajectory: anonymous, 12 activities
#> { Activity: Timeout      | delay: 1 }
#> { Activity: Timeout      | delay: 2 }
#> { Activity: Timeout      | delay: 3 }
#> { Activity: Timeout      | delay: 4 }
#> { Activity: Timeout      | delay: 5 }
#> { Activity: Timeout      | delay: 6 }
#> { Activity: Timeout      | delay: 7 }
#> { Activity: Timeout      | delay: 8 }
#> { Activity: Timeout      | delay: 9 }
#> { Activity: Timeout      | delay: 10 }
#> { Activity: Timeout      | delay: 11 }
#> { Activity: Timeout      | delay: 12 }

x[10]                 # the tenth element of x
#> trajectory: anonymous, 1 activities
#> { Activity: Timeout      | delay: 10 }
x[-1]                 # delete the 1st element of x
#> trajectory: anonymous, 11 activities
#> { Activity: Timeout      | delay: 2 }
#> { Activity: Timeout      | delay: 3 }
#> { Activity: Timeout      | delay: 4 }
#> { Activity: Timeout      | delay: 5 }
#> { Activity: Timeout      | delay: 6 }
#> { Activity: Timeout      | delay: 7 }
#> { Activity: Timeout      | delay: 8 }
#> { Activity: Timeout      | delay: 9 }
#> { Activity: Timeout      | delay: 10 }
#> { Activity: Timeout      | delay: 11 }
#> { Activity: Timeout      | delay: 12 }
x[c(TRUE, FALSE)]     # logical indexing
#> trajectory: anonymous, 6 activities
#> { Activity: Timeout      | delay: 1 }
#> { Activity: Timeout      | delay: 3 }
#> { Activity: Timeout      | delay: 5 }
#> { Activity: Timeout      | delay: 7 }
#> { Activity: Timeout      | delay: 9 }
#> { Activity: Timeout      | delay: 11 }
x[c(1, 5, 2, 12, 4)]  # numeric indexing
#> trajectory: anonymous, 5 activities
#> { Activity: Timeout      | delay: 1 }
#> { Activity: Timeout      | delay: 5 }
#> { Activity: Timeout      | delay: 2 }
#> { Activity: Timeout      | delay: 12 }
#> { Activity: Timeout      | delay: 4 }
x[c(FALSE, TRUE)] <- x[c(TRUE, FALSE)] # replacing
x
#> trajectory: anonymous, 12 activities
#> { Activity: Timeout      | delay: 1 }
#> { Activity: Timeout      | delay: 1 }
#> { Activity: Timeout      | delay: 3 }
#> { Activity: Timeout      | delay: 3 }
#> { Activity: Timeout      | delay: 5 }
#> { Activity: Timeout      | delay: 5 }
#> { Activity: Timeout      | delay: 7 }
#> { Activity: Timeout      | delay: 7 }
#> { Activity: Timeout      | delay: 9 }
#> { Activity: Timeout      | delay: 9 }
#> { Activity: Timeout      | delay: 11 }
#> { Activity: Timeout      | delay: 11 }