Averages/Root mean square: Difference between revisions

m
No edit summary
Line 1,754:
 
=={{header|R}}==
 
We may calculate the answer directly using R's built-in <code>sqrt</code> and <code>mean</code> functions:
<lang R>sqrt(mean((1:10)^2))</lang>
The following function works for any vector x:
<lang R>RMS =<- function(x, na.rm = F) sqrt(mean(x^2, na.rm = na.rm)){
 
sqrt(mean(x^2))
<lang R>> RMS(1:10)
}</lang>
# [1] 6.204837 </lang>
Usage:
 
<lang R>> RMS(1:10)
RMS(c(NA, 1:10))
[1] 6.204837 </lang>
# [1] NA
 
RMS(c(NA, 1:10), na.rm = T)
# [1] 6.204837</lang>
 
=={{header|Racket}}==
1,336

edits