On Thu, Mar 14, 2013 at 9:45 AM, yash kajaria <yash.kaja...@gmail.com> wrote: > Hi, > I wanted to learn how to solve a date and time manipulation where i can > do the following two > 1. difference of two dates eg (differnce between 5th jan 2013 and 1st > jan 2013) > > 2.Suppose i have week number of the year, i want to know if i can find > out the day it refers to eg( say week 2 of 2013 would be 6th jan 2013 and > the day is sunday) > i need my result to tell me that its the 6th of jan 2013 as well as > the day (sunday)
Try this: > dif <- d - as.Date(cut(d, "year")) > dif Time difference of 4 days > as.numeric(dif) [1] 4 The year and week don't imply the day of the week. We can input the year, week number and day of the week to get the date: > year <- 2013 > week <- 2 > day <- "Sun" > as.Date(paste(year, week-1, day), "%Y %W %a") [1] "2013-01-06" -- Statistics & Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.