Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- library(data.table)
- library(magrittr)
- library(stringr)
- # create a function to delete unnecessary variables from a CAFAS or PECFAS
- data set and save the reduced copy
- del.items <- function(file)
- {
- data <- read.csv(input = paste0("../data/pecfas|cafas/raw",
- str_match(pattern = "cafas|pecfas", string = file) %>% tolower, "/raw/",
- file), sep = ",", header = TRUE, na.strings = "", stringsAsFactors = FALSE,
- skip = 0, colClasses = "character", data.table = FALSE)
- data <- data[-grep(pattern = "^(CA|PEC)FAS_E[0-9]+(T(Initial|[0-
- 9]+|Exit)|SP[a-z])_(G|S|Item)[0-9]+$", x = names(data))]
- write.csv(data, file = paste0("../data/pecfas|cafas/items-del",
- str_match(pattern = "cafas|pecfas", string = file) %>% tolower, "/items-
- del/", sub(pattern = "ExportData_", x = file, replacement = "")) %>%
- tolower, sep = ",", row.names = FALSE, col.names = TRUE)
- }
- # delete items from all cafas data sets
- cafas.files <- list.files("../data/cafas/raw/", pattern = ".csv")
- for (file in cafas.files){
- del.items(file)
- }
- # delete items from all pecfas data sets
- pecfas.files <- list.files("../data/pecfas/raw/", pattern = ".csv")
- for (file in pecfas.files){
- del.items(file)
- }
Add Comment
Please, Sign In to add comment