Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Selected Reading
How to find the sum of squared deviations for an R data frame column?
The sum of squared deviations is the total of the square of difference between each value and the mean. To find this value, we need to create the formula in R platform. For example, if we have a data frame called df that contains a column x then the sum of squared deviations for x can be calculated by using sum((df$x−mean(df$x))^2).
Example1
y1<−1:20 y2<−rnorm(20,2525,301.2) df2<−data.frame(y1,y2) df2
Output
y1 y2 1 1 2643.340 2 2 2682.804 3 3 2555.982 4 4 2906.473 5 5 1771.400 6 6 2763.651 7 7 2818.183 8 8 3184.697 9 9 2731.398 10 10 2530.297 11 11 2361.374 12 12 2534.605 13 13 2266.180 14 14 2237.827 15 15 3178.079 16 16 2761.979 17 17 2224.662 18 18 2351.776 19 19 2200.108 20 20 2067.530
Finding the sum of squared deviations for column y2 in df2 −
Example
sum((df2$y2−mean(df2$y2))^2)
Output
[1] 2464370
Advertisements
