Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

hist.r

By: rherrick on Jun 17th, 2013  |  syntax: R  |  size: 0.42 KB  |  views: 44  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. test <- read.table(textConnection("age popperc
  2. 0-5 7
  3. 5-15 14
  4. 15-20 7
  5. 20-25 7
  6. 25-35 7
  7. 25-30 7
  8. 30-35 7
  9. 35-45 15
  10. 45-55 14
  11. 55-65 10
  12. 65-75 6
  13. 75-85 6"),header=TRUE,stringsAsFactors=FALSE)
  14.  
  15. midval <- sapply(strsplit(test$age,"-"),function(x) mean(as.numeric(x)))
  16. breakval <- strsplit(test$age,"-")
  17. breakval <- as.numeric(c(sapply(breakval,head,1),tail(unlist(breakval),1)))
  18. hist(rep(midval,test$popperc),breaks=breakval)