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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T05:27:46+00:00 2026-06-03T05:27:46+00:00

Given a frequency table below: > print(dat) V1 V2 1 1 11613 2 2

  • 0

Given a frequency table below:

> print(dat)
V1    V2
1  1 11613
2  2  6517
3  3  2442
4  4   687
5  5   159
6  6    29

# V1 = Score
# V2 = Frequency

How can we plot the density, (i.e. y-axis range from 0 to 1.0).

Currently the I have the following for frequency plot:

plot(0,main="table",type="n");
lines(dat,lty=1)

# I need to use lines() and plot() here, 
# because need to make multiple lines in single plot

Not sure how to approach that for density.

  • 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-06-03T05:27:48+00:00Added an answer on June 3, 2026 at 5:27 am

    The density of each block would be V2 / sum(V2) assuming that each row is a separate block.

    For your data

    dat <- data.frame(V1 = 1:6, V2 = c(11613, 6517, 2442, 687, 159, 29))
    

    I get:

    > with(dat, V2 / sum(V2))
    [1] 0.541474332 0.303865342 0.113862079 0.032032452 0.007413624 0.001352170
    

    Which we can check using R’s tools. First expand your compact frequency table

    dat2 <- unlist(apply(dat, 1, function(x) rep(x[1], x[2])))
    

    Then use hist() to compute the values we want

    dens <- hist(dat2, breaks = c(0:6), plot = FALSE)
    

    Look at the resulting object:

    > str(dens)
    List of 7
     $ breaks     : int [1:7] 0 1 2 3 4 5 6
     $ counts     : int [1:6] 11613 6517 2442 687 159 29
     $ intensities: num [1:6] 0.54147 0.30387 0.11386 0.03203 0.00741 ...
     $ density    : num [1:6] 0.54147 0.30387 0.11386 0.03203 0.00741 ...
         $ mids       : num [1:6] 0.5 1.5 2.5 3.5 4.5 5.5
     $ xname      : chr "dat2"
     $ equidist   : logi TRUE
     - attr(*, "class")= chr "histogram"
    

    Note the density component which is:

    > dens$density
    [1] 0.541474332 0.303865342 0.113862079 0.032032452 0.007413624 0.001352170
    

    Which concurs with my by-hand calculation from the original frequency table representation.

    As for the plotting, if you just want to draw densities instead then try:

    dat <- transform(dat, density = V2 / sum(V2))
    plot(density ~ V1, data = dat, type = "n")
    lines(density ~ V1, data = dat, col = "red")
    

    If you want to force axis limits do:

    plot(density ~ V1, data = dat, type = "n", ylim = c(0,1))
    lines(density ~ V1, data = dat, col = "red")
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

At work, we are given a set of constraints of the form (taskname, frequency)
Given a package, how can I automatically find all its sub-packages?
Given a (simplified) table CREATE TABLE `transactions` ( `ID` bigint(20) NOT NULL AUTO_INCREMENT, `CREATION_DT`
I have a table which has no primary key and I can't add one
Given: table 'thing': age --- 3.4 3.4 10.1 40 45 49 I want to
Given this markup: // Calendar.html?date=1/2/2003 <script> $(function() { $('.inlinedatepicker').datepicker(); }); </script> ... <div class=inlinedatepicker
Given these two queries: Select t1.id, t2.companyName from table1 t1 INNER JOIN table2 t2
Given a date range how to calculate the number of weekends partially or wholly
Given an interface or interfaces, what is the best way to generate an class
Given: unsigned int a, b, c, d; I want: d = a * b

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.