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 7368165
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T03:37:51+00:00 2026-05-29T03:37:51+00:00

I have a data frame that has a format like the following: Month Frequency

  • 0

I have a data frame that has a format like the following:

Month       Frequency
2007-08     2
2010-11     5
2011-01     43
2011-02     52
2011-03     31
2011-04     64
2011-05     73

I would like to create a histogram from this data, using X bins (X will probably be around 15, but the actual data has over 200 months), and using the data from the frequency column as the frequency for each bin of the histogram. How can I accomplish this?

I’ve tried two approaches so far, with the hist() and barplot() commands. The problem with hist() is that it does not seem to give me any way to specify that I want to use the frequency column in the frequency calculations for the histogram. The problem with barplot() is that I don’t have any flexibility in choosing X bins, and if there are omitted months, then resulting graph is not actually a true histogram because the x-axis isn’t continuous.

The only idea I have right now is to go with the barplot() approach, fill in the missing months with a value of 0 for Frequency, and use space=0 to remove the spacing between the bars. The problem with that is that it’s not particularly easy to choose an arbitrary number of bins.

  • 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-29T03:37:52+00:00Added an answer on May 29, 2026 at 3:37 am

    To get this kind of flexibility, you may have to replicate your data. Here is one way of doing it with rep:

    n <- 10
    dat <- data.frame(
        x = sort(sample(1:50, n)),
        f = sample(1:100, n))
    dat
    
    expdat <- dat[rep(1:n, times=dat$f), "x", drop=FALSE]
    

    Now you have your data replicated in the data.frame expdat, allowing you to call hist with different numbers of bins:

    par(mfcol=c(1, 2))
    hist(expdat$x, breaks=50, col="blue", main="50 bins")
    hist(expdat$x, breaks=5, col="blue", main="5 bins")
    par(mfcol=c(1, 1))
    

    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 in R that has come about from running some
I have a data.frame in R that looks like this: score rms template aln_id
I have a data frame in R that looks like this: > TimeOffset, Source,
I have a data frame that looks like this: user1,product1,0 user1,product2,2 user1,product3,1 user1,product4,2 user2,product3,0
I have this huge data frame that has servernames, Date, CPU, memory as the
I have a data.frame that has a number of duplicate rows, akin to something
i have a data frame that contains a data like this : V1 V2
I have a data.frame, d1, that has 7 columns, the 5th through 7th column
I often run into an issue where I have a data frame that has
I have a data frame that looks like this: site date var dil 1

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.