R语言输出报告
1.日期函数
get_data_month <- function(x,y,sep='-'){
library(stringr)
x <- c(str_sub(x,1,4),str_sub(x,5,6))
date_month <- as.numeric(x[1])*12+as.numeric(x[2])-y
date_month <- paste0(date_month%/%12,ifelse((date_month%%12)<10,paste0('0',date_month%%12),date_month%%12))
if(str_sub(date_month,5,6)=='00')
{
date_month <- paste0(as.numeric(str_sub(date_month,1,4))-1,12)
}
#
date_month <- paste0(str_sub(date_month,1,4),sep,str_sub(date_month,5,6))
return(date_month)
}
For example ,set suffix='20190101'
output:
网友评论