Advertisement
Guest User

Untitled

a guest
Sep 25th, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 KB | None | 0 0
  1. date CMA0013 CMA0047 CMA0052 CMA0067
  2. 1975-10-01 0 0.012 0.078 0
  3. 1975-10-02 0 0.012 0.078 0
  4. 1975-10-03 0 0.012 0.078 0
  5. 1975-10-04 0 0.012 0.078 0
  6. 1975-10-05 0 0.012 0.078 0
  7. 1975-10-06 0 0.012 0.078 0
  8. ...
  9.  
  10. month year CMA0013 CMA0047 CMA0052 CMA0067
  11. 10 1975 6 0 0 6
  12. 11 1975 ...
  13.  
  14. df$year <- year(df$date)
  15. df$month <- month(df$date)
  16.  
  17. df2 <- ddply(df,~year+month,summarise,
  18. count = length(df[df$CMA0010 < 0.001,]))
  19.  
  20. library(lubridate) #to extract the year and month
  21. df$year <- year(df$date)
  22. df$month <- month(df$date)
  23. df2 <- aggregate(df[, grep("CMA", names(df))], #just summarise columns starting "CMA"
  24. by = list(year=df$year, month=df$month),
  25. function(x) sum(x<0.001))
  26.  
  27. df2
  28. year month CMA0013 CMA0047 CMA0052 CMA0067
  29. 1 1975 10 6 0 0 6
  30.  
  31. sum_df <- daily %>%
  32. mutate(month = lubridate::month(date),
  33. year= lubridate::year(date)) %>%
  34. group_by(year, month) %>%
  35. summarise(CMA0013 = sum(CMA0013 < 0.001),
  36. #The rest of you sums...
  37. )
  38.  
  39. library(dplyr)
  40. library(lubridate)
  41. library(tidyr)
  42. d %>%
  43. gather(key, value, -date) %>%
  44. mutate(year = year(date), month = month(date)) %>%
  45. select(-date) %>%
  46. group_by(year, month, key) %>%
  47. summarize(N = sum(value < 0.001)) %>%
  48. spread(key, N)
  49.  
  50. # A tibble: 1 x 6
  51. # Groups: year, month [1]
  52. year month CMA0013 CMA0047 CMA0052 CMA0067
  53. * <dbl> <dbl> <int> <int> <int> <int>
  54. 1 1975 10 6 0 0 6
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement