Root mean square function in R

29,992

Solution 1

I didn't search for a function but you can write it

x <- 1:10
sqrt(sum(x^2)/length(x))
6.204837

A better alternative is using mean function

> sqrt(mean(x^2))
[1] 6.204837

Solution 2

The function rms(x) from the package {seewave} must produce the same value.

Share:
29,992

Related videos on Youtube

Jojo
Author by

Jojo

Updated on July 09, 2022

Comments

  • Jojo
    Jojo almost 2 years

    A very brief question. After much searching I couldn't find a function to calculate the RMS of a set of integers. Does such a function exist in R?

  • sebastian-c
    sebastian-c almost 12 years
    You could even write a function: RMS <- function(num) sqrt(sum(num^2)/length(num)); RMS(x)
  • Jojo
    Jojo almost 12 years
    Ok thankyou...I'm not sure if it actually exists, which surprises me.