copy.attributes: Copy attributes between two data frames

View source: R/other_functions.R

copy.attributesR Documentation

Copy attributes between two data frames

Description

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.

Usage

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"

common documentation built on May 29, 2024, 1:48 a.m.