Description Usage Arguments Details Value See Also Examples
Operator to get or set values corresponding to a given key for all records in a hstore.
1 2 3 | hstore %->% key
hstore %->% key <- value
|
hstore |
A hstore (i.e. list of lists). |
key |
Character string corresponding to a key in |
value |
Vector of values of the same length as |
Based on the hstore "->
" operator in PostgreSQL, the %->%
operator returns values associated with a given key for all records in the
hstore. The assignment version of the operator i.e.
hstore %->% key <- value
either creates a new key-value pair or,
if they key exists, update the associated value. It can also delete a key
by assigning its value to NULL.
Note that to subset the records in hstore
to which the operator applies,
you must use single brackets so that the result remains a list of lists. See
below for usage examples.
For the extract version, a vector of the same length as hstore
,
containing the value correponding to key
for each record
(or NA
if none). For the replace version, the modified hstore.
new_hstore
to create a empty hstore.
1 2 3 4 5 6 7 8 9 | contacts <- data.frame(name = c("Anne", "Bert", "Chris"))
contacts$phone <- new_hstore(3)
contacts$phone %->% "home" <- c("555-123-4567", "555-923-9134", "555-276-1123")
contacts$phone[2:3] %->% "home"
contacts$phone[2] %->% "home" <- NULL
contacts$phone %->% "home"
contacts$phone[2] %->% "cell" <- "555-889-9134"
contacts$phone %->% "cell"
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.