D3.js | d3.deviation() function
The d3.deviation() function in D3.js is used to return the standard deviation of the given array’s elements. If the array is having less than two elements then it returns undefined.
Syntax:
d3.deviation(Array)
Parameters: This function accepts a parameters Array which is an array of elements whose standard deviation are to be calculated. Here elements should be integers not string otherwise it returns undefined.
Return Value: It returns the standard deviation of the given array’s element.
Below programs illustrate the d3.deviation() function in D3.js.
Example 1:
<html> <head> <title> Getting standard deviation of the elements of given array </title> </head> <body> </script> <script> // initialising the array of elements var Array1 = [10, 20, 30, 40, 50, 60]; var Array2 = [1, 2]; var Array3 = [0, 1.5, 6.8]; var Array4 = [.8, .08, .008]; // Calling to d3.deviation() function A = d3.deviation(Array1); B = d3.deviation(Array2); C = d3.deviation(Array3); D = d3.deviation(Array4); // Getting standard deviation of the given array's element document.write(A + "<br>"); document.write(B + "<br>"); document.write(C + "<br>"); document.write(D + "<br>"); </script> </body> </html> |
Output:
18.708286933869708 0.7071067811865476 3.572580766523457 0.4379589021814719
Example 2:
<html> <head> <title> Getting standard deviation of the elements of given array </title> </head> <body> </script> <script> // initialising the array of elements var Array1 = [1]; var Array2 = ["a", "b", "c"]; var Array3 = [1, 2, "B", "C"]; var Array4 = ["Geek", "Geeks", 2, 3, "GeeksforGeeks"]; // Calling to d3.deviation() function A = d3.deviation(Array1); B = d3.deviation(Array2); C = d3.deviation(Array3); D = d3.deviation(Array4); // Getting standard deviation of // the given array's element document.write(A + "<br>"); document.write(B + "<br>"); document.write(C + "<br>"); document.write(D + "<br>"); </script> </body> </html> |
Output:
undefined undefined 0.7071067811865476 0.7071067811865476
Note: In the above output, if the parameter is having less than one elements or strings then it returns undefined and if the parameter is having string including some integers value then the standard deviation of the integer’s value is returned.
Ref: https://devdocs.io/d3~4/d3-array#deviation
Recommended Posts:
- How to call a function that return another function in JavaScript ?
- How to get the function name from within that function using JavaScript ?
- How to get the function name inside a function in PHP ?
- PHP | max( ) Function
- D3.js | d3.min() function
- D3.js | d3.map.set() Function
- PHP | min( ) Function
- CSS | rgb() Function
- PHP | Ds\Map get() Function
- D3.js | d3.lab() Function
- p5.js | value() Function
- p5.js | str() function
- CSS | var() Function
- D3.js | d3.hcl() Function
- PHP | dir() Function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



