Description Usage Arguments Details Value Examples
The name 'dfat' comes from 'df' for data frames, and '
This overwrites the slotOP
http://www.inside-r.org/r-doc/base/slotOp, which is only for S4 objects.
1 | "@"(x, key)
|
x |
A list of lists, where the sub-lists should have named members. |
key |
Either a string that is the name of the attribute to extract, or an integer index of the attribute to extract. |
Imagine you have a data.frame where a variable/column is a list of lists, and the lists have named members, e.g.,
df$itinary <- list(
list(from="NYC", to="LA", price=1200, via="train"),
list(from="LA", to="SF", price="unknown"),
...)
You want to get the "from" value of itinary as a vector. You can do
df$itinary
or
It is slightly more than syntactic sugar for
sapply(x, function(m) {
m[["from"]]
})
We extended the idea in several ways:
1). We define a in-fix operator
2). We added error handling, in the case of bad indecies, etc.
A vector of the attribute, in the same class as the attribute, with unsuccessful conversions (non-atomic or recursive values such as lists) filled by NAs. Note that the attribute may be a vector, which would result in a matrix if x is a vector. In this version we will return NA, just to keep the return value a strict vector.
1 2 3 4 |
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.