Find the day of a week

前端 未结 7 1714
长情又很酷
长情又很酷 2020-11-22 17:37

Let\'s say that I have a date in R and it\'s formatted as follows.

   date      
2012-02-01 
2012-02-01
2012-02-02

Is there any way in R to

相关标签:
7条回答
  • 2020-11-22 18:04

    This should do the trick

    df = data.frame(date=c("2012-02-01", "2012-02-01", "2012-02-02")) 
    dow <- function(x) format(as.Date(x), "%A")
    df$day <- dow(df$date)
    df
    
    #Returns:
            date       day
    1 2012-02-01 Wednesday
    2 2012-02-01 Wednesday
    3 2012-02-02  Thursday
    
    0 讨论(0)
提交回复
热议问题