Advertisement
Guest User

Untitled

a guest
Nov 7th, 2018
681
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.88 KB | None | 0 0
  1. library(devtools)
  2. install_github('NickCH-K/vtable')
  3.  
  4. library(vtable)
  5.  
  6. #Load in some data
  7. data("LifeCycleSavings")
  8. vtable(LifeCycleSavings)
  9. vtable(LifeCycleSavings,values=TRUE)
  10.  
  11. #Values option works with factors too. Set factor.limit to decide how many to show.
  12. LifeCycleSavings$country <- as.factor(row.names(LifeCycleSavings))
  13. vtable(LifeCycleSavings,values=TRUE)
  14.  
  15. #Create value labels
  16. #These are nicked from the help(LifeCycleSavings) file
  17. #but a lot of datasets don't have a file like that!
  18. labs <- c('numeric aggregate personal savings',
  19. 'numeric % of population under 15',
  20. 'numeric % of population over 75',
  21. 'numeric real per-capita disposable income',
  22. 'numeric % growth rate of dpi')
  23. vtable(LifeCycleSavings,labels=labs,values=TRUE,
  24. data.title="Intercountry Life-Cycle Savings Data",desc="Data on the savings ratio 1960–1970.")
  25. #These label variants would work just as well:
  26. #Data frame or matrix where column 1 is variable names and column 2 is labels
  27. labsv2 <- data.frame(v1=names(LifeCycleSavings),
  28. v2=c('numeric aggregate personal savings',
  29. 'numeric % of population under 15',
  30. 'numeric % of population over 75',
  31. 'numeric real per-capita disposable income',
  32. 'numeric % growth rate of dpi'))
  33. #Data frame or matrix where column titles are variable names and row 1 is labels
  34. labsv3 <- data.frame(sr="numeric aggregate personal savings",
  35. pop15='numeric % of population under 15',
  36. pop75='numeric % of population over 75',
  37. dpi='numeric real per-capita disposable income',
  38. ddpi='numeric % growth rate of dpi')
  39.  
  40. #This data set has embedded variable labels and value labels
  41. library(sjlabelled)
  42. data(efc)
  43. vtable(efc,values=TRUE)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement