copy.attributes: Copy attributes between two data frames

View source: R/other_functions.R

copy.attributesR Documentation

Copy attributes between two data frames


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)



A data frame to copy attributes from.


A data frame to copy attributes to.


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

See Also

Other overrides:,


# 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
# $mpg
# [1] "Miles Per Gallon"
# $cyl
# [1] "Cylinders"
# $disp
# [1] "Displacement"

common documentation built on Sept. 29, 2022, 9:06 a.m.