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
. Thex
object is retained and has y values stored in the internal cache in memory.x
also supportslight.edusrvey.data.frame
objects ify
is adata.frame
orlight.edsurvey.data.frame
object.- y
either a
light.edsurvey.data.frame
or adata.frame
- by
the column name(s) to perform the data merge operation. If differing column names between the
x
andy
objects, use theby.x
andby.y
arguments.- by.x
the column name(s) to perform the data merge operation for the
x
object. Defaults toby
value.- by.y
the column name(s) to perform the data merge operation for the
y
object. Defaults toby
value.- ...
arguments passed to merge, note that
all.x
will always beTRUE
(the data on theedsurvey.data.frame
will always be kept) andall.y
will always beFALSE
to avoid adding data not on theedsurvey.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.
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
} # }