baytrends (version 1.1.0)

.reAttDF: Re-attribute df based on previous df

Description

Re-attribute df based on previous df. This is useful if you run a drop column command run an aggregate function. This types of functions drop the attributes. This function examines to original and new dfs and adds the attributes from the original df to the new df whenever the new df doesn't have a particular attribute. (This navigates around the issue of changed structure.)

Usage

.reAttDF(df1, df0)

Arguments

df1

new data frame

df0

old data frame

Value

n/a

Examples

Run this code
# NOT RUN {
# create data frame
df0 <- data.frame (sta=c("A","A"), lay=c("B","C"), x1 =c(NA,2), x2 =c( 4,14))

#add simple attribute
attr(df0, "Attribute1") <- "Test attribute1"

#run aggregate -- loose attributes
df1 <- aggregate(x2 ~ sta, data=df0, mean, na.action=na.pass, na.rm=TRUE)
df2 <- .reAttDF(df1, df0)
# }

Run the code above in your browser using DataCamp Workspace