Hello,

Try


#
# Adapted from several posts to R-Help,
# mostly by David Winsemius, also by Gabor Grothendiek.
#
nweek <- function(x, format="%Y-%m-%d", origin){
        if(missing(origin)){
                as.integer(format(strptime(x, format=format), "%W"))
        }else{
                x <- as.Date(x, format=format)
                o <- as.Date(origin, format=format)
                w <- as.integer(format(strptime(x, format=format), "%w"))
                2 + as.integer(x - o - w) %/% 7
        }
}

dates<- as.Date(c("1996-03-29","1996-05-30","1996-09-28","1996-05-09"))

nweek(dates)
nweek(dates, origin="1995-12-30")


Note that you have used two different date formats, Y-m-d (dates vector) and
Y-d-m (origin).
Above the origin is consistent with the rest.

Hope this helps,

Rui Barradas



--
View this message in context: 
http://r.789695.n4.nabble.com/Extracting-week-number-starting-from-a-specific-date-tp4598676p4599178.html
Sent from the R help mailing list archive at Nabble.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.

Reply via email to