Description Usage Arguments Author(s) Examples
View source: R/collect-attach-attributes.r
Since attributes sometimes gets lost in R functions, these are some convience functions to collect and attach attributes from object.
1 | collect_attr(df, attr = "label")
|
df |
data frame or similar object |
attr |
attribute |
Henrik Renlund
1 2 3 4 5 6 7 8 9 10 11 12 | df1 <- data.frame(id = 1:2, x = runif(2))
attr(df1$x, "label") <- "X value"
df2 <- data.frame(id = 2:1, y = runif(2))
attr(df2$id, "label") <- "Identifier"
attr(df2$y, "label") <- "Y value"
df <- merge(df1, df2, by = "id")
str(df) ## no attributes on variables
c1 <- collect_attr(df1)
c2 <- collect_attr(df2)
df <- attach_attr(df, c(c1,c2))
str(df) ## has attributes on variables
rm(df1, df2, c1, c2, df)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.