Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6239891
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T11:28:10+00:00 2026-05-24T11:28:10+00:00

I have a data-frame of dates (Date object); see bottom. I’m trying to convert

  • 0

I have a data-frame of dates (Date object); see bottom.
I’m trying to convert them to day-of-week and then draw a histogram, but ideally where the labels are ‘Monday’…’Sunday’ (not numeric)

I have two distinct problems:

  1. It’s easy to convert a Date object to day-of-week, but the result is string or numeric, not an object.
  2. When I get a histogram, the bins and labels are wrong (see below).

If I use weekdays(dat), the output is string (“Monday”…) which cannot be used in hist().

Alternatively, if I convert to numeric data, how to get string labels on hist()?

> dotw <- with( month.day.year(dat[,1]), day.of.week(month,day,year) )
> hist(xxx,labels=c('M','Tu','W','Th','F','Sa','Su'),col='black') # WTF?!
> hist(dotw,xlab=list('M','Tu','W','Th','F','Sa','Su'))

Does not work as intended for labeling. What’s with the 0.5-width bins? And also, how to prevent the lack of gap between Sunday->0 and Monday->1? Ideally, no gaps between columns.

My data looks like:

> dat
  [1] "2010-04-02" "2010-04-06" "2010-04-09" "2010-04-10" "2010-04-14" "2010-04-15" "2010-04-19"
  [8] "2010-04-21" "2010-04-22" "2010-04-23" "2010-04-26" "2010-04-28" "2010-04-29" "2010-04-30"
 ...

> str(dat)
 Date[1:146], format: "2010-04-02" "2010-04-06" "2010-04-09" "2010-04-10" "2010-04-14" "2010-04-15" ...

> str(weekdays(dat))
 chr [1:146] "Friday" "Tuesday" "Friday" "Saturday" "Wednesday" "Thursday" "Monday" ...
> hist(weekdays(dat))
Error in hist.default(weekdays(dat)) : 'x' must be numeric
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T11:28:10+00:00Added an answer on May 24, 2026 at 11:28 am
    dat <- as.Date( c("2010-04-02", "2010-04-06", "2010-04-09", "2010-04-10", "2010-04-14", 
           "2010-04-15", "2010-04-19",   "2010-04-21", "2010-04-22", "2010-04-23","2010-04-24", 
            "2010-04-25", "2010-04-26", "2010-04-28", "2010-04-29", "2010-04-30"))
     dwka <- format(dat , "%a")
     dwka
    # [1] "Fri" "Tue" "Fri" "Sat" "Wed" "Thu" "Mon"
    #  [8] "Wed" "Thu" "Fri" "Sat" "Sun" "Mon" "Wed"
    # [15] "Thu" "Fri"
    dwkn <- as.numeric( format(dat , "%w") ) # numeric version
    hist( dwkn , breaks= -.5+0:7, labels= unique(dwka[order(dwkn)]))
    

    enter image description here

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say we have the following simple data-frame of date-value pairs, where some dates are
I have a data frame with a character column of date-times. When I use
I have a data frame where the row.names correspond to date values. $ cat
I have a data frame as follows, > mydata date station treatment subject par
I need to sort a data frame by date in R. The dates are
I have a data frame in R which looks like: | RIC | Date
I have two data.frame s in R , each indexed by date. One is
I have a data frame containing multiple time series of returns, stored in columns.
I have the following data frame: Date1 Date2 Date3 Date4 Date5 1 25 April
I have a data frame with 251 observations and 45 variables. There are 6

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.