Description Usage Arguments Details Value Note Author(s) See Also Examples
Get or set a lazy frame column attribute.
1 2 | column_attr(x, col, which)
column_attr(x, col, which) <- value
|
x |
A lazy.frame object. |
col |
A numeric column index. |
which |
The attribute name to set or get. |
value |
The new attribute value. |
Because lazy frames load data from text files on demand, column attributes set in the usual way are ephemeral–they only affect data frame subsets returned as a result of index operations.
Use the column_attr function to set attributes on a lazy frame column that persist for all extracted subsets.
The attribute value is returned by the get version of the function.
This function is typically used to manually set factor levels
for factor-valued columns, for example if
stringsAsFactors=TRUE
. See below for an example.
B. W. Lewis <blewis@illposed.net>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | # Note that the 5th column of the 'iris' data set is factor coded.
data(iris)
f = tempfile()
write.table(iris, file=f, sep=",", row.names=FALSE, col.names=TRUE)
x = lazy.frame(f, header=TRUE, stringsAsFactors=TRUE)
# Lazy frames load data on demand from the file, they can't automatically
# code factor levels. Subsets will only include factor level codings
# defined within the subset (probably not what you want!), for example:
x[1:3,5]
# If we know all the levels, however, we can explicitly set them with
# the column_attr function:
column_attr(x,5,"levels") <- levels(iris[,5])
# Now we're OK:
x[1:3,5]
unlink(f)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.