merge.edsurvey.data {EdSurvey} | R Documentation |
EdSurvey Merge
Description
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 |
y |
either a |
by |
the column name(s) to perform the data merge operation. If differing column names between the |
by.x |
the column name(s) to perform the data merge operation for the |
by.y |
the column name(s) to perform the data merge operation for the |
... |
arguments passed to merge, note that |
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.
Author(s)
Tom Fink
See Also
Examples
## Not run:
# 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
## End(Not run)