-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #23 from iuliadmtru/dimnames
Implement `dimnames`, `dim` and `colnames`
- Loading branch information
Showing
4 changed files
with
91 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
""" | ||
dim(design) | ||
Get the dimensions of a survey design. | ||
```jldoctest | ||
julia> using Survey | ||
julia> data(api); | ||
julia> dstrat = svydesign(data = apistrat, id = :1, strata = :stype, weights = :pw, fpc = :fpc); | ||
julia> dim(dstrat) | ||
(200, 44) | ||
``` | ||
""" | ||
dim(design::svydesign) = size(design.variables) | ||
|
||
""" | ||
colnames(design) | ||
Get the column names of a survey design. | ||
```jldoctest | ||
julia> using Survey | ||
julia> data(api); | ||
julia> dstrat = svydesign(data = apistrat, id = :1, strata = :stype, weights = :pw, fpc = :fpc); | ||
julia> colnames(dstrat) | ||
44-element Vector{String}: | ||
"Column1" | ||
"cds" | ||
"stype" | ||
"name" | ||
"sname" | ||
"snum" | ||
"dname" | ||
"dnum" | ||
"cname" | ||
"cnum" | ||
⋮ | ||
"emer" | ||
"enroll" | ||
"api.stu" | ||
"pw" | ||
"fpc" | ||
"probs" | ||
"popsize" | ||
"sampsize" | ||
"strata" | ||
``` | ||
""" | ||
colnames(design::svydesign) = names(design.variables) | ||
|
||
""" | ||
dimnames(design) | ||
Get the names of the rows and columns of a survey design. | ||
```jldoctest | ||
julia> using Survey | ||
julia> data(api); | ||
julia> dstrat = svydesign(data = apistrat, id = :1, strata = :stype, weights = :pw, fpc = :fpc); | ||
julia> dimnames(dstrat) | ||
2-element Vector{Vector{String}}: | ||
["1", "2", "3", "4", "5", "6", "7", "8", "9", "10" … "191", "192", "193", "194", "195", "196", "197", "198", "199", "200"] | ||
["Column1", "cds", "stype", "name", "sname", "snum", "dname", "dnum", "cname", "cnum" … "full", "emer", "enroll", "api.stu", "pw", "fpc", "probs", "popsize", "sampsize", "strata"] | ||
``` | ||
""" | ||
dimnames(design::svydesign) = [string.(1:size(design.variables, 1)), names(design.variables)] |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using Survey | ||
using Test | ||
|
||
@testset "dimnames.jl" begin | ||
data(api) | ||
dstrat = svydesign(data = apistrat, id = :1, strata = :stype, weights = :pw, fpc = :fpc) | ||
|
||
@test dim(dstrat)[1] == 200 | ||
@test dim(dstrat)[2] == size(dstrat.variables, 2) | ||
|
||
@test length(colnames(dstrat)) == dim(dstrat)[2] | ||
|
||
@test length(dimnames(dstrat)[1]) == parse(Int, last(dimnames(dstrat)[1])) | ||
@test dimnames(dstrat)[2] == colnames(dstrat) | ||
end |
This file contains 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