Advertisement
Guest User

Untitled

a guest
Jul 18th, 2017
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. df[3:13] <- sapply(df[3:13], as.numeric)
  2. df$YearMonth <- strftime(df$date, "%Y %m")
  3.   #Get last available date in a month
  4. LastDate <- function(x){
  5.   y <- filter(x, !is.na(x))
  6.   last(y)
  7. }
  8.  
  9. LastDate(df[1:20,1])
  10.  
  11. df %>%
  12.   select(China:US, YearMonth) %>%
  13.   group_by(YearMonth) %>%
  14.   summarise_all("LastDate")
  15.  
  16. x <- 1:10
  17. LastDate(x)
  18. x[10] = NA
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement