rebindAttributes: Copy Data Frame Attributes

Description Usage Arguments Value Author(s) Examples

View source: R/rebindAttributes.R

Description

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.

Usage

1
rebindAttributes(data, attributeData)

Arguments

data

a data.frame

attributeData

an edsurvey.data.frame or light.edsurvey.data.frame that contains the desired attributes

Value

a data.frame with a class of a light.edsurvey.data.frame containing all elements of data and the attributes (except names and row.names) from attributeData

Author(s)

Paul Bailey and Trang Nguyen

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
## 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)

## End(Not run)

EdSurvey documentation built on March 26, 2020, 7:10 p.m.