collect_attr: Collect attributes

Description Usage Arguments Author(s) Examples

View source: R/collect-attach-attributes.r

Description

Since attributes sometimes gets lost in R functions, these are some convience functions to collect and attach attributes from object.

Usage

1
collect_attr(df, attr = "label")

Arguments

df

data frame or similar object

attr

attribute

Author(s)

Henrik Renlund

Examples

 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)

renlund/dataman documentation built on May 27, 2019, 5:51 a.m.