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

  • SEARCH
  • Home
  • 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

I have a data frame with dates and prices as: >df Price Date 1.25
Say we have the following simple data-frame of date-value pairs, where some dates are
I have a data frame of daily data: df with four columns: Date, A,
I have a date column in a data frame in chr format as follows:
I have a data frame with start dates and end dates, along with the
I have extracted data to a data frame with mixed format dates that need
I have a data.frame as follows: dat <- structure(list(id = 1:4, date = structure(list(sec
I have this huge data frame that has servernames, Date, CPU, memory as the
I have a very long data frame with different plots, dates of sampling and
Suppose I have a date.frame like: df <- data.frame(a=1:5, b=sample(1:5, 5, replace=TRUE), c=5:1) df

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.