Skip to contents

Takes a data.frame or a light.edsurvey.data.frame and merges with a edsurvey.data.frame into it's internal data cache.

Usage

# S3 method for class 'edsurvey.data.frame'
merge(x, y, by = "id", by.x = by, by.y = by, ...)

Arguments

x

a edsurvey.data.frame. The x object is retained and has y values stored in the internal cache in memory. x also supports light.edusrvey.data.frame objects if y is a data.frame or light.edsurvey.data.frame object.

y

either a light.edsurvey.data.frame or a data.frame

by

the column name(s) to perform the data merge operation. If differing column names between the x and y objects, use the by.x and by.y arguments.

by.x

the column name(s) to perform the data merge operation for the x object. Defaults to by value.

by.y

the column name(s) to perform the data merge operation for the y object. Defaults to by value.

...

arguments passed to merge, note that all.x will always be TRUE (the data on the edsurvey.data.frame will always be kept) and all.y will always be FALSE to avoid adding data not on the edsurvey.data.frame.

Value

a merged data set the same object type as x. For edsurvey.data.frame objects then resulting merged data is stored in the objects internal data cache.

See also

Author

Tom Fink

Examples

if (FALSE) { # \dontrun{
# read in NAEP primer data
sdf <- readNAEP(path=system.file("extdata/data", "M36NT2PM.dat", package = "NAEPprimer"))
lsdf <- getData(data=sdf, varnames=c("dsex", "b017451"), addAttributes = TRUE)
df <- data.frame(dsex = c("Male","Female"), dsex2 = c("Boy","Girl"))

#merging an edsurvey.data.frame with a data.frame/light.edsurvey.data.frame
#returns an edsurvey.data.frame object
sdf2 <- merge(sdf, df, by = "dsex")
table(sdf2$dsex2)

# merging a light.edsurvey.data.frame with a data.frame
# returns a light.edsurvey.data.frame object
merged_lsdf <- merge(lsdf,df, by = "dsex")
class(merged_lsdf) #  "light.edsurvey.data.frame" "data.frame"
head(merged_lsdf) # shows merge results

# merging behaves similarly to base::merge
df2 <- data.frame(dsex = c("Male","Female"), b017451 = c(1,2))
merged_lsdf2 <- merge(lsdf,df2, by = "dsex")
names(merged_lsdf2) # "dsex"      "b017451.x" "b017451.y"
head(merged_lsdf2) # shows merge results
} # }