date<-as.Date('2017/09/02')
date
## [1] "2017-09-02"
date2<-as.Date('2017/11/10')
date2
## [1] "2017-11-10"
result<-date2-date
result
## Time difference of 69 days
dtime<-difftime(date,date2,unit="weeks")
dtime
## Time difference of -9.857143 weeks
sum<-date+10
sum
## [1] "2017-09-12"
v1<-as.Date(c('2015/09/02','2016/09/03','2017/08/01'))
diff(v1)
## Time differences in days
## [1] 367 332
v2<-as.Date(c('2017/09/02','2017/10/03','2017/11/10'))
diff(v2)
## Time differences in days
## [1] 31 38
dt<-seq(date,length=6,by="week")
dt
## [1] "2017-09-02" "2017-09-09" "2017-09-16" "2017-09-23" "2017-09-30"
## [6] "2017-10-07"
dt2<-seq(date,length=6,by="2 week")
dt2
## [1] "2017-09-02" "2017-09-16" "2017-09-30" "2017-10-14" "2017-10-28"
## [6] "2017-11-11"
dt3<-seq(date,length=10,by=20 )
dt3
## [1] "2017-09-02" "2017-09-22" "2017-10-12" "2017-11-01" "2017-11-21"
## [6] "2017-12-11" "2017-12-31" "2018-01-20" "2018-02-09" "2018-03-01"
dt4 <- as.Date("04/20/2011", format = "%m/%d/%Y")
dt4
## [1] "2011-04-20"
dt5 <- as.Date("October 6, 2010", format = "%B %d, %Y")
dt5
## [1] "2010-10-06"
unclass(dt4)
## [1] 15084
oldClass(dt5)
## [1] "Date"
inherits(dt4, what = "", which = FALSE)
## [1] FALSE
tm1 <- as.POSIXct("2013-07-24 23:55:26")
tm1
## [1] "2013-07-24 23:55:26 IST"
tm2 <- as.POSIXct("25072013 08:32:07", format = "%d%m%Y %H:%M:%S")
tm2
## [1] "2013-07-25 08:32:07 IST"
tm3 <- as.POSIXct("2010-12-01 11:42:03", tz = "GMT")
tm3
## [1] "2010-12-01 11:42:03 GMT"
tm2 > tm1
## [1] TRUE
tm1 + 30
## [1] "2013-07-24 23:55:56 IST"
tm1 - 14
## [1] "2013-07-24 23:55:12 IST"
tm2 - tm1
## Time difference of 8.611389 hours
as.POSIXct("2013-03-10 08:32:07") - as.POSIXct("2013-03-09 23:55:26")
## Time difference of 8.611389 hours
Sys.time()
## [1] "2017-10-02 09:12:36 IST"
unclass(tm1)
## [1] 1374690326
## attr(,"tzone")
## [1] ""
tm1.lt <- as.POSIXlt("2013-07-24 23:55:26")
tm1.lt
## [1] "2013-07-24 23:55:26 IST"
unclass(tm1.lt)
## $sec
## [1] 26
##
## $min
## [1] 55
##
## $hour
## [1] 23
##
## $mday
## [1] 24
##
## $mon
## [1] 6
##
## $year
## [1] 113
##
## $wday
## [1] 3
##
## $yday
## [1] 204
##
## $isdst
## [1] 0
##
## $zone
## [1] "IST"
##
## $gmtoff
## [1] NA
This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.
When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
summary(cars)
## speed dist
## Min. : 4.0 Min. : 2.00
## 1st Qu.:12.0 1st Qu.: 26.00
## Median :15.0 Median : 36.00
## Mean :15.4 Mean : 42.98
## 3rd Qu.:19.0 3rd Qu.: 56.00
## Max. :25.0 Max. :120.00
You can also embed plots, for example:
Note that the echo = FALSE parameter was added to the code chunk to prevent printing of the R code that generated the plot.