1.獲取當前日期app
> Sys.Date() [1] "2018-06-06" > Sys.Date()-6 #獲取往前第6天的日期 [1] "2018-05-31"
2.格式化日期函數
> day<-Sys.Date() > day [1] "2018-06-06" > new<-format(day,format="%Y%m%d") > new [1] "20180606" > mode(new) [1] "character"
3.替換函數code
> day<-Sys.Date() > day [1] "2018-06-06" > newday<-gsub("-","",day) > newday [1] "20180606"
4.將數據框多列文本數字轉換爲數值數字orm
data[,m:n]<-lapply(data[,m:n],as.numeric) #m、n均指列數
5.文本轉換爲日期函數form
> d<-c("2018-06-01","2018-06-02") > mode(d) [1] "character" > d1<-as.Date(d,"%Y-%m-%d") > d1 [1] "2018-06-01" "2018-06-02" > mode(d1) [1] "numeric"
6.文本截取函數apply
> a<-"2018-06-05" > b<-substr(a,start=6,stop=10) > b [1] "06-05"