levels shows levels for variables in data frame, relevel relevels a factor in data.frame

drelevel(
  data,
  y = NULL,
  x = NULL,
  ref = NULL,
  newlevels = NULL,
  regex = mets.options()$regex,
  sep = NULL,
  overwrite = FALSE,
  ...
)

Arguments

data

if x is formula or names for data frame then data frame is needed.

y

name of variable, or fomula, or names of variables on data frame.

x

name of variable, or fomula, or names of variables on data frame.

ref

new reference variable

newlevels

to combine levels of factor in data frame

regex

for regular expressions.

sep

seperator for naming of cut names.

overwrite

to overwrite variable

...

Optional additional arguments

Author

Klaus K. Holst and Thomas Scheike

Examples


data(mena)
dstr(mena)
#> 'data.frame':	2000 obs. of  7 variables:
#>  $ cohort    : Factor w/ 4 levels "[1973,1975]",..: 1 1 1 1 1 1 1 1 1 1 ...
#>  $ agemena   : num  13.8 12.7 12.4 13.1 13.5 ...
#>  $ status    : int  1 1 1 1 1 1 1 1 1 1 ...
#>  $ zyg       : Factor w/ 2 levels "MZ","DZ": 2 2 1 1 1 1 1 1 1 1 ...
#>  $ twinnum   : int  2 1 2 1 2 1 2 1 2 1 ...
#>  $ id        : num  1 1 2 2 3 3 4 4 5 5 ...
#>  $ mothermena: num  13.5 13.5 12.5 12.5 14.7 ...
#> Warning: Calling 'structure(NULL, *)' is deprecated, as NULL cannot have attributes.
#>   Consider 'structure(list(), *)' instead.
dfactor(mena)  <- ~twinnum
dnumeric(mena) <- ~twinnum.f

dstr(mena)
#> 'data.frame':	2000 obs. of  9 variables:
#>  $ cohort     : Factor w/ 4 levels "[1973,1975]",..: 1 1 1 1 1 1 1 1 1 1 ...
#>  $ agemena    : num  13.8 12.7 12.4 13.1 13.5 ...
#>  $ status     : int  1 1 1 1 1 1 1 1 1 1 ...
#>  $ zyg        : Factor w/ 2 levels "MZ","DZ": 2 2 1 1 1 1 1 1 1 1 ...
#>  $ twinnum    : int  2 1 2 1 2 1 2 1 2 1 ...
#>  $ id         : num  1 1 2 2 3 3 4 4 5 5 ...
#>  $ mothermena : num  13.5 13.5 12.5 12.5 14.7 ...
#>  $ twinnum.f  : Factor w/ 2 levels "1","2": 2 1 2 1 2 1 2 1 2 1 ...
#>  $ twinnum.f.n: num  2 1 2 1 2 1 2 1 2 1 ...
#> Warning: Calling 'structure(NULL, *)' is deprecated, as NULL cannot have attributes.
#>   Consider 'structure(list(), *)' instead.

mena2 <- drelevel(mena,"cohort",ref="(1980,1982]")
mena2 <- drelevel(mena,~cohort,ref="(1980,1982]")
mena2 <- drelevel(mena,cohortII~cohort,ref="(1980,1982]")
dlevels(mena)
#> cohort #levels=:4 
#> [1] "[1973,1975]" "(1975,1977]" "(1977,1980]" "(1980,1982]"
#> -----------------------------------------
#> zyg #levels=:2 
#> [1] "MZ" "DZ"
#> -----------------------------------------
#> twinnum.f #levels=:2 
#> [1] "1" "2"
#> -----------------------------------------
dlevels(mena2)
#> cohort #levels=:4 
#> [1] "[1973,1975]" "(1975,1977]" "(1977,1980]" "(1980,1982]"
#> -----------------------------------------
#> zyg #levels=:2 
#> [1] "MZ" "DZ"
#> -----------------------------------------
#> twinnum.f #levels=:2 
#> [1] "1" "2"
#> -----------------------------------------
#> cohortII #levels=:4 
#> [1] "(1980,1982]" "[1973,1975]" "(1975,1977]" "(1977,1980]"
#> -----------------------------------------
drelevel(mena,ref="(1975,1977]")  <-  ~cohort
drelevel(mena,ref="(1980,1982]")  <-  ~cohort
dlevels(mena,"coh*")
#> cohort #levels=:4 
#> [1] "[1973,1975]" "(1975,1977]" "(1977,1980]" "(1980,1982]"
#> -----------------------------------------
#> cohort.(1975,1977] #levels=:4 
#> [1] "(1975,1977]" "[1973,1975]" "(1977,1980]" "(1980,1982]"
#> -----------------------------------------
#> cohort.(1980,1982] #levels=:4 
#> [1] "(1980,1982]" "[1973,1975]" "(1975,1977]" "(1977,1980]"
#> -----------------------------------------
dtable(mena,"coh*",level=1)
#> 
#> cohort
#> [1973,1975] (1975,1977] (1977,1980] (1980,1982] 
#>         710         412         540         338 
#> 
#> cohort.(1975,1977]
#> (1975,1977] [1973,1975] (1977,1980] (1980,1982] 
#>         412         710         540         338 
#> 
#> cohort.(1980,1982]
#> (1980,1982] [1973,1975] (1975,1977] (1977,1980] 
#>         338         710         412         540 
#> 

### level 1 of zyg as baseline for new variable
drelevel(mena,ref=1) <- ~zyg
drelevel(mena,ref=c("DZ","[1973,1975]")) <- ~ zyg+cohort
drelevel(mena,ref=c("DZ","[1973,1975]")) <- zygdz+cohort.early~ zyg+cohort
### level 2 of zyg and cohort as baseline for new variables
drelevel(mena,ref=2) <- ~ zyg+cohort
dlevels(mena)
#> cohort #levels=:4 
#> [1] "[1973,1975]" "(1975,1977]" "(1977,1980]" "(1980,1982]"
#> -----------------------------------------
#> zyg #levels=:2 
#> [1] "MZ" "DZ"
#> -----------------------------------------
#> twinnum.f #levels=:2 
#> [1] "1" "2"
#> -----------------------------------------
#> cohort.(1975,1977] #levels=:4 
#> [1] "(1975,1977]" "[1973,1975]" "(1977,1980]" "(1980,1982]"
#> -----------------------------------------
#> cohort.(1980,1982] #levels=:4 
#> [1] "(1980,1982]" "[1973,1975]" "(1975,1977]" "(1977,1980]"
#> -----------------------------------------
#> zyg.1 #levels=:2 
#> [1] "MZ" "DZ"
#> -----------------------------------------
#> zyg.DZ #levels=:2 
#> [1] "DZ" "MZ"
#> -----------------------------------------
#> cohort.[1973,1975] #levels=:4 
#> [1] "[1973,1975]" "(1975,1977]" "(1977,1980]" "(1980,1982]"
#> -----------------------------------------
#> zygdz #levels=:2 
#> [1] "DZ" "MZ"
#> -----------------------------------------
#> cohort.early #levels=:4 
#> [1] "[1973,1975]" "(1975,1977]" "(1977,1980]" "(1980,1982]"
#> -----------------------------------------
#> zyg.2 #levels=:2 
#> [1] "DZ" "MZ"
#> -----------------------------------------
#> cohort.2 #levels=:4 
#> [1] "(1975,1977]" "[1973,1975]" "(1977,1980]" "(1980,1982]"
#> -----------------------------------------

##################### combining factor levels with newlevels argument

dcut(mena,labels=c("I","II","III","IV")) <- cat4~agemena
dlevels(drelevel(mena,~cat4,newlevels=1:3))
#> cohort #levels=:4 
#> [1] "[1973,1975]" "(1975,1977]" "(1977,1980]" "(1980,1982]"
#> -----------------------------------------
#> zyg #levels=:2 
#> [1] "MZ" "DZ"
#> -----------------------------------------
#> twinnum.f #levels=:2 
#> [1] "1" "2"
#> -----------------------------------------
#> cohort.(1975,1977] #levels=:4 
#> [1] "(1975,1977]" "[1973,1975]" "(1977,1980]" "(1980,1982]"
#> -----------------------------------------
#> cohort.(1980,1982] #levels=:4 
#> [1] "(1980,1982]" "[1973,1975]" "(1975,1977]" "(1977,1980]"
#> -----------------------------------------
#> zyg.1 #levels=:2 
#> [1] "MZ" "DZ"
#> -----------------------------------------
#> zyg.DZ #levels=:2 
#> [1] "DZ" "MZ"
#> -----------------------------------------
#> cohort.[1973,1975] #levels=:4 
#> [1] "[1973,1975]" "(1975,1977]" "(1977,1980]" "(1980,1982]"
#> -----------------------------------------
#> zygdz #levels=:2 
#> [1] "DZ" "MZ"
#> -----------------------------------------
#> cohort.early #levels=:4 
#> [1] "[1973,1975]" "(1975,1977]" "(1977,1980]" "(1980,1982]"
#> -----------------------------------------
#> zyg.2 #levels=:2 
#> [1] "DZ" "MZ"
#> -----------------------------------------
#> cohort.2 #levels=:4 
#> [1] "(1975,1977]" "[1973,1975]" "(1977,1980]" "(1980,1982]"
#> -----------------------------------------
#> cat4 #levels=:4 
#> [1] "I"   "II"  "III" "IV" 
#> -----------------------------------------
#> cat4.1:3 #levels=:2 
#> [1] "I-III" "IV"   
#> -----------------------------------------
dlevels(drelevel(mena,ncat4~cat4,newlevels=3:2))
#> cohort #levels=:4 
#> [1] "[1973,1975]" "(1975,1977]" "(1977,1980]" "(1980,1982]"
#> -----------------------------------------
#> zyg #levels=:2 
#> [1] "MZ" "DZ"
#> -----------------------------------------
#> twinnum.f #levels=:2 
#> [1] "1" "2"
#> -----------------------------------------
#> cohort.(1975,1977] #levels=:4 
#> [1] "(1975,1977]" "[1973,1975]" "(1977,1980]" "(1980,1982]"
#> -----------------------------------------
#> cohort.(1980,1982] #levels=:4 
#> [1] "(1980,1982]" "[1973,1975]" "(1975,1977]" "(1977,1980]"
#> -----------------------------------------
#> zyg.1 #levels=:2 
#> [1] "MZ" "DZ"
#> -----------------------------------------
#> zyg.DZ #levels=:2 
#> [1] "DZ" "MZ"
#> -----------------------------------------
#> cohort.[1973,1975] #levels=:4 
#> [1] "[1973,1975]" "(1975,1977]" "(1977,1980]" "(1980,1982]"
#> -----------------------------------------
#> zygdz #levels=:2 
#> [1] "DZ" "MZ"
#> -----------------------------------------
#> cohort.early #levels=:4 
#> [1] "[1973,1975]" "(1975,1977]" "(1977,1980]" "(1980,1982]"
#> -----------------------------------------
#> zyg.2 #levels=:2 
#> [1] "DZ" "MZ"
#> -----------------------------------------
#> cohort.2 #levels=:4 
#> [1] "(1975,1977]" "[1973,1975]" "(1977,1980]" "(1980,1982]"
#> -----------------------------------------
#> cat4 #levels=:4 
#> [1] "I"   "II"  "III" "IV" 
#> -----------------------------------------
#> ncat4 #levels=:3 
#> [1] "III-II" "I"      "IV"    
#> -----------------------------------------
drelevel(mena,newlevels=3:2) <- ncat4~cat4
dlevels(mena)
#> cohort #levels=:4 
#> [1] "[1973,1975]" "(1975,1977]" "(1977,1980]" "(1980,1982]"
#> -----------------------------------------
#> zyg #levels=:2 
#> [1] "MZ" "DZ"
#> -----------------------------------------
#> twinnum.f #levels=:2 
#> [1] "1" "2"
#> -----------------------------------------
#> cohort.(1975,1977] #levels=:4 
#> [1] "(1975,1977]" "[1973,1975]" "(1977,1980]" "(1980,1982]"
#> -----------------------------------------
#> cohort.(1980,1982] #levels=:4 
#> [1] "(1980,1982]" "[1973,1975]" "(1975,1977]" "(1977,1980]"
#> -----------------------------------------
#> zyg.1 #levels=:2 
#> [1] "MZ" "DZ"
#> -----------------------------------------
#> zyg.DZ #levels=:2 
#> [1] "DZ" "MZ"
#> -----------------------------------------
#> cohort.[1973,1975] #levels=:4 
#> [1] "[1973,1975]" "(1975,1977]" "(1977,1980]" "(1980,1982]"
#> -----------------------------------------
#> zygdz #levels=:2 
#> [1] "DZ" "MZ"
#> -----------------------------------------
#> cohort.early #levels=:4 
#> [1] "[1973,1975]" "(1975,1977]" "(1977,1980]" "(1980,1982]"
#> -----------------------------------------
#> zyg.2 #levels=:2 
#> [1] "DZ" "MZ"
#> -----------------------------------------
#> cohort.2 #levels=:4 
#> [1] "(1975,1977]" "[1973,1975]" "(1977,1980]" "(1980,1982]"
#> -----------------------------------------
#> cat4 #levels=:4 
#> [1] "I"   "II"  "III" "IV" 
#> -----------------------------------------
#> ncat4 #levels=:3 
#> [1] "III-II" "I"      "IV"    
#> -----------------------------------------

dlevels(drelevel(mena,nca4~cat4,newlevels=list(c(1,4),2:3)))
#> cohort #levels=:4 
#> [1] "[1973,1975]" "(1975,1977]" "(1977,1980]" "(1980,1982]"
#> -----------------------------------------
#> zyg #levels=:2 
#> [1] "MZ" "DZ"
#> -----------------------------------------
#> twinnum.f #levels=:2 
#> [1] "1" "2"
#> -----------------------------------------
#> cohort.(1975,1977] #levels=:4 
#> [1] "(1975,1977]" "[1973,1975]" "(1977,1980]" "(1980,1982]"
#> -----------------------------------------
#> cohort.(1980,1982] #levels=:4 
#> [1] "(1980,1982]" "[1973,1975]" "(1975,1977]" "(1977,1980]"
#> -----------------------------------------
#> zyg.1 #levels=:2 
#> [1] "MZ" "DZ"
#> -----------------------------------------
#> zyg.DZ #levels=:2 
#> [1] "DZ" "MZ"
#> -----------------------------------------
#> cohort.[1973,1975] #levels=:4 
#> [1] "[1973,1975]" "(1975,1977]" "(1977,1980]" "(1980,1982]"
#> -----------------------------------------
#> zygdz #levels=:2 
#> [1] "DZ" "MZ"
#> -----------------------------------------
#> cohort.early #levels=:4 
#> [1] "[1973,1975]" "(1975,1977]" "(1977,1980]" "(1980,1982]"
#> -----------------------------------------
#> zyg.2 #levels=:2 
#> [1] "DZ" "MZ"
#> -----------------------------------------
#> cohort.2 #levels=:4 
#> [1] "(1975,1977]" "[1973,1975]" "(1977,1980]" "(1980,1982]"
#> -----------------------------------------
#> cat4 #levels=:4 
#> [1] "I"   "II"  "III" "IV" 
#> -----------------------------------------
#> ncat4 #levels=:3 
#> [1] "III-II" "I"      "IV"    
#> -----------------------------------------
#> nca4 #levels=:2 
#> [1] "I-IV"   "II-III"
#> -----------------------------------------

drelevel(mena,newlevels=list(c(1,4),2:3)) <- nca4..2 ~ cat4
dlevels(mena)
#> cohort #levels=:4 
#> [1] "[1973,1975]" "(1975,1977]" "(1977,1980]" "(1980,1982]"
#> -----------------------------------------
#> zyg #levels=:2 
#> [1] "MZ" "DZ"
#> -----------------------------------------
#> twinnum.f #levels=:2 
#> [1] "1" "2"
#> -----------------------------------------
#> cohort.(1975,1977] #levels=:4 
#> [1] "(1975,1977]" "[1973,1975]" "(1977,1980]" "(1980,1982]"
#> -----------------------------------------
#> cohort.(1980,1982] #levels=:4 
#> [1] "(1980,1982]" "[1973,1975]" "(1975,1977]" "(1977,1980]"
#> -----------------------------------------
#> zyg.1 #levels=:2 
#> [1] "MZ" "DZ"
#> -----------------------------------------
#> zyg.DZ #levels=:2 
#> [1] "DZ" "MZ"
#> -----------------------------------------
#> cohort.[1973,1975] #levels=:4 
#> [1] "[1973,1975]" "(1975,1977]" "(1977,1980]" "(1980,1982]"
#> -----------------------------------------
#> zygdz #levels=:2 
#> [1] "DZ" "MZ"
#> -----------------------------------------
#> cohort.early #levels=:4 
#> [1] "[1973,1975]" "(1975,1977]" "(1977,1980]" "(1980,1982]"
#> -----------------------------------------
#> zyg.2 #levels=:2 
#> [1] "DZ" "MZ"
#> -----------------------------------------
#> cohort.2 #levels=:4 
#> [1] "(1975,1977]" "[1973,1975]" "(1977,1980]" "(1980,1982]"
#> -----------------------------------------
#> cat4 #levels=:4 
#> [1] "I"   "II"  "III" "IV" 
#> -----------------------------------------
#> ncat4 #levels=:3 
#> [1] "III-II" "I"      "IV"    
#> -----------------------------------------
#> nca4..2 #levels=:2 
#> [1] "I-IV"   "II-III"
#> -----------------------------------------

drelevel(mena,newlevels=list("I-III"=c("I","II","III"),"IV"="IV")) <- nca4..3 ~ cat4
dlevels(mena)
#> cohort #levels=:4 
#> [1] "[1973,1975]" "(1975,1977]" "(1977,1980]" "(1980,1982]"
#> -----------------------------------------
#> zyg #levels=:2 
#> [1] "MZ" "DZ"
#> -----------------------------------------
#> twinnum.f #levels=:2 
#> [1] "1" "2"
#> -----------------------------------------
#> cohort.(1975,1977] #levels=:4 
#> [1] "(1975,1977]" "[1973,1975]" "(1977,1980]" "(1980,1982]"
#> -----------------------------------------
#> cohort.(1980,1982] #levels=:4 
#> [1] "(1980,1982]" "[1973,1975]" "(1975,1977]" "(1977,1980]"
#> -----------------------------------------
#> zyg.1 #levels=:2 
#> [1] "MZ" "DZ"
#> -----------------------------------------
#> zyg.DZ #levels=:2 
#> [1] "DZ" "MZ"
#> -----------------------------------------
#> cohort.[1973,1975] #levels=:4 
#> [1] "[1973,1975]" "(1975,1977]" "(1977,1980]" "(1980,1982]"
#> -----------------------------------------
#> zygdz #levels=:2 
#> [1] "DZ" "MZ"
#> -----------------------------------------
#> cohort.early #levels=:4 
#> [1] "[1973,1975]" "(1975,1977]" "(1977,1980]" "(1980,1982]"
#> -----------------------------------------
#> zyg.2 #levels=:2 
#> [1] "DZ" "MZ"
#> -----------------------------------------
#> cohort.2 #levels=:4 
#> [1] "(1975,1977]" "[1973,1975]" "(1977,1980]" "(1980,1982]"
#> -----------------------------------------
#> cat4 #levels=:4 
#> [1] "I"   "II"  "III" "IV" 
#> -----------------------------------------
#> ncat4 #levels=:3 
#> [1] "III-II" "I"      "IV"    
#> -----------------------------------------
#> nca4..2 #levels=:2 
#> [1] "I-IV"   "II-III"
#> -----------------------------------------
#> nca4..3 #levels=:2 
#> [1] "I-III" "IV"   
#> -----------------------------------------

drelevel(mena,newlevels=list("I-III"=c("I","II","III"))) <- nca4..4 ~ cat4
dlevels(mena)
#> cohort #levels=:4 
#> [1] "[1973,1975]" "(1975,1977]" "(1977,1980]" "(1980,1982]"
#> -----------------------------------------
#> zyg #levels=:2 
#> [1] "MZ" "DZ"
#> -----------------------------------------
#> twinnum.f #levels=:2 
#> [1] "1" "2"
#> -----------------------------------------
#> cohort.(1975,1977] #levels=:4 
#> [1] "(1975,1977]" "[1973,1975]" "(1977,1980]" "(1980,1982]"
#> -----------------------------------------
#> cohort.(1980,1982] #levels=:4 
#> [1] "(1980,1982]" "[1973,1975]" "(1975,1977]" "(1977,1980]"
#> -----------------------------------------
#> zyg.1 #levels=:2 
#> [1] "MZ" "DZ"
#> -----------------------------------------
#> zyg.DZ #levels=:2 
#> [1] "DZ" "MZ"
#> -----------------------------------------
#> cohort.[1973,1975] #levels=:4 
#> [1] "[1973,1975]" "(1975,1977]" "(1977,1980]" "(1980,1982]"
#> -----------------------------------------
#> zygdz #levels=:2 
#> [1] "DZ" "MZ"
#> -----------------------------------------
#> cohort.early #levels=:4 
#> [1] "[1973,1975]" "(1975,1977]" "(1977,1980]" "(1980,1982]"
#> -----------------------------------------
#> zyg.2 #levels=:2 
#> [1] "DZ" "MZ"
#> -----------------------------------------
#> cohort.2 #levels=:4 
#> [1] "(1975,1977]" "[1973,1975]" "(1977,1980]" "(1980,1982]"
#> -----------------------------------------
#> cat4 #levels=:4 
#> [1] "I"   "II"  "III" "IV" 
#> -----------------------------------------
#> ncat4 #levels=:3 
#> [1] "III-II" "I"      "IV"    
#> -----------------------------------------
#> nca4..2 #levels=:2 
#> [1] "I-IV"   "II-III"
#> -----------------------------------------
#> nca4..3 #levels=:2 
#> [1] "I-III" "IV"   
#> -----------------------------------------
#> nca4..4 #levels=:2 
#> [1] "I-III" "IV"   
#> -----------------------------------------

drelevel(mena,newlevels=list(group1=c("I","II","III"))) <- nca4..5 ~ cat4
dlevels(mena)
#> cohort #levels=:4 
#> [1] "[1973,1975]" "(1975,1977]" "(1977,1980]" "(1980,1982]"
#> -----------------------------------------
#> zyg #levels=:2 
#> [1] "MZ" "DZ"
#> -----------------------------------------
#> twinnum.f #levels=:2 
#> [1] "1" "2"
#> -----------------------------------------
#> cohort.(1975,1977] #levels=:4 
#> [1] "(1975,1977]" "[1973,1975]" "(1977,1980]" "(1980,1982]"
#> -----------------------------------------
#> cohort.(1980,1982] #levels=:4 
#> [1] "(1980,1982]" "[1973,1975]" "(1975,1977]" "(1977,1980]"
#> -----------------------------------------
#> zyg.1 #levels=:2 
#> [1] "MZ" "DZ"
#> -----------------------------------------
#> zyg.DZ #levels=:2 
#> [1] "DZ" "MZ"
#> -----------------------------------------
#> cohort.[1973,1975] #levels=:4 
#> [1] "[1973,1975]" "(1975,1977]" "(1977,1980]" "(1980,1982]"
#> -----------------------------------------
#> zygdz #levels=:2 
#> [1] "DZ" "MZ"
#> -----------------------------------------
#> cohort.early #levels=:4 
#> [1] "[1973,1975]" "(1975,1977]" "(1977,1980]" "(1980,1982]"
#> -----------------------------------------
#> zyg.2 #levels=:2 
#> [1] "DZ" "MZ"
#> -----------------------------------------
#> cohort.2 #levels=:4 
#> [1] "(1975,1977]" "[1973,1975]" "(1977,1980]" "(1980,1982]"
#> -----------------------------------------
#> cat4 #levels=:4 
#> [1] "I"   "II"  "III" "IV" 
#> -----------------------------------------
#> ncat4 #levels=:3 
#> [1] "III-II" "I"      "IV"    
#> -----------------------------------------
#> nca4..2 #levels=:2 
#> [1] "I-IV"   "II-III"
#> -----------------------------------------
#> nca4..3 #levels=:2 
#> [1] "I-III" "IV"   
#> -----------------------------------------
#> nca4..4 #levels=:2 
#> [1] "I-III" "IV"   
#> -----------------------------------------
#> nca4..5 #levels=:2 
#> [1] "group1" "IV"    
#> -----------------------------------------

drelevel(mena,newlevels=list(g1=c("I","II","III"),g2="IV")) <- nca4..6 ~ cat4
dlevels(mena)
#> cohort #levels=:4 
#> [1] "[1973,1975]" "(1975,1977]" "(1977,1980]" "(1980,1982]"
#> -----------------------------------------
#> zyg #levels=:2 
#> [1] "MZ" "DZ"
#> -----------------------------------------
#> twinnum.f #levels=:2 
#> [1] "1" "2"
#> -----------------------------------------
#> cohort.(1975,1977] #levels=:4 
#> [1] "(1975,1977]" "[1973,1975]" "(1977,1980]" "(1980,1982]"
#> -----------------------------------------
#> cohort.(1980,1982] #levels=:4 
#> [1] "(1980,1982]" "[1973,1975]" "(1975,1977]" "(1977,1980]"
#> -----------------------------------------
#> zyg.1 #levels=:2 
#> [1] "MZ" "DZ"
#> -----------------------------------------
#> zyg.DZ #levels=:2 
#> [1] "DZ" "MZ"
#> -----------------------------------------
#> cohort.[1973,1975] #levels=:4 
#> [1] "[1973,1975]" "(1975,1977]" "(1977,1980]" "(1980,1982]"
#> -----------------------------------------
#> zygdz #levels=:2 
#> [1] "DZ" "MZ"
#> -----------------------------------------
#> cohort.early #levels=:4 
#> [1] "[1973,1975]" "(1975,1977]" "(1977,1980]" "(1980,1982]"
#> -----------------------------------------
#> zyg.2 #levels=:2 
#> [1] "DZ" "MZ"
#> -----------------------------------------
#> cohort.2 #levels=:4 
#> [1] "(1975,1977]" "[1973,1975]" "(1977,1980]" "(1980,1982]"
#> -----------------------------------------
#> cat4 #levels=:4 
#> [1] "I"   "II"  "III" "IV" 
#> -----------------------------------------
#> ncat4 #levels=:3 
#> [1] "III-II" "I"      "IV"    
#> -----------------------------------------
#> nca4..2 #levels=:2 
#> [1] "I-IV"   "II-III"
#> -----------------------------------------
#> nca4..3 #levels=:2 
#> [1] "I-III" "IV"   
#> -----------------------------------------
#> nca4..4 #levels=:2 
#> [1] "I-III" "IV"   
#> -----------------------------------------
#> nca4..5 #levels=:2 
#> [1] "group1" "IV"    
#> -----------------------------------------
#> nca4..6 #levels=:2 
#> [1] "g1" "g2"
#> -----------------------------------------