Skip to content

Instantly share code, notes, and snippets.

@AngelBerihuete
Created December 1, 2017 07:58
Show Gist options
  • Save AngelBerihuete/b5cf089d4beac3adb1b004dfc7ccbb5c to your computer and use it in GitHub Desktop.
Save AngelBerihuete/b5cf089d4beac3adb1b004dfc7ccbb5c to your computer and use it in GitHub Desktop.
[rtip] Load your own dataset
loadOwnDataset <- function(year = NULL, country = NULL, region = NULL, hhcsw = NULL, hhsize = NULL, ehhs = NULL, edi = NULL){
# year: year of the survey
# country: Country
# region: Region in the country
# hhcsw: Household cross-sectional weight
# hhsize: Household size
# ehhs: Equivalised household size
# edi: Equivalised disposable income (with the modified OECD scale)
check1 <- is.null(c(hhcsw,hhsize,ehhs, edi))
check1 <- is.null(list(year, country, region))
if(!check1){
stop('Missing data in variables hhcsw, hhsize, ehhs or edi')
}else if (!check2){
stop('Missing data in variables year, country or region')
}else{
n_hhsize <- length(hhsize)
n_hhcsw <- length(hhcsw)
n_ehhs <- length(ehhs)
if(n_hhsize==n_hhcsw & n_hhsize==n_ehhs){
dataset <- data.frame(DB010 = rep(year, length(n_hhsize)),
DB020 = rep(country, length(n_hhsize)),
DB040 = rep(region, length(n_hhsize)),
DB090 = hhcsw,
HX040 = hhsize,
HX050 = ehhs,
HX090 = edi)
}else{
stop('The size of variables are different. Check lenght of hhcsw, hhsize, ehhs or edi')
}
}
return(dataset)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment