Advertisement
Guest User

Untitled

a guest
Sep 29th, 2016
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 KB | None | 0 0
  1. # skeleton of a function that collects lifetables, exposures, death counts,
  2. # and stacks all countries, years, sexes
  3. # package can be pain to install, try different stuff, seek help
  4. library(HMDHFDplus)
  5. Countries <- getHMDcountries() # returns vector of HMD country codes
  6.  
  7. # us <- "HMD username" # change to yours: you need to be registered at www.mortality.org
  8. # pw <- "HMD password" # change to yours
  9. # makes long data frame of HMD lifetables, takes several minutes to run
  10. LT <- do.call(rbind, # (idiom to rbind a list of data.frames together)
  11. # lapply() is like looping, except it sticks everything in a lsit for you,
  12. # sometimes also a bit faster, and usually more elegant...
  13. lapply(Countries, function(XYZ, us, pw){ # here define an 'anonymous' function.
  14. # print progress to console
  15. cat(XYZ,"\n")
  16. # male lifetables
  17. LTM <- readHMDweb(XYZ, "mltper_1x1", username = us, password = pw)
  18. # female lifetable
  19. LTF <- readHMDweb(XYZ, "fltper_1x1", username = us, password = pw)
  20. # add sex columns
  21. LTM$Sex <- "m"
  22. LTF$Sex <- "f"
  23. # ADD CODE HERE to add death count and exposure columns
  24. # after having read in those data objects
  25.  
  26. # then stick together
  27. LT <- rbind(LTM, LTF)
  28. # add country name
  29. LT$CNTRY <- XYZ
  30. LT
  31. }, us = us, pw = pw))
  32.  
  33. # then the rest of the assignment basically follow from this object.
  34. #
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement