Created
September 25, 2014 17:04
-
-
Save floswald/f7b4ef9f0e6746e928c5 to your computer and use it in GitHub Desktop.
demean
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
julia> using DataFrames, DataFramesMeta, Lazy | |
julia> df = DataFrame(id=[1,1,1,2,2,2,3,3,3],x=rand(9)) | |
9x2 DataFrame | |
| Row | id | x | | |
|-----|----|-----------| | |
| 1 | 1 | 0.0470736 | | |
| 2 | 1 | 0.440199 | | |
| 3 | 1 | 0.156013 | | |
| 4 | 2 | 0.864873 | | |
| 5 | 2 | 0.236155 | | |
| 6 | 2 | 0.851055 | | |
| 7 | 3 | 0.672592 | | |
| 8 | 3 | 0.30145 | | |
| 9 | 3 | 0.987773 | | |
julia> @> df @by(:id,demeanx = :x .- mean(:x)) | |
9x2 DataFrame | |
| Row | id | demeanx | | |
|-----|----|------------| | |
| 1 | 1 | -0.167355 | | |
| 2 | 1 | 0.225771 | | |
| 3 | 1 | -0.0584158 | | |
| 4 | 2 | 0.214178 | | |
| 5 | 2 | -0.414539 | | |
| 6 | 2 | 0.200361 | | |
| 7 | 3 | 0.0186536 | | |
| 8 | 3 | -0.352488 | | |
| 9 | 3 | 0.333835 | | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment