A function to copy column attributes from one data frame to another. The function will copy all attributes attached to each column. The column order does not matter, and the data frames do not need identical structures. The matching occurs by column name, not position. Any existing attributes on the target data frame that do not match the source data frame will be retained unaltered.

copy.attributes(source, target)

Arguments

source

A data frame to copy attributes from.

target

A data frame to copy attributes to.

Value

The data frame in the target parameter, with updated attributes from source.

See also

Other overrides: labels.data.frame(), sort.data.frame()

Examples

# Prepare data
dat1 <- mtcars
dat2 <- mtcars

# Set labels for dat1
labels(dat1) <- list(mpg = "Miles Per Gallon",
                     cyl = "Cylinders",
                     disp = "Displacement")

# Copy labels from dat1 to dat2
dat2 <- copy.attributes(dat1, dat2)

# View results
labels(dat2)
# $mpg
# [1] "Miles Per Gallon"
#
# $cyl
# [1] "Cylinders"
#
# $disp
# [1] "Displacement"