| Extract | R Documentation |
Extract or replace subsets of coords.
## S3 method for class 'coords'
x[i]
## S3 replacement method for class 'coords'
x[i] <- value
x |
a |
i |
indices specifying elements to extract or replace—see base
|
value |
a |
Subsetting a "coords" object (except by an empty index) will drop all attributes
except fmt, latlon, names and valid. Indices referencing values
greater than length(x) will throw a subscript out of bounds error. If names are not
required, use unname(), see examples.
Replacement values may be a single numeric, a numeric vector of coordinate values
of length(i), or a "coords" object, possibly with a "latlon"
attribute. However, the "latlon" attribute of the replacement value is ignored if the
"coords" object x has no corresponding attribute set. If replacement values
are named, the names are also ignored; to replace names, use names<-()
replacement form.
The [<-(<coords>) replacement operator automatically revalidates
"coords" objects after the replacement operation by invoking
validate().
A "coords" object.
To extract and replace subsets of "waypoints" objects, simply use the base
package [ and [<- operators, taking
care not to exclude the latitude and longitude columns or "Name" column
(if present), which could lead to undefined results. Whereas "coords" objects are
automatically revalidated after using the [<-(<coords>) replacement
operator, following value replacement using the base [<-
operator, "waypoints" objects should be revalidated using
validate(), see validate Examples.
"coords", base Extract,
unname(), and validate().
## Continuing example from `as_coords()`...
## Named "coords" object in degrees and minutes with
## eight values each of latitude and longitude
dm
## Extract the first eight values
dm[1:8]
## Exclude the first eight values
dm[-8:0]
## Index odd-numbered values
(index <- as.logical(1:16 %% 2))
dm[index]
## Extract values without names
unname(dm)[1:4]
## Create "coords" object with updated position of Tally Ho
newpos <- as_coords(c(4930.342, -12411.580), fmt = 2)
latlon(newpos) <- c(TRUE, FALSE)
newpos
## Update position using the "coords" object as replacement value
dm[c(3, 11)] <- newpos
dm[c(3, 11)]
## Or, as latlon didn't actually change, use simple numeric vector
dm[c(3, 11)] <- c(4930.342, -12411.580)
dm[c(3, 11)]
rm(dm, index, newpos)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.