Advertisement
Vermiculus

R Lab

Apr 20th, 2012
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
R 0.51 KB | None | 0 0
  1. # R Lab
  2. # 18/4/2012
  3. # Sean Allred
  4.  
  5. path <- "~/cs/R/t/test2.txt"
  6. data <- read.table(path)
  7. types <- unique(data[[2]])
  8. months <- unique(data[[3]])
  9.  
  10. mat <- matrix(nrow=length(months),ncol=length(types))
  11. colnames(mat) = months
  12. rownames(mat) = types
  13.  
  14. for (month in 1:length(months)) {
  15.     for (type in 1:length(types)) {
  16.         mat[month, type] <- sum(subset(data, V3 == months[month] & V2 == types[type])[1])
  17.     }
  18. }
  19. barplot(mat, beside=TRUE, legend.text=TRUE, xlab="Months", ylab="Money Spent (USD)", main="Spending")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement