
Last chance! 50% off unlimited learning
Sale ends in
Many R functions strip attributes from data frame objects. This function assigns the attributes from the `attributeData` argument to the data frame in the `data` argument.
rebindAttributes(data, attributeData)
a data.frame
an edsurvey.data.frame
or light.edsurvey.data.frame
that contains the desired attributes
a data.frame
with a class of light.edsurvey.data.frame
containing
all of the elements of data and the attributes (except
names
and row.names
) from attributeData
# NOT RUN {
require(dplyr)
PISA2012 <- readPISA(path = paste0(edsurveyHome, "PISA/2012"),
database = "INT",
countries = "ALB", verbose=TRUE)
ledf <- getData(data = PISA2012, varnames = c("cnt", "oecd", "w_fstuwt",
"st62q04", "st62q11",
"st62q13", "math"),
omittedLevels = FALSE, addAttributes = TRUE)
omittedLevels <- c('Invalid', 'N/A', 'Missing', 'Miss', 'NA', '(Missing)')
for (i in c("st62q04", "st62q11", "st62q13")) {
ledf[,i] <- factor(ledf[,i], exclude=omittedLevels)
}
#after applying some dplyr functions, the "light.edsurvey.data.frame" becomes just "data.frame"
PISA2012_ledf <- ledf %>%
rowwise() %>%
mutate(avg_3 = mean(c(st62q04, st62q11, st62q13), na.rm = TRUE)) %>%
ungroup() %>%
rebindAttributes(PISA2012) # could also be called with ledf
class(PISA2012_ledf)
# again a light.edsurvey.data.frame
lma <- lm.sdf(math ~ avg_3,data=PISA2012_ledf)
summary(lma)
PISA2012_ledf <- ledf %>%
rowwise() %>%
mutate(avg_3 = mean(c(st62q04, st62q11, st62q13), na.rm = TRUE)) %>%
ungroup() %>%
rebindAttributes(ledf) # return attributes and make a light.edsurvey.data.frame
# again a light.edsurvey.data.frame
lma <- lm.sdf(math ~ avg_3,data=PISA2012_ledf)
summary(lma)
# }
Run the code above in your browser using DataLab