storeVar: Store raw demographic and political variables for all unique...

Description Usage Arguments Examples

Description

Store raw demographic and political variables for all unique emails in the panel

Usage

1
2
storeVar(var, Data, toFile, fromFile = NA, idvar = NA, source = NA,
  reportFile = NA)

Arguments

var

a vector of variabels to store

Data

a data frame of the input dataset to extract raw variabels from

toFile

a vector of paths of the output datasets

fromFile

a vector of paths of the input datasets

idvar

a vector of id variables for the input and output datasets

source

a string of source of the input dataset

reportFile

a string path of a report file

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
library(plyr)
setwd("~/Dropbox (Vox Pop Labs)/Data/Panel/CanadaPanel/RawData")
parents.dir <- list.files()
fromFilePaths <- unlist(apply(as.matrix(parents.dir), 1, function(x) paste0(x, "/", list.files(x))))
Data <- list()

for (i in 1:length(fromFilePaths)) {
Data[[i]] <- read.csv(fromFilePaths[i], stringsAsFactors = FALSE)
Data[[i]]$source <- gsub("\\/", "-", gsub("EmailData.csv", "", fromFilePaths[i]))
if ( grepl("Toronto2014", fromFilePaths[i]) ) { Data[[i]]$province <- "Ontario"
} else if ( grepl("Alberta2015", fromFilePaths[i]) ) {
		Data[[i]]$province <- "Alberta"
}
		names(Data)[names(Data) %in% "province"] <- "provinceRaw"
}
varList <- c("genderRaw", "birthYearRaw", "religionRaw", "incomeRaw", "educationRaw", "selfPlacementRaw", "polInterestRaw", "voteChoiceRaw")
varList <- c("occupationRaw")
varList <- c("province", "postal_code", "riding")
toFilePaths <- paste0("../Variables/", varList, ".csv")
l_ply(Data, function(D) { storeVar(varList, D, toFilePaths, idvar = c("date", "uniqueID"), source = unique(D$source), reportFile = "../Report.csv") })

uyenhoang/panelmanager documentation built on May 3, 2019, 2:41 p.m.