How to find mean and standard deviation from frequency table in R? (2024)

To find the mean and standard deviation from frequency table, we would need to apply the formula for mean and standard deviation for frequency data. For example, if we have a data frame called df that contains a column x for units and frequency for counts then the mean and standard deviation can be calculated as −

Mean = sum(df$x*df$frequency)/sum(df$frequency)SD = sqrt(sum((df$x−Mean)**2*df$frequency)/(sum(df$frequency)−1)) respectively.

Example1

Live Demo

x<−rpois(20,5)frequency<−sample(1:100,20)df1<−data.frame(x,frequency)df1

Output

x frequency1 6 42 7 263 1 864 2 65 4 526 4 617 1 558 4 239 8 3810 3 4011 8 5412 10 5613 7 7414 9 7015 7 5916 16 9517 4 2018 5 919 4 8220 9 45

Example

Mean=sum(df1$x*df1$frequency)/sum(df1$frequency)Mean

Output

[1] 6.55288

Example

SD=sqrt(sum((df1$x−Mean)**2*df1$frequency)/(sum(df1$frequency)−1))SD

Output

[1] 4.172396

Example2

Live Demo

y<−rnorm(20,25,3.24)frequency<−rpois(20,10)df2<−data.frame(y,frequency)df2

Output

y frequency1 27.44960 72 25.80343 53 22.64088 84 22.39061 75 24.55087 76 24.41826 167 23.24647 118 25.61511 99 22.42244 1110 26.77522 1411 21.89209 1112 22.95852 813 25.79808 1614 22.39654 615 21.20728 1216 28.25911 1717 26.67983 818 25.24964 1219 20.92070 820 28.25806 7

Example

Mean=sum(df2$y*df2$frequency)/sum(df2$frequency)Mean

Output

[1] 24.58724

Example

SD=sqrt(sum((df2$y−Mean)**2*df2$frequency)/(sum(df2$frequency)−1))SD

Output

[1] 2.284964

Updated on: 09-Feb-2021

4K+ Views

Related Articles

Kickstart Your Career

Get certified by completing the course

Get Started

How to find mean and standard deviation from frequency table in R? (31)

Advertisem*nts

How to find mean and standard deviation from frequency table in R? (2024)
Top Articles
Latest Posts
Article information

Author: Roderick King

Last Updated:

Views: 6239

Rating: 4 / 5 (71 voted)

Reviews: 94% of readers found this page helpful

Author information

Name: Roderick King

Birthday: 1997-10-09

Address: 3782 Madge Knoll, East Dudley, MA 63913

Phone: +2521695290067

Job: Customer Sales Coordinator

Hobby: Gunsmithing, Embroidery, Parkour, Kitesurfing, Rock climbing, Sand art, Beekeeping

Introduction: My name is Roderick King, I am a cute, splendid, excited, perfect, gentle, funny, vivacious person who loves writing and wants to share my knowledge and understanding with you.