Julia ใง็ตฑ่จ่งฃๆใ็ฌฌ 4 ็ซ ใไธๅค้็ตฑ่จยถ
Version()
ๆๆฐใใผใธใงใณ 2024-07-18 11:11
ไธๅค้็ตฑ่จยถ
ใตใณใใซใตใคใบ๏ผ๏ผ็ฎ่ก๏ผๅนณๅๅค๏ผไธๅๅๆฃ๏ผๆจๆบๅๅทฎใฏๅบๆฌ็ตฑ่จ้ใจๅผใฐใใใใใฎไปใซไบๆฐ่ฆ็ดๅคใงใใๆๅฐๅค๏ผ็ฌฌไธๅๅไฝๆฐ๏ผไธญๅคฎๅค๏ผ็ฌฌไบๅๅไฝๆฐ๏ผ๏ผ็ฌฌไธๅๅไฝๆฐ๏ผๆๅคงๅคใๅฟ ่ฆใงใใใ
R ใซ็จๆใใใฆใใ airquality
ใใผใฟใปใใใ็จใใฆไพ็คบใใใ
using RCall
airquality = rcopy(R"airquality");
println("size: ", size(airquality))
first(airquality, 5)
size: (153, 6)
Row | Ozone | Solar_R | Wind | Temp | Month | Day |
---|---|---|---|---|---|---|
Int64? | Int64? | Float64 | Int64 | Int64 | Int64 | |
1 | 41 | 190 | 7.4 | 67 | 5 | 1 |
2 | 36 | 118 | 8.0 | 72 | 5 | 2 |
3 | 12 | 149 | 12.6 | 74 | 5 | 3 |
4 | 18 | 313 | 11.5 | 62 | 5 | 4 |
5 | missing | missing | 14.3 | 56 | 5 | 5 |
Ozone
, Solar_R
ใฏๆฌ ๆๅคใๅซใใฎใงๅใๆฑใใซๆณจๆใๅฟ
่ฆใงใใใdropmissing()
ใซใใๆฌ ๆๅคใใชในใใฏใคใบ้คๅปใใใใผใฟใใฌใผใ ใไฝใฃใฆใใใๅๆใซ๏ผๅๆใซๅฟ
่ฆใฎใชใๅคๆฐใใ้ธๆใใชใใ๏ผใใไปฅๅคใ้ธๆใใ๏ผใใใซ select()
ใไฝฟใใ
using DataFrames
airquality2 = dropmissing(select(airquality, Not([:Month, :Day])))
# airquality2 = dropmissing(select(airquality, [1, 2, 3, 4])) ใชใฉใจๅใ
println("size: ", size(airquality2))
first(airquality2, 5)
size: (111, 4)
Row | Ozone | Solar_R | Wind | Temp |
---|---|---|---|---|
Int64 | Int64 | Float64 | Int64 | |
1 | 41 | 190 | 7.4 | 67 |
2 | 36 | 118 | 8.0 | 72 |
3 | 12 | 149 | 12.6 | 74 |
4 | 18 | 313 | 11.5 | 62 |
5 | 23 | 299 | 8.6 | 65 |
ไธๅคๆฐใฎๅ ดๅยถ
ๅบ็ค็ตฑ่จ้ยถ
ๅๅค้ใฎๅบ็ค็ตฑ่จ้ใๆฑใใ้ขๆฐใจใใฆ๏ผsum()
, mean()
, var()
, std()
, median()
, quantile()
ใใใใ
ๅๅฅใฎๅคๆฐใซๅฏพใใฆ้ฉ็จใใๅ ดๅใฏไปฅไธใฎใใใซใใใ
using Statistics
mean(airquality.Ozone)
missing
Ozone
ใซใฏๆฌ ๆๅค missing
ใๅซใพใใฆใใใฎใง๏ผๅนณๅๅคใๆฑใใใใใซใฏๅใใฃใฆ skipmissing()
ใ้ฉ็จใใชใใใฐใชใใชใใ
mean(skipmissing(airquality.Ozone))
42.12931034482759
ไฝๅใ Ozone
ใซใคใใฆ็ตฑ่จๅฆ็ใใใๅ ดๅ๏ผไฝฟ็จใใใใณใซ skipmissing()
ใใใฎใฏ็ก้งใชใฎใง๏ผ็ตๆใๅคๆฐใซไปฃๅ
ฅใใฆใใใฐใใใ
ใชใ๏ผไปฅไธใฎไฝฟ็จไพใงๆๅพใซ |> plintln
ใใคใใฆใใใฎใฏใใฎ่ณๆไฝๆใใผใซใฎใใใซๅฏพๅฟใใใใใชใฎใง๏ผREPL ใขใผใใงๅฎ่กใใๅ ดๅใฏไธ่ฆใงใใใ
x = skipmissing(airquality.Ozone);
mean(x) |> println
var(x) |> println
std(x) |> println
42.12931034482759 1088.2005247376317 32.98788451443396
ใชใ๏ผairquality2
ใฏไธใคใงใๆฌ ๆๅคใๅซใ่กใฏๅ้คใใฆใใใฎใง๏ผairquality2
ใซใใใฆใฏ skipmissing()
ใไฝฟใๅฟ
่ฆใฏใชใใ๏ผใตใณใใซใตใคใบใ็ฐใชใใฎใง๏ผ็ตๆใ้ใใใจใซๆณจๆใใๅฟ
่ฆใใใใ
mean(airquality2.Ozone)
42.0990990990991
ใใผใฟใฎๅๆฐใฏ length()
ใง็ขบ่ชใงใใใ skipmissing()
ใงๅพใใใใใผใฟใฏไฝฟ็จใงใใชใใไปฅไธใงๅฎ็พฉใใใใใช filter()
ใไฝฟใๅฟ
่ฆใใใใfilter()
ใฏ๏ผๆฌ ๆๅคใ้คใใใผใฟใไฝใใskipmissing()
ใฏๆฌ ๆๅคใๅซใใใผใฟใจใใใใผใฟๅใไฝใใ ใใง๏ผๅฎ้ใซ missing
ใ้คๅปใใใใใใงใฏใชใใใใใ๏ผไปใฎ็ตฑ่จ้ขๆฐใงใฏ skipmissing()
ใซใใๅ ดๅใ filter(!ismissing, )
ใซใใๅ ดๅใ็ตๆใฏๅใใงใใใ
y = filter(!ismissing, airquality.Ozone)
mean(y) |> println
var(y) |> println
std(y) |> println
length(y) |> println
42.12931034482759 1088.200524737631 32.987884514433944 116
ใใผใปใณใฟใคใซๅคยถ
ใใผใปใณใฟใคใซๅคใฏ quantile()
ใงๆฑใใใ็ฌฌ 2 ๅผๆฐใง ไปปๆใฎ q
ๅคใใใฏใใซใงๆๅฎใงใใใ
using StatsBase
quantile(skipmissing(airquality.Ozone), [0, 0.25, 0.5, 0.75, 1])
5-element Vector{Float64}: 1.0 18.0 31.5 63.25 168.0
quantile(airquality2.Ozone, [0, 0.25, 0.5, 0.75, 1])
5-element Vector{Float64}: 1.0 18.0 31.0 62.0 168.0
ๅบฆๆฐๅๅธยถ
ใซใใดใชใผๅคๆฐใฎๅบฆๆฐๅๅธใฏ freqtable()
ใงๆฑใใใfreqtable()
ใฏๆฌ ๆๅค missing
ใฎๅๆฐใใซใฆใณใใใใ
chickwts
ใฏ๏ผ้คใฎๆทปๅ ็ฉ๏ผfeed
๏ผใฎ็จฎ้กใซใใ้้ณฅใฎไฝ้๏ผweight
๏ผใฎใใผใฟใปใใใงใใใ
using RCall
chickwts = rcopy(R"chickwts")
using FreqTables
freqtable(chickwts.feed)
6-element Named Vector{Int64} Dim1 โ โโโโโโโโโโโผโโโ casein โ 12 horsebean โ 10 linseed โ 12 meatmeal โ 11 soybean โ 14 sunflower โ 12
่คๆฐใฎๅคๆฐใฎๅ ดๅยถ
ๅๆๅฏพ่ฑกใ่คๆฐใฎๅคๆฐใฎๅ ดๅใซ๏ผๅคๆฐใ 1 ใคใใคๅๆใใใฎใฏๅน็ใๆชใใ
ใพใจใใฆๅฆ็ใใใใใซ๏ผeachcol()
, describe()
, combine()
้ขๆฐใใใใ
eachcol() ใไฝฟใยถ
eachcol()
ใฏใใผใฟใใฌใผใ ใฎๅๅใซๅฏพใใฆ้ขๆฐใ้ฉ็จใ๏ผ็ตๆใใใฏใใซใจใใฆ่ฟใใ
mean
ใฎๅพใซ .
ใใคใใฆใใใฎใฏ๏ผmean
ใ่คๆฐใฎ่ฆ็ด ๏ผใใผใฟใใฌใผใ ใฎๅๅ๏ผใซๅฏพใใฆๅฆ็ใ่กใใใใซใใใใใงใใใ
airquality = rcopy(R"airquality")
first(airquality, 10)
Row | Ozone | Solar_R | Wind | Temp | Month | Day |
---|---|---|---|---|---|---|
Int64? | Int64? | Float64 | Int64 | Int64 | Int64 | |
1 | 41 | 190 | 7.4 | 67 | 5 | 1 |
2 | 36 | 118 | 8.0 | 72 | 5 | 2 |
3 | 12 | 149 | 12.6 | 74 | 5 | 3 |
4 | 18 | 313 | 11.5 | 62 | 5 | 4 |
5 | missing | missing | 14.3 | 56 | 5 | 5 |
6 | 28 | missing | 14.9 | 66 | 5 | 6 |
7 | 23 | 299 | 8.6 | 65 | 5 | 7 |
8 | 19 | 99 | 13.8 | 59 | 5 | 8 |
9 | 8 | 19 | 20.1 | 61 | 5 | 9 |
10 | missing | 194 | 8.6 | 69 | 5 | 10 |
M = mean.(eachcol(airquality));
M
6-element Vector{Union{Missing, Float64}}: missing missing 9.957516339869283 77.88235294117646 6.993464052287582 15.803921568627452
REPL ใงใฎๅบๅใจ๏ผprintln()
ใงใฎๅบๅๅฝขๅผใ็ฐใชใใฎใง๏ผDataFrame()
ใซใใฆใใ println()
ใใใฐใใใ
ใชใ๏ผใใฎใพใพใงใฏๅ่กใฎๅคๆฐๅใ่กจ็คบใใใชใใฎใง๏ผDataFrame()
ใง๏ผvariable=names(ใใผใฟใใฌใผใ ๅ)
ใจใใใฐ 1 ๅ็ฎใซๅคๆฐๅใไปๅ ใใใใ
DataFrame()
ใฎไธญใงใฎ๏ผa=b
ใจใใๆๅฎใฏ๏ผใๅคๆฐ b
ใๅๅ a
ใจใใฆใใผใฟใใฌใผใ ใซๅซใใใใจใใๆๅณใงใใ๏ผa
ใจ b
ใๅใใงใๆงใใชใ๏ผใ
DataFrame(variable=names(airquality), Mean=M) |> println
6ร2 DataFrame Row โ variable Mean โ String Float64? โโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโ 1 โ Ozone missing 2 โ Solar_R missing 3 โ Wind 9.95752 4 โ Temp 77.8824 5 โ Month 6.99346 6 โ Day 15.8039
ๅๅคๆฐใซๆฌ ๆๅคใๅซใพใใๅ ดๅใซใฏ skipmissing()
ใใๅพใซ็ตฑ่จ้ขๆฐใ้ฉ็จใใชใใใฐใชใใชใใฎใง๏ผไปฅไธใฎใใใซใใใ
map()
ใฏ๏ผ็ฌฌ 2 ๅผๆฐใฎใใใใใฎ่ฆ็ด ใซๅฏพใใฆ ็ฌฌ 1 ๅผๆฐใงๅฎ็พฉใใใ้ขๆฐใ้ฉ็จใใใ้ขๆฐใฏๆฎ้ใฎ้ขๆฐใจ็กๅ้ขๆฐใฎๅ ดๅใใใใ็กๅ้ขๆฐใฏใไปฎๅผๆฐ -> ้ขๆฐๅฎ็พฉใใฎๅฝขใใใฆใใใ
M = map(x -> mean(skipmissing(x)), eachcol(airquality))
M
6-element Vector{Float64}: 42.12931034482759 185.93150684931507 9.95751633986928 77.88235294117646 6.993464052287582 15.803921568627452
ไธใฎไพใงไฝฟ็จใใ็กๅ้ขๆฐใจๅใใใจใใใๆฎ้ใฎ้ขๆฐใจใใฆๅฎ็พฉใ๏ผใใใ map()
ใงไฝฟ็จใใๅ ดๅใฏไปฅไธใฎใใใซใชใใ
mean2(x) = mean(skipmissing(x))
M = map(mean2, eachcol(airquality))
6-element Vector{Float64}: 42.12931034482759 185.93150684931507 9.95751633986928 77.88235294117646 6.993464052287582 15.803921568627452
่คๆฐใฎ็ตฑ่จ้ใ่จ็ฎใใฆใใใใ DataFtame()
ใงใพใจใใฆไธ่ฆง่กจใซใใใใจใใงใใใ
M = map(x -> mean(skipmissing(x)), eachcol(airquality))
V = map(x -> var(skipmissing(x)), eachcol(airquality))
S = map(x -> std(skipmissing(x)), eachcol(airquality))
n = map(x -> length(filter(!ismissing, x)), eachcol(airquality))
DataFrame(variable=names(airquality), n=n, Mean=M, Var=V, SD=S)
Row | variable | n | Mean | Var | SD |
---|---|---|---|---|---|
String | Int64 | Float64 | Float64 | Float64 | |
1 | Ozone | 116 | 42.1293 | 1088.2 | 32.9879 |
2 | Solar_R | 146 | 185.932 | 8110.52 | 90.0584 |
3 | Wind | 153 | 9.95752 | 12.4115 | 3.523 |
4 | Temp | 153 | 77.8824 | 89.5913 | 9.46527 |
5 | Month | 153 | 6.99346 | 2.00654 | 1.41652 |
6 | Day | 153 | 15.8039 | 78.5797 | 8.86452 |
ใใฎใใใซ map()
ใไฝฟใๆนๆณใฏ๏ผๅใใใใชๆๅฎใไฝๅใ็นฐใ่ฟใใชใใใฐใชใใชใใ๏ผๅฟ
่ฆใชๅฆ็ใใพใจใใฆ้ขๆฐๅใใฆใใใฐ 1 ่กใฎ้ขๆฐๅผใณๅบใใงๅฎ่กใงใใใฎใง็ฐกๅใซไฝฟ็จใงใใใ
using Statistics
function describe2(df)
M = map(x -> mean(skipmissing(x)), eachcol(df))
V = map(x -> var(skipmissing(x)), eachcol(df))
S = map(x -> std(skipmissing(x)), eachcol(df))
n = map(x -> length(filter(!ismissing, x)), eachcol(df))
DataFrame(variable=names(df), n=n, Mean=M, Var=V, SD=S)
end
describe2 (generic function with 1 method)
describe2(airquality) |> println
6ร5 DataFrame Row โ variable n Mean Var SD โ String Int64 Float64 Float64 Float64 โโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ 1 โ Ozone 116 42.1293 1088.2 32.9879 2 โ Solar_R 146 185.932 8110.52 90.0584 3 โ Wind 153 9.95752 12.4115 3.523 4 โ Temp 153 77.8824 89.5913 9.46527 5 โ Month 153 6.99346 2.00654 1.41652 6 โ Day 153 15.8039 78.5797 8.86452
describe2(airquality2) |> println
4ร5 DataFrame Row โ variable n Mean Var SD โ String Int64 Float64 Float64 Float64 โโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ 1 โ Ozone 111 42.0991 1107.29 33.276 2 โ Solar_R 111 184.802 8308.74 91.1523 3 โ Wind 111 9.93964 12.6573 3.55771 4 โ Temp 111 77.7928 90.8203 9.52997
describe()
ใไฝฟใยถ
describe()
ใงใฏ๏ผใใ็ฐกๅใซ่คๆฐใฎๅคๆฐใซๅฏพใใฆ่คๆฐใฎ็ตฑ่จ้ใใพใจใใฆๆฑใใใใจใใงใใใ
ๅฟ
่ฆใช็ตฑ่จ้ใฏ็ฌฌ 2 ๅผๆฐไปฅ้ใซไปปๆใฎ้ ๅบใงใทใณใใซใซใใฃใฆๅๆใใใๆๅฎใงใใใฎใฏ :mean
, :std
, :min
, :q25
, :median
, :q75
, :max
, :nunique
, :nmissing
, :first
, :last
, :eltype
ใงใใใ
ใในใฆใฎ็ตฑ่จ้ใ่จ็ฎใใใจใใฏ :all
ใๆๅฎใใใฐใใใ
describe()
ใซใฏ็ทๅ sum()
๏ผไธๅๅๆฃ var()
ใฏๅฎ่ฃ
ใใใฆใใชใใ
describe()
ใงใฏใใผใปใณใฟใคใซๅคใฏ q0
(min
), q25
, q50
(median
), q75
, q100
(max
) ใๆฑใใใใจใใงใใใ
ใชใ๏ผREPL ใงใฏ็ตๆใฎๅบๅๆกๆฐ๏ผๅน
๏ผใซใใ่กจ็คบใๆใกๅใใใใ
ไปฅไธใฎใใใซ printlins()
ใงๆ็คบ็ใซๅบๅใใใฐๆใกๅใใใใใจใฏใชใใ
ใใ ใ๏ผ็ฉ็็ใชๅบๅๆกๆฐใฎๅถ้ใซใใๆใ่ฟใ่กจ็คบใใใใฎใง่ฆใซใใใชใใใจใฏใใใ
println(describe(airquality, :all))
6ร16 DataFrame Row โ variable mean std min q25 median q75 max sum nunique nuniqueall nmissing nnonmissing first last eltype โ Symbol Float64 Float64 Real Float64 Float64 Float64 Real Real Nothing Int64 Int64 Int64 Real Real Type โโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ 1 โ Ozone 42.1293 32.9879 1 18.0 31.5 63.25 168 4887 67 37 116 41 20 Union{Missing, Int64} 2 โ Solar_R 185.932 90.0584 7 115.75 205.0 258.75 334 27146 117 7 146 190 223 Union{Missing, Int64} 3 โ Wind 9.95752 3.523 1.7 7.4 9.7 11.5 20.7 1523.5 31 0 153 7.4 11.5 Float64 4 โ Temp 77.8824 9.46527 56 72.0 79.0 85.0 97 11916 40 0 153 67 68 Int64 5 โ Month 6.99346 1.41652 5 6.0 7.0 8.0 9 1070 5 0 153 5 9 Int64 6 โ Day 15.8039 8.86452 1 8.0 16.0 23.0 31 2418 31 0 153 1 30 Int64
sum()
, var()
ใซๅฏพๅฟใใ้ขๆฐ describe2()
ใๅฎ็พฉใใฆใใใๆๅฎใงใใใฎใฏ :sum
, :mean
, :var
, :std
, :min
, :q25
, :median
, :q75
, :max
, :nmissing
ใงใใใ
ใในใฆใฎ็ตฑ่จ้ใ่จ็ฎใใใจใใฏ๏ผ็ตฑ่จ้ใฎๆๅฎใใใชใใใใซใใใ :all
ใๆๅฎใใใฐใใใ
function describe2(df, arg...=:all)
q25(x) = quantile(x, 0.25)
q75(x) = quantile(x, 0.75)
nmissing(x) = nrow(df) - length(ismissing.(x))
arg0 = [:sum, :mean, :var, :std, :min, :q25, :median, :q75, :max, :nmissing]
func = [sum, mean, var, std, minimum, q25, median, q75, maximum, nmissing]
funcname = ["sum", "mean", "var", "std", "minimum", "q25", "median", "q75", "maximum", "nmissing"]
arg[1] == :all && (arg = arg0)
res = DataFrame(variable = Symbol.(names(df)))
n = ncol(df)
m = length(arg)
body = Array{Float64, 2}(undef, n, m)
loc = indexin(arg, arg0)
for i in 1:n
x = skipmissing(df[!, i])
body[i, :] = [func[j](x) for j in loc]
end
bodydf = DataFrame(body, funcname[loc])
pos = indexin(["nmissing"], funcname[loc])[1]
isnothing(pos) || (bodydf[!, pos] = Int.(bodydf[:, pos]))
hcat(res, bodydf)
end
describe2(airquality) |> println; println()
describe2(airquality, :all) |> println; println()
describe2(airquality, :q25, :q75, :nmissing) |> println; println()
describe2(airquality2, :q25, :q75, :nmissing) |> println; println()
6ร11 DataFrame Row โ variable sum mean var std minimum q25 median q75 maximum nmissing โ Symbol Float64 Float64 Float64 Float64 Float64 Float64 Float64 Float64 Float64 Int64 โโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ 1 โ Ozone 4887.0 42.1293 1088.2 32.9879 1.0 18.0 31.5 63.25 168.0 37 2 โ Solar_R 27146.0 185.932 8110.52 90.0584 7.0 115.75 205.0 258.75 334.0 7 3 โ Wind 1523.5 9.95752 12.4115 3.523 1.7 7.4 9.7 11.5 20.7 0 4 โ Temp 11916.0 77.8824 89.5913 9.46527 56.0 72.0 79.0 85.0 97.0 0 5 โ Month 1070.0 6.99346 2.00654 1.41652 5.0 6.0 7.0 8.0 9.0 0 6 โ Day 2418.0 15.8039 78.5797 8.86452 1.0 8.0 16.0 23.0 31.0 0 6ร11 DataFrame Row โ variable sum mean var std minimum q25 median q75 maximum nmissing โ Symbol Float64 Float64 Float64 Float64 Float64 Float64 Float64 Float64 Float64 Int64 โโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ 1 โ Ozone 4887.0 42.1293 1088.2 32.9879 1.0 18.0 31.5 63.25 168.0 37 2 โ Solar_R 27146.0 185.932 8110.52 90.0584 7.0 115.75 205.0 258.75 334.0 7 3 โ Wind 1523.5 9.95752 12.4115 3.523 1.7 7.4 9.7 11.5 20.7 0 4 โ Temp 11916.0 77.8824 89.5913 9.46527 56.0 72.0 79.0 85.0 97.0 0 5 โ Month 1070.0 6.99346 2.00654 1.41652 5.0 6.0 7.0 8.0 9.0 0 6 โ Day 2418.0 15.8039 78.5797 8.86452 1.0 8.0 16.0 23.0 31.0 0 6ร4 DataFrame Row โ variable q25 q75 nmissing โ Symbol Float64 Float64 Int64 โโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ 1 โ Ozone 18.0 63.25 37 2 โ Solar_R 115.75 258.75 7 3 โ Wind 7.4 11.5 0 4 โ Temp 72.0 85.0 0 5 โ Month 6.0 8.0 0 6 โ Day 8.0 23.0 0 4ร4 DataFrame Row โ variable q25 q75 nmissing โ Symbol Float64 Float64 Int64 โโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ 1 โ Ozone 18.0 62.0 0 2 โ Solar_R 113.5 255.5 0 3 โ Wind 7.4 11.5 0 4 โ Temp 71.0 84.5 0
ๅ
ใฎ describe()
ใซ :sum
ใจ :var
ใใซใๅฏพๅฟใใๅฅใใผใธใงใณใฎ้ขๆฐใๅ็คบใใฆใใใ
function getcol(df, sym, newsym)
df2 = describe(df, sym, :nmissing)
if sym == :mean
n = nrow(df)
df2[!, sym] .*= (n .- df2.nmissing)
else
df2[!, sym] .*= df2[:, sym]
end
rename!(df2, sym => newsym)
end
function describe3(df, arg...)
length(arg) == 1 && arg[1] == :all && (arg = (:sum, :mean, :var, :std, :min, :q25, :median, :q75, :max, :nunique, :nmissing, :first, :last, :eltype))
df2 = DataFrame(variable = Symbol.(names(df)))
for a in arg
if a == :sum
df3 = getcol(df, :mean, :sum)
elseif a == :var
df3 = getcol(df, :std, :var)
else
df3 = describe(df, a)
end
df2 = hcat(df2, select(df3, 2))
end
df2
end
describe3(airquality, :all)
Row | variable | sum | mean | var | std | min | q25 | median | q75 | max | nunique | nmissing | first | last | eltype |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Symbol | Float64 | Float64 | Float64 | Float64 | Real | Float64 | Float64 | Float64 | Real | Nothing | Int64 | Real | Real | Type | |
1 | Ozone | 4887.0 | 42.1293 | 1088.2 | 32.9879 | 1 | 18.0 | 31.5 | 63.25 | 168 | 37 | 41 | 20 | Union{Missing, Int64} | |
2 | Solar_R | 27146.0 | 185.932 | 8110.52 | 90.0584 | 7 | 115.75 | 205.0 | 258.75 | 334 | 7 | 190 | 223 | Union{Missing, Int64} | |
3 | Wind | 1523.5 | 9.95752 | 12.4115 | 3.523 | 1.7 | 7.4 | 9.7 | 11.5 | 20.7 | 0 | 7.4 | 11.5 | Float64 | |
4 | Temp | 11916.0 | 77.8824 | 89.5913 | 9.46527 | 56 | 72.0 | 79.0 | 85.0 | 97 | 0 | 67 | 68 | Int64 | |
5 | Month | 1070.0 | 6.99346 | 2.00654 | 1.41652 | 5 | 6.0 | 7.0 | 8.0 | 9 | 0 | 5 | 9 | Int64 | |
6 | Day | 2418.0 | 15.8039 | 78.5797 | 8.86452 | 1 | 8.0 | 16.0 | 23.0 | 31 | 0 | 1 | 30 | Int64 |
่คๆฐใฎๅคๆฐใซๅฏพใใฆ๏ผไปปๆใฎ q
ๅคใซๅฏพใใใใผใปใณใฟใคใซๅคใๆฑใใใซใฏ๏ผไปฅไธใฎใใใช้ขๆฐใๅฎ็พฉใใใฐใใใmissing
ใ้คๅปใใฆ่จ็ฎใใใใ
function quantile2(df, qs=[0, 0.25, 0.5, 0.75, 1])
Names =["q$(Int(100q))" for q in qs]
Names = replace(Names, "q0" => "min", "q50" => "median", "q100" => "max")
qtile = map(x -> quantile(skipmissing(x), qs), eachcol(df))
df2 = DataFrame(Matrix(reshape(vcat(qtile...), length(qs), :)'), Names)
n = map(x -> length(filter(!ismissing, x)), eachcol(df))
insertcols!(df2, 1, :variable => names(df), :n => n)
df2
end
quantile2(airquality) |> println; println()
quantile2(airquality, [0.05, 0.25, 0.75, 0.95]) |> println; println()
6ร7 DataFrame Row โ variable n min q25 median q75 max โ String Int64 Float64 Float64 Float64 Float64 Float64 โโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ 1 โ Ozone 116 1.0 18.0 31.5 63.25 168.0 2 โ Solar_R 146 7.0 115.75 205.0 258.75 334.0 3 โ Wind 153 1.7 7.4 9.7 11.5 20.7 4 โ Temp 153 56.0 72.0 79.0 85.0 97.0 5 โ Month 153 5.0 6.0 7.0 8.0 9.0 6 โ Day 153 1.0 8.0 16.0 23.0 31.0 6ร6 DataFrame Row โ variable n q5 q25 q75 q95 โ String Int64 Float64 Float64 Float64 Float64 โโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ 1 โ Ozone 116 7.75 18.0 63.25 108.5 2 โ Solar_R 146 24.25 115.75 258.75 311.5 3 โ Wind 153 4.6 7.4 11.5 15.5 4 โ Temp 153 60.2 72.0 85.0 92.0 5 โ Month 153 5.0 6.0 8.0 9.0 6 โ Day 153 2.0 8.0 23.0 29.4
function quantile3(df, q=[0, 0.25, 0.5, 0.75, 1])
res = DataFrame(variable = Symbol.(names(df)))
n = ncol(df)
m = length(q)
body = Array{Float64, 2}(undef, n, m)
for i in 1:n
body[i, :] = quantile(skipmissing(df[!, i]), q)
end
colnames = ["q$(Int(q0*100))" for q0 in q]
replace!(colnames, "q0" => "min", "q50" => "median", "q100" => "max")
hcat(res, DataFrame(body, colnames))
end
quantile3(airquality) |> println; println()
quantile3(airquality2) |> println; println()
6ร6 DataFrame Row โ variable min q25 median q75 max โ Symbol Float64 Float64 Float64 Float64 Float64 โโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ 1 โ Ozone 1.0 18.0 31.5 63.25 168.0 2 โ Solar_R 7.0 115.75 205.0 258.75 334.0 3 โ Wind 1.7 7.4 9.7 11.5 20.7 4 โ Temp 56.0 72.0 79.0 85.0 97.0 5 โ Month 5.0 6.0 7.0 8.0 9.0 6 โ Day 1.0 8.0 16.0 23.0 31.0 4ร6 DataFrame Row โ variable min q25 median q75 max โ Symbol Float64 Float64 Float64 Float64 Float64 โโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ 1 โ Ozone 1.0 18.0 31.0 62.0 168.0 2 โ Solar_R 7.0 113.5 207.0 255.5 334.0 3 โ Wind 2.3 7.4 9.7 11.5 20.7 4 โ Temp 57.0 71.0 79.0 84.5 97.0
ใใผใปใณใฟใคใซๅคใๆฑใใ q
ๅคใๆๅฎใงใใใ
quantile2(airquality2, (1:2:9)./10)
Row | variable | n | q10 | q30 | median | q70 | q90 |
---|---|---|---|---|---|---|---|
String | Int64 | Float64 | Float64 | Float64 | Float64 | Float64 | |
1 | Ozone | 111 | 11.0 | 20.0 | 31.0 | 49.0 | 89.0 |
2 | Solar_R | 111 | 37.0 | 137.0 | 207.0 | 248.0 | 285.0 |
3 | Wind | 111 | 5.7 | 8.0 | 9.7 | 11.5 | 14.9 |
4 | Temp | 111 | 64.0 | 73.0 | 79.0 | 83.0 | 90.0 |
ๅๆใซไฝฟ็จใใๅคๆฐใฏไปฅไธใฎใใใซๆๅฎใงใใใฎใง๏ผๆฐใใใใผใฟใใฌใผใ ใไฝใๅฟ ่ฆใฏใชใใ
quantile2(airquality[:, [1, 3, 4]])
Row | variable | n | min | q25 | median | q75 | max |
---|---|---|---|---|---|---|---|
String | Int64 | Float64 | Float64 | Float64 | Float64 | Float64 | |
1 | Ozone | 116 | 1.0 | 18.0 | 31.5 | 63.25 | 168.0 |
2 | Wind | 153 | 1.7 | 7.4 | 9.7 | 11.5 | 20.7 |
3 | Temp | 153 | 56.0 | 72.0 | 79.0 | 85.0 | 97.0 |
combine(), select()/select!(), transform()/transform!() ใไฝฟใยถ
Hadley Wickham ใๆธใใ่ซๆ "The Split-Apply-Combine Strategy for Data Analysis" ใซใใใใใซ๏ผ็ตฑ่จ่งฃๆใฏใใใผใฟใใฐใซใผใๅใ(split)๏ผใใใใใฎใฐใซใผใใซ้ขๆฐใ้ฉ็จใ(apply)๏ผ็ตๆใใพใจใไธใใ(combine)ใใจใใไธๆฎต้ใใใชใใ
Julia ใงใฏใใใ๏ผcombin2
, select
/select!
, transform
/transform!
ใง่กใใ
combine()
ใฏ๏ผ็ฌฌ 1 ๅผๆฐใงๆธกใใใใใผใฟใใฌใผใ ใซใคใใฆ๏ผ็ฌฌ 2 ๅผๆฐไปฅ้ใงๆ็คบใใใ้ขๆฐใ้ฉ็จใ๏ผ็ตๆใใใผใฟใใฌใผใ ใซใพใจใใใ
ๆฌๆฅใฏ่คๆฐใฎใตใใฐใซใผใใซๅฏพใใฆ็จใใใใฎใงใใใ๏ผใใผใฟใใฌใผใ ๅ จไฝใ 1 ๅใฎใตใใฐใซใผใใซ้ใใชใใฎใง๏ผ้ฉ็จใใฆใใชใใฎๅ้กใใชใใ
็ฌฌ 2 ๅผๆฐใฏไฝ้ใใใฎๆธใๆนใใใใ
nrow
ใฎใใใซใใผใฟใใฌใผใ ใๅผๆฐใจใใ้ขๆฐๅใ ใใๆธใๅ ดๅใnrow()
ใฏใใผใฟใใฌใผใ ใซไฝ็จใใ้ขๆฐใง๏ผใใผใฟใใฌใผใ ใฎ่กๆฐใ่ฟใใ็ตๆใฎใใผใฟใใฌใผใ ใง๏ผnrow
ๅใซ 153 ใๆธใใใฆใใใ็ตๆใฏ 1 ๅใฎๆฐๅคใซ้ใใชใใใใจใใฐsize()
ใฏใใผใฟใใฌใผใ ใฎ่กๆฐใจๅๆฐใใฟใใซใง่ฟใใฎใง๏ผ็ตๆใฎ x1 ใฎๅใซ (153, 6) ใๆธใใใฆใใใๅๅใฎx1
ใฏใใใฉใซใใงใใใquantil()
ใฏใใฏใใซใ่ฟใใ๏ผtuple ใซๅคๆใใชใใจ็ตๆใ่ฆใซใใใชใใnrow => :ๅๅ
ใใฎใใใซๆธใใจ๏ผๅๅใๅฎ็พฉใงใใใ:nrow
ใจๆธใใใฎใง๏ผ็ตๆใฎใใผใฟใใฌใผใ ใง๏ผๅๅใn
ใซใชใฃใฆใใใ- ๆๅใฎ
=>
ใฎๅทฆใซใใใใฎใฏใใผใฟใใฌใผใ ใฎๅใ็คบใใใทใณใใซ(:
ใใคใใฆใใ๏ผใๆๅญๅ๏ผ" "
ใงๅฒใพใใฆใใ๏ผใๆฐๅญ๏ผๅใฎ็ชๅท๏ผใชใฉใฎๅ ดๅใใใใ - ๆๅใฎ
=>
ใฎๅณใซใใใฎใใฎใฏ้ขๆฐ๏ผ่ชไฝใฎ้ขๆฐใๅฏ๏ผใพใใฏ็กๅ้ขๆฐใงใใใ - ้ขๆฐใไฝๆฎต้ใ้ ็ชใซ้ฉ็จใใใจใใซใฏ็กๅ้ขๆฐใงๅฎ็พฉใใ๏ผ
=>
ใง้ขๆฐใๆฐ็ ใคใชใใซใใใใจใฏใงใใชใ๏ผใ - ้ขๆฐ/็กๅ้ขๆฐใฎๅพใซ
=>
ใซ็ถใใใฎใใใๅ ดๅใฏ๏ผใใใฏ็ตๆใฎใใผใฟใใฌใผใ ใฎๅๅใซใชใ๏ผ้่คใใๅๅใฏๆๅฎใงใใชใ๏ผใใชใๅ ดๅใซใฏใใใฉใซใใงใใฃใจใใใใๅๅใไปใใใใใ
function my_std(x)
mean = sum(x) / length(x)
var = sum((x .- mean).^2) / (length(x) - 1)
sqrt(var)
end
results = combine(airquality,
nrow,
size,
nrow => :n,
:Wind => std,
"Wind" => var => :var_wind,
3 => var => "var-wind",
3 => (x -> sqrt(var(x))) => "std-wind",
:Wind => my_std => "std-wind-2",
:Ozone => (x -> length(filter(!ismissing, x))) => "valid cases",
:Ozone => (x -> mean(skipmissing(x))) => :Mean,
:Temp => (x -> tuple(quantile(x, [0.25, 0.5, 0.75]))) => "%-tiles(25, 50, 75)"
)
typeof(results) |> println; println()
results |> println
DataFrame 1ร11 DataFrame Row โ nrow x1 n Wind_std var_wind var-wind std-wind std-wind-2 valid cases Mean %-tiles(25, 50, 75) โ Int64 Tupleโฆ Int64 Float64 Float64 Float64 Float64 Float64 Int64 Float64 Tupleโฆ โโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ 1 โ 153 (153, 6) 153 3.523 12.4115 12.4115 3.523 3.523 116 42.1293 ([72.0, 79.0, 85.0],)
ใฐใซใผใใใจใฎ่จ่ฟฐ็ตฑ่จ้ยถ
ใใผใฟใใฌใผใ ใใฐใซใผใใ่กจใๅคๆฐใงใฐใซใผใๅใ๏ผใใใใใฎใตใใฐใซใผใใใจใซ็ตฑ่จ้ใๆฑใใใ
airquality
ใใผใฟใปใใใฎ :Month
ใงใฐใซใผใๅใใใ
select()
/select!()
ใฏใใผใฟใใฌใผใ ใฎๅใ้ธๆใใใNot(ใทใณใใซ)
๏ผNot(ใทใณใใซใใฏใใซ)
ใฏใใใใๅซใพใชใใใจใ่กจใใ
groupby(ใใผใฟใใฌใผใ ๏ผใฐใซใผใๅใซไฝฟใๅใฎๆๅฎ)
ใงใฐใซใผใๅใใใๅใฎๆๅฎใฏใใฏใใซใงใใใใ
using RCall
airquality = rcopy(R"airquality");
gdf = groupby(select(airquality, Not(:Day)), :Month);
println("number of subgroup = ", length(gdf))
number of subgroup = 5
gdf[1]
ใฏ :Month
ใ 5 ใฎๅ ดๅใฎใตใใฐใซใผใใงใใใ
first(gdf[1], 5)
Row | Ozone | Solar_R | Wind | Temp | Month |
---|---|---|---|---|---|
Int64? | Int64? | Float64 | Int64 | Int64 | |
1 | 41 | 190 | 7.4 | 67 | 5 |
2 | 36 | 118 | 8.0 | 72 | 5 |
3 | 12 | 149 | 12.6 | 74 | 5 |
4 | 18 | 313 | 11.5 | 62 | 5 |
5 | missing | missing | 14.3 | 56 | 5 |
describe() ใไฝฟใยถ
groupby()
ใซใใๅๅฒใใใใใใใใฎ gdf[i]
ใฏ๏ผใใผใฟใใฌใผใ ใชใฎใง๏ผๅ็ฏใซ่ฟฐในใๆนๆณใใใฎใพใพ้ฉ็จใงใใใ
describe(select(gdf[1], Not(:Month)))
Row | variable | mean | min | median | max | nmissing | eltype |
---|---|---|---|---|---|---|---|
Symbol | Float64 | Real | Float64 | Real | Int64 | Type | |
1 | Ozone | 23.6154 | 1 | 18.0 | 115 | 5 | Union{Missing, Int64} |
2 | Solar_R | 181.296 | 8 | 194.0 | 334 | 4 | Union{Missing, Int64} |
3 | Wind | 11.6226 | 5.7 | 11.5 | 20.1 | 0 | Float64 |
4 | Temp | 65.5484 | 56 | 66.0 | 81 | 0 | Int64 |
describe2(select(gdf[1], Not(:Month)))
Row | variable | sum | mean | var | std | minimum | q25 | median | q75 | maximum | nmissing |
---|---|---|---|---|---|---|---|---|---|---|---|
Symbol | Float64 | Float64 | Float64 | Float64 | Float64 | Float64 | Float64 | Float64 | Float64 | Int64 | |
1 | Ozone | 614.0 | 23.6154 | 493.926 | 22.2244 | 1.0 | 11.0 | 18.0 | 31.5 | 115.0 | 5 |
2 | Solar_R | 4895.0 | 181.296 | 13242.4 | 115.075 | 8.0 | 72.0 | 194.0 | 284.5 | 334.0 | 4 |
3 | Wind | 360.3 | 11.6226 | 12.4711 | 3.53145 | 5.7 | 8.9 | 11.5 | 14.05 | 20.1 | 0 |
4 | Temp | 2032.0 | 65.5484 | 46.9892 | 6.85487 | 56.0 | 60.0 | 66.0 | 69.0 | 81.0 | 0 |
quantile(select(gdf[end], Not(:Month)).Wind)
5-element Vector{Float64}: 2.8 7.550000000000001 10.3 12.325 16.6
quantile2(select(gdf[end], Not(:Month)))
Row | variable | n | min | q25 | median | q75 | max |
---|---|---|---|---|---|---|---|
String | Int64 | Float64 | Float64 | Float64 | Float64 | Float64 | |
1 | Ozone | 29 | 7.0 | 16.0 | 23.0 | 36.0 | 96.0 |
2 | Solar_R | 30 | 14.0 | 116.75 | 192.0 | 234.5 | 259.0 |
3 | Wind | 30 | 2.8 | 7.55 | 10.3 | 12.325 | 16.6 |
4 | Temp | 30 | 63.0 | 71.0 | 76.0 | 81.0 | 93.0 |
for
ใซใผใใง๏ผใในใฆใฎใตใใฐใซใผใใซใคใใฆๅๆใงใใใ
for df in gdf
println("\nMonth: ", df[1, :Month], "\n", describe(select(df, Not(:Month))))
end
Month: 5 4ร7 DataFrame Row โ variable mean min median max nmissing eltype โ Symbol Float64 Real Float64 Real Int64 Type โโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ 1 โ Ozone 23.6154 1 18.0 115 5 Union{Missing, Int64} 2 โ Solar_R 181.296 8 194.0 334 4 Union{Missing, Int64} 3 โ Wind 11.6226 5.7 11.5 20.1 0 Float64 4 โ Temp 65.5484 56 66.0 81 0 Int64 Month: 6 4ร7 DataFrame Row โ variable mean min median max nmissing eltype โ Symbol Float64 Real Float64 Real Int64 Type โโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ 1 โ Ozone 29.4444 12 23.0 71 21 Union{Missing, Int64} 2 โ Solar_R 190.167 31 188.5 332 0 Union{Missing, Int64} 3 โ Wind 10.2667 1.7 9.7 20.7 0 Float64 4 โ Temp 79.1 65 78.0 93 0 Int64 Month: 7 4ร7 DataFrame Row โ variable mean min median max nmissing eltype โ Symbol Float64 Real Float64 Real Int64 Type โโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ 1 โ Ozone 59.1154 7 60.0 135 5 Union{Missing, Int64} 2 โ Solar_R 216.484 7 253.0 314 0 Union{Missing, Int64} 3 โ Wind 8.94194 4.1 8.6 14.9 0 Float64 4 โ Temp 83.9032 73 84.0 92 0 Int64 Month: 8 4ร7 DataFrame Row โ variable mean min median max nmissing eltype โ Symbol Float64 Real Float64 Real Int64 Type โโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ 1 โ Ozone 59.9615 9 52.0 168 5 Union{Missing, Int64} 2 โ Solar_R 171.857 24 197.5 273 3 Union{Missing, Int64} 3 โ Wind 8.79355 2.3 8.6 15.5 0 Float64 4 โ Temp 83.9677 72 82.0 97 0 Int64 Month: 9 4ร7 DataFrame Row โ variable mean min median max nmissing eltype โ Symbol Float64 Real Float64 Real Int64 Type โโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ 1 โ Ozone 31.4483 7 23.0 96 1 Union{Missing, Int64} 2 โ Solar_R 167.433 14 192.0 259 0 Union{Missing, Int64} 3 โ Wind 10.18 2.8 10.3 16.6 0 Float64 4 โ Temp 76.9 63 76.0 93 0 Int64
ๅคๆฐใใจใซ็ตฑ่จ้ใไธ่ฆง่กจ็คบยถ
ๅคๆฐใใจใซไธ่ฆง่กจ็คบใใใซใฏ๏ผใใใใใญใณใฐใใฉใผใใใใซใใฆๅฆ็ใใใๅฟ ่ฆใใใใ
long = stack(select(airquality, Not(:Day)), [:Ozone, :Solar_R, :Wind, :Temp])
gdf2 = groupby(long, [:variable, :Month]);
first(gdf2[1], 5)
Row | Month | variable | value |
---|---|---|---|
Int64 | String | Float64? | |
1 | 5 | Ozone | 41.0 |
2 | 5 | Ozone | 36.0 |
3 | 5 | Ozone | 12.0 |
4 | 5 | Ozone | 18.0 |
5 | 5 | Ozone | missing |
result = combine(gdf2, nrow,
:value => (x -> length(filter(!ismissing, x))) => :n,
:value => (x -> mean(skipmissing(x))) => :Mean,
:value => (x -> std(skipmissing(x))) => :SD,
);
result |> println
20ร6 DataFrame Row โ variable Month nrow n Mean SD โ String Int64 Int64 Int64 Float64 Float64 โโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ 1 โ Ozone 5 31 26 23.6154 22.2244 2 โ Ozone 6 30 9 29.4444 18.2079 3 โ Ozone 7 31 26 59.1154 31.6358 4 โ Ozone 8 31 26 59.9615 39.6812 5 โ Ozone 9 30 29 31.4483 24.1418 6 โ Solar_R 5 31 27 181.296 115.075 7 โ Solar_R 6 30 30 190.167 92.883 8 โ Solar_R 7 31 31 216.484 80.5683 9 โ Solar_R 8 31 28 171.857 76.8349 10 โ Solar_R 9 30 30 167.433 79.1183 11 โ Wind 5 31 31 11.6226 3.53145 12 โ Wind 6 30 30 10.2667 3.76923 13 โ Wind 7 31 31 8.94194 3.03598 14 โ Wind 8 31 31 8.79355 3.22593 15 โ Wind 9 30 30 10.18 3.46125 16 โ Temp 5 31 31 65.5484 6.85487 17 โ Temp 6 30 30 79.1 6.59859 18 โ Temp 7 31 31 83.9032 4.31551 19 โ Temp 8 31 31 83.9677 6.58526 20 โ Temp 9 30 30 76.9 8.35567
ๅฟ ่ฆใชใๅฐๅใใซใใฆ่กจ็คบใใใฐใใใ
result.variable
ใฎๅใฏ String
ใชใฎใง๏ผWind
ใฎ็ตๆใ ใใๆฝๅบใใใซใฏ result.variable .== "Wind"
ใจใใ๏ผ:Wind
ใงใฏใชใใฎใงๆณจๆ๏ผใ
result[result.variable .== "Wind", [:n, :Mean, :SD]]
Row | n | Mean | SD |
---|---|---|---|
Int64 | Float64 | Float64 | |
1 | 31 | 11.6226 | 3.53145 |
2 | 30 | 10.2667 | 3.76923 |
3 | 31 | 8.94194 | 3.03598 |
4 | 31 | 8.79355 | 3.22593 |
5 | 30 | 10.18 | 3.46125 |
function temp(i, sym1, df)
combine(filter(x -> x[sym1] == i, df),
:Wind => (x -> length(filter(!ismissing, x))) => :n,
:Wind => mean,
:Wind => std)
end
result2 = temp(5, :Month, airquality);
for i in 6:9
append!(result2, temp(i, :Month, airquality))
end
result2
Row | n | Wind_mean | Wind_std |
---|---|---|---|
Int64 | Float64 | Float64 | |
1 | 31 | 11.6226 | 3.53145 |
2 | 30 | 10.2667 | 3.76923 |
3 | 31 | 8.94194 | 3.03598 |
4 | 31 | 8.79355 | 3.22593 |
5 | 30 | 10.18 | 3.46125 |
ๆใใจใฎ็ตๆใๅฟ
่ฆใชใ Month
ใงใฝใผใใใฆ่กจ็คบใใใ
sort(result, :Month)
Row | variable | Month | nrow | n | Mean | SD |
---|---|---|---|---|---|---|
String | Int64 | Int64 | Int64 | Float64 | Float64 | |
1 | Ozone | 5 | 31 | 26 | 23.6154 | 22.2244 |
2 | Solar_R | 5 | 31 | 27 | 181.296 | 115.075 |
3 | Wind | 5 | 31 | 31 | 11.6226 | 3.53145 |
4 | Temp | 5 | 31 | 31 | 65.5484 | 6.85487 |
5 | Ozone | 6 | 30 | 9 | 29.4444 | 18.2079 |
6 | Solar_R | 6 | 30 | 30 | 190.167 | 92.883 |
7 | Wind | 6 | 30 | 30 | 10.2667 | 3.76923 |
8 | Temp | 6 | 30 | 30 | 79.1 | 6.59859 |
9 | Ozone | 7 | 31 | 26 | 59.1154 | 31.6358 |
10 | Solar_R | 7 | 31 | 31 | 216.484 | 80.5683 |
11 | Wind | 7 | 31 | 31 | 8.94194 | 3.03598 |
12 | Temp | 7 | 31 | 31 | 83.9032 | 4.31551 |
13 | Ozone | 8 | 31 | 26 | 59.9615 | 39.6812 |
14 | Solar_R | 8 | 31 | 28 | 171.857 | 76.8349 |
15 | Wind | 8 | 31 | 31 | 8.79355 | 3.22593 |
16 | Temp | 8 | 31 | 31 | 83.9677 | 6.58526 |
17 | Ozone | 9 | 30 | 29 | 31.4483 | 24.1418 |
18 | Solar_R | 9 | 30 | 30 | 167.433 | 79.1183 |
19 | Wind | 9 | 30 | 30 | 10.18 | 3.46125 |
20 | Temp | 9 | 30 | 30 | 76.9 | 8.35567 |
ไปฅไธใฎใใใชใใญใฐใฉใ ใๆธใใใจใใงใใใ
a = [describe(df) for df in gdf]
variable = [:Ozone, :Solar_R, :Wind, :Temp]
for i in variable
df = DataFrame[]
for j in 1:length(a)
pos = indexin([Symbol(i)], a[j][:, 1])[1]
ismissing(pos) && continue
row = DataFrame(a[j][pos, :])
if df == [] # first
df = row
else
append!(df, row)
end
end
println("\n", df[1,1])
rename!(df, 1 => :GroupKey)
nam = [replace("$key", "GroupKey: " => "") for key in keys(gdf)]
df[!, 1] = nam
println(df)
end
Ozone 5ร7 DataFrame Row โ GroupKey mean min median max nmissing eltype โ String Float64 Real Float64 Real Int64 Type โโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ 1 โ (Month = 5,) 23.6154 1 18.0 115 5 Union{Missing, Int64} 2 โ (Month = 6,) 29.4444 12 23.0 71 21 Union{Missing, Int64} 3 โ (Month = 7,) 59.1154 7 60.0 135 5 Union{Missing, Int64} 4 โ (Month = 8,) 59.9615 9 52.0 168 5 Union{Missing, Int64} 5 โ (Month = 9,) 31.4483 7 23.0 96 1 Union{Missing, Int64} Solar_R 5ร7 DataFrame Row โ GroupKey mean min median max nmissing eltype โ String Float64 Real Float64 Real Int64 Type โโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ 1 โ (Month = 5,) 181.296 8 194.0 334 4 Union{Missing, Int64} 2 โ (Month = 6,) 190.167 31 188.5 332 0 Union{Missing, Int64} 3 โ (Month = 7,) 216.484 7 253.0 314 0 Union{Missing, Int64} 4 โ (Month = 8,) 171.857 24 197.5 273 3 Union{Missing, Int64} 5 โ (Month = 9,) 167.433 14 192.0 259 0 Union{Missing, Int64} Wind 5ร7 DataFrame Row โ GroupKey mean min median max nmissing eltype โ String Float64 Real Float64 Real Int64 Type โโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ 1 โ (Month = 5,) 11.6226 5.7 11.5 20.1 0 Float64 2 โ (Month = 6,) 10.2667 1.7 9.7 20.7 0 Float64 3 โ (Month = 7,) 8.94194 4.1 8.6 14.9 0 Float64 4 โ (Month = 8,) 8.79355 2.3 8.6 15.5 0 Float64 5 โ (Month = 9,) 10.18 2.8 10.3 16.6 0 Float64 Temp 5ร7 DataFrame Row โ GroupKey mean min median max nmissing eltype โ String Float64 Real Float64 Real Int64 Type โโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ 1 โ (Month = 5,) 65.5484 56 66.0 81 0 Int64 2 โ (Month = 6,) 79.1 65 78.0 93 0 Int64 3 โ (Month = 7,) 83.9032 73 84.0 92 0 Int64 4 โ (Month = 8,) 83.9677 72 82.0 97 0 Int64 5 โ (Month = 9,) 76.9 63 76.0 93 0 Int64
using DataFrames, Statistics
for variable in [:Ozone, :Solar_R, :Wind, :Temp]
println("\n$variable")
result = DataFrame[]
for i in 1:length(gdf)
each = dropmissing(select(gdf[i], [:Month, variable]))
res = combine(each, :Month => first => :Month, nrow => :n, variable => mean => :Mean, variable => std => :SD)
if result == []
result = res
else
result = vcat(result, res)
end
end
println(result)
end
Ozone 5ร4 DataFrame Row โ Month n Mean SD โ Int64 Int64 Float64 Float64 โโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ 1 โ 5 26 23.6154 22.2244 2 โ 6 9 29.4444 18.2079 3 โ 7 26 59.1154 31.6358 4 โ 8 26 59.9615 39.6812 5 โ 9 29 31.4483 24.1418 Solar_R 5ร4 DataFrame Row โ Month n Mean SD โ Int64 Int64 Float64 Float64 โโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ 1 โ 5 27 181.296 115.075 2 โ 6 30 190.167 92.883 3 โ 7 31 216.484 80.5683 4 โ 8 28 171.857 76.8349 5 โ 9 30 167.433 79.1183 Wind 5ร4 DataFrame Row โ Month n Mean SD โ Int64 Int64 Float64 Float64 โโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ 1 โ 5 31 11.6226 3.53145 2 โ 6 30 10.2667 3.76923 3 โ 7 31 8.94194 3.03598 4 โ 8 31 8.79355 3.22593 5 โ 9 30 10.18 3.46125 Temp 5ร4 DataFrame Row โ Month n Mean SD โ Int64 Int64 Float64 Float64 โโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ 1 โ 5 31 65.5484 6.85487 2 โ 6 30 79.1 6.59859 3 โ 7 31 83.9032 4.31551 4 โ 8 31 83.9677 6.58526 5 โ 9 30 76.9 8.35567
ไบๅค้็ตฑ่จยถ
2 ๅค้ใฎ็ตฑ่จ้ใฏ๏ผใซใใดใชใผๅคๆฐใฎๅ ดๅใฏใฏใญใน้่จ่กจ๏ผ้้ๅฐบๅบฆๅคๆฐใฎๅ ดๅใฏใใขใฝใณใฎ็ฉ็็ธ้ขไฟๆฐ cor()
๏ผๅ
ฑๅๆฃ var()
๏ผ้ ๅบๅฐบๅบฆๅคๆฐใฎๅ ดๅใฏในใใขใใณใฎ้ ไฝ็ธ้ขไฟๆฐ corspearman()
๏ผใฑใณใใผใซใฎ้ ไฝ็ธ้ขไฟๆฐ corkendall()
ใใใใ
ไบ้ใฏใญใน้่จ่กจยถ
2 ๅค้ใฎๅฐใชใใจใ 1 ใคใใซใใดใชใผๅคๆฐ๏ผๅ็พฉๅฐบๅบฆๅคๆฐ๏ผ้ ๅบๅฐบๅบฆๅคๆฐ๏ผใฎๅ ดๅใซ็จใใใๅฏพใซใชใๅคๆฐใ้้ๅฐบๅบฆๅคๆฐ๏ผ้ๅฐบๅบฆๅคๆฐใฎๅ ดๅใฏ๏ผ้็ดๅใใใฆ้่จใใชใใใฐใชใใชใใ
็จใใใฎใฏ 1 ๅค้ใฎๅ ดๅใฎๅบฆๆฐๅๅธใไฝๆใใใฎใจๅใ freqtable()
ใงใใใ
esoph
ใฏใใฉใณในใซใใใๅซ็
ใป้ฃฒ้
ใจ้ฃ้็ใฎใฑใผในใปใณใณใใญใผใซ็ ็ฉถใฎ็ตๆใงใใใ้่จใใผใฟใชใฎใง๏ผๅ
ใใผใฟใซๅฑ้ใใใใฎใ็จใใใ
esoph = rcopy(R"esoph")
insertcols!(esoph, 6, :which => " ")
size(esoph) |> println
first(esoph, 2) |> println
(sum(esoph.ncases), sum(esoph.ncontrols)) |> println
(88, 6) 2ร6 DataFrame Row โ agegp alcgp tobgp ncases ncontrols which โ Catโฆ Catโฆ Catโฆ Float64 Float64 String โโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ 1 โ 25-34 0-39g/day 0-9g/day 0.0 40.0 2 โ 25-34 0-39g/day 10-19 0.0 10.0 (200.0, 775.0)
ESOPH = DataFrame()
for row in eachrow(esoph)
row.which = "Case"
for j in 1:row.ncases
push!(ESOPH, row)
end
row.which = "Control"
for j in 1:row.ncontrols
push!(ESOPH, row)
end
end
freqtable(ESOPH.which)
2-element Named Vector{Int64} Dim1 โ โโโโโโโโโผโโโโ Case โ 200 Control โ 775
select!(ESOPH, Not([:ncases, :ncontrols])); # ็ไพๆฐใฎ 2 ๅใ้คใ
size(ESOPH) |> println
first(ESOPH, 5) |> println
(975, 4) 5ร4 DataFrame Row โ agegp alcgp tobgp which โ Catโฆ Catโฆ Catโฆ String โโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ 1 โ 25-34 0-39g/day 0-9g/day Control 2 โ 25-34 0-39g/day 0-9g/day Control 3 โ 25-34 0-39g/day 0-9g/day Control 4 โ 25-34 0-39g/day 0-9g/day Control 5 โ 25-34 0-39g/day 0-9g/day Control
freqtable(ESOPH.agegp, ESOPH.alcgp)
6ร4 Named Matrix{Int64} Dim1 โฒ Dim2 โ 0-39g/day 40-79 80-119 120+ โโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ 25-34 โ 61 45 5 5 35-44 โ 89 80 20 10 45-54 โ 78 81 39 15 55-64 โ 89 84 43 26 65-74 โ 71 53 29 8 75+ โ 27 12 2 3
freqtable(ESOPH.agegp, ESOPH.tobgp)
6ร4 Named Matrix{Int64} Dim1 โฒ Dim2 โ 0-9g/day 10-19 20-29 30+ โโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ 25-34 โ 70 19 11 16 35-44 โ 109 46 27 17 45-54 โ 104 57 33 19 55-64 โ 117 65 38 22 65-74 โ 99 38 20 4 75+ โ 26 11 3 4
using RCall
airquality = rcopy(R"airquality");
airquality2 = dropmissing(select(airquality, Not([:Month, :Day])));
็ธ้ขไฟๆฐ๏ผๅ ฑๅๆฃยถ
ๆฌ ๆๅคใๅซใพใชใๅ ดๅยถ
ใใใใใฎ้ขๆฐใไฝฟใยถ
ๅคๆฐใฎๅฏพใใจใซ๏ผ้ขๆฐใ้ฉ็จใใใๅคๆฐใฎๆๅฎๆณใฏ่ฒใ ใใใ
cor(airquality2.Ozone, airquality2.Temp) |> println
corspearman(airquality2.Ozone, airquality2.Temp) |> println
corkendall(airquality2.Ozone, airquality2.Temp) |> println
cov(airquality2.Ozone, airquality2.Temp) |> println
cov(airquality2[!, :Ozone], airquality2.Temp) |> println
cov(airquality2[!, "Ozone"], airquality2.Temp) |> println
cov(airquality2[!, 1], airquality2.Temp) |> println
0.6985414096486391 0.7729319330689582 0.5861471249834473 221.52072072072067 221.52072072072067 221.52072072072067 221.52072072072067
combine() ใไฝฟใยถ
combine(airquality2,
[:Ozone, :Temp] => cor,
[:Ozone, :Wind] => cor,
[:Ozone, :Solar_R] => cor,
[:Ozone, :Solar_R] => corspearman,
)
Row | Ozone_Temp_cor | Ozone_Wind_cor | Ozone_Solar_R_cor | Ozone_Solar_R_corspearman |
---|---|---|---|---|
Float64 | Float64 | Float64 | Float64 | |
1 | 0.698541 | -0.612497 | 0.348342 | 0.348186 |
ๆฌ ๆๅคใๅซใๅ ดๅยถ
ใใใใใฎ้ขๆฐใไฝฟใยถ
ๆฌ ๆๅคใๅซใพใใใใผใฟใฎๅ ดๅใฏ๏ผไธกๆนใฎๅคๆฐใใจใใซ missing
ใงใชใใใผใฟๅฏพใฎใฟใๅๆใซไฝฟใใใใ
ๆนๆณใฏใใใคใใใใ๏ผairquality2
ใไฝใฃใใจใใจๅใใใใซ๏ผselect()
ใง 2 ๅคๆฐใฎใฟใๅซใใใผใฟใใฌใผใ ใไฝใ๏ผdropmissing()
ใงๆฌ ๆๅคใๅซใใใผใฟใ้คใใฎใใใฃใจใ็ฐกๅใงใใใใ
df = dropmissing(airquality[:, [:Ozone, :Temp]]);
first(df, 3)
Row | Ozone | Temp |
---|---|---|
Int64 | Int64 | |
1 | 41 | 67 |
2 | 36 | 72 |
3 | 12 | 74 |
cor(df.Ozone, df.Temp) |> println
corspearman(df.Ozone, df.Temp) |> println
corkendall(df.Ozone, df.Temp) |> println
cov(df.Ozone, df.Temp) |> println
0.6983603421509317 0.7740429554613014 0.5862988215264407 218.52121439280359
combine()
ใไฝฟใยถ
ๆฌ ๆๅคๅฆ็ใ่กใ็กๅ้ขๆฐใฎ่จ่ฟฐใ้ทใใฎใง๏ผไฝๅใไฝฟใๅ ดๅใฏ้ขๆฐๅฎ็พฉใใใฆใใใจใใใ
cor2(x, y) = cor(Matrix(dropmissing(DataFrame(x=x, y=y))))[1,2]
cov2(x, y) = cov(Matrix(dropmissing(DataFrame(x=x, y=y))))[1,2]
combine(airquality,
[:Ozone, :Temp] => ((x, y) -> cor(Matrix(dropmissing(DataFrame(x=x, y=y))))[1,2]),
[:Ozone, :Temp] => cor2,
[:Ozone, :Wind] => cor2,
[:Ozone, :Wind] => ((x, y) -> cov(Matrix(dropmissing(DataFrame(x=x, y=y))))[1,2]),
[:Ozone, :Wind] => cov2,
)
Row | Ozone_Temp_function | Ozone_Temp_cor2 | Ozone_Wind_cor2 | Ozone_Wind_function | Ozone_Wind_cov2 |
---|---|---|---|---|---|
Float64 | Float64 | Float64 | Float64 | Float64 | |
1 | 0.69836 | 0.69836 | -0.601547 | -70.9385 | -70.9385 |
corspearman(airquality2.Ozone, airquality2.Temp) |> println
corspearman(df.Ozone, df.Temp) |> println
0.7729319330689582 0.7740429554613014
็ธ้ขไฟๆฐ่กๅ๏ผๅๆฃใปๅ ฑๅๆฃ่กๅยถ
3 ๅไปฅไธใฎๅคๆฐใๅซใใใผใฟใซใใใฆ๏ผใในใฆใฎ2ๅคๆฐใฎ็ตใฟๅใใใซใใใ็ตฑ่จ้ใฏ๏ผ็ธ้ขไฟๆฐ่กๅ๏ผๅๆฃๅ ฑๅๆฃ่กๅใจใใฆๅพใใใใ
ๆฌ ๆๅคใๅซใพใชใๅ ดๅยถ
้ข้ฃใใๅคๆฐใในใฆใซๆฌ ๆๅคใใชใๅ ดๅใฏใใใใใฎ้ขๆฐใซ่กๅๅคๆใใใใผใฟใใฌใผใ ใไธใใใฐใใใ
cor(Matrix(airquality2)) |> display
4ร4 Matrix{Float64}: 1.0 0.348342 -0.612497 0.698541 0.348342 1.0 -0.127183 0.294088 -0.612497 -0.127183 1.0 -0.49719 0.698541 0.294088 -0.49719 1.0
corspearman(Matrix(airquality2)) |> display
4ร4 Matrix{Float64}: 1.0 0.348186 -0.605136 0.772932 0.348186 1.0 -0.0616964 0.209537 -0.605136 -0.0616964 1.0 -0.499323 0.772932 0.209537 -0.499323 1.0
corkendall(Matrix(airquality2)) |> display
4ร4 Matrix{Float64}: 1.0 0.240319 -0.440459 0.586147 0.240319 1.0 -0.0430135 0.142902 -0.440459 -0.0430135 1.0 -0.362387 0.586147 0.142902 -0.362387 1.0
cov(Matrix(airquality2)) |> display
4ร4 Matrix{Float64}: 1107.29 1056.58 -72.5112 221.521 1056.58 8308.74 -41.2448 255.468 -72.5112 -41.2448 12.6573 -16.8572 221.521 255.468 -16.8572 90.8203
ๆฌ ๆๅคใๅซใๅ ดๅยถ
ๅฏพๅฆๆณใฏ 2 ใคใใใ1 ใคใฏ๏ผdropmissing()
ใซใใฃใฆๆฌ ๆๅคใๅซใพใชใ๏ผใชในใใฏใคใบ้คๅป๏ผใใผใฟใใฌใผใ ใซใใฆ ใ2.2.1.ใๆฌ ๆๅคใๅซใพใชใๅ ดๅใ ใ้ฉ็จใใใ
ใใ 1 ใคใฏ๏ผใในใฆใฎ 2 ๅคๆฐใฎ็ตใฟๅใใใซใใใฆ๏ผ2 ๅคๆฐใฎๅ ดๅใซ็คบใใใใขใฏใคใบ้คๅปใซใใ็ตฑ่จ้ใ่จ็ฎใใใ
ใใฎใใใฎ้ขๆฐใไปฅไธใซ็คบใใฆใใใ
function multi(df, FUNC; samplesize=false)
n = ncol(df)
A = ones(n, n)
N = zeros(Int, n, n)
for i in 1:n
x = filter(!ismissing, df[:, i])
FUNC == cov && (A[i, i] = var(x))
N[i, i] = length(x)
end
for i in 1:n-1
for j in i+1:n
df2 = Matrix(dropmissing(df[:, [i, j]]))
A[j, i] = A[i, j] = FUNC(df2[:, 1], df2[:, 2])
N[j, i] = N[i, j] = size(df2, 1)
end
end
return (samplesize ? (A, N) : A)
end;
samplesize=false
ใๆๅฎใใใฐ๏ผ2ๅคๆฐใฎ็ตใฟๅใใใซใใใๆๅนใตใณใใซใตใคใบใฎ่กๅใ่ฟใใใใฎใจใใซใฏ๏ผๆปใๅคใ 2 ๅๅใๅใใฎใง๏ผๅทฆ่พบใซใฏ 2 ๅใฎๅคๆฐใๆๅฎใใชใใใฐใชใใชใใ1 ใค็ฎใฏ็ตฑ่จ้ใฎ่กๅ๏ผ2 ใค็ฎใใตใณใใซใตใคใบ่กๅใงใใใ
df = select(airquality, Not([:Month, :Day]))
A, N = multi(df, cor, samplesize=true)
A|> display
N|> display
4ร4 Matrix{Float64}: 1.0 0.348342 -0.601547 0.69836 0.348342 1.0 -0.0567917 0.27584 -0.601547 -0.0567917 1.0 -0.457988 0.69836 0.27584 -0.457988 1.0
4ร4 Matrix{Int64}: 116 111 116 116 111 146 146 146 116 146 153 153 116 146 153 153
multi(df, corspearman) |> display
4ร4 Matrix{Float64}: 1.0 0.348186 -0.590155 0.774043 0.348186 1.0 -0.000977333 0.207428 -0.590155 -0.000977333 1.0 -0.446541 0.774043 0.207428 -0.446541 1.0
multi(df, corkendall) |> display
4ร4 Matrix{Float64}: 1.0 0.240319 -0.42836 0.586299 0.240319 1.0 0.00067856 0.144234 -0.42836 0.00067856 1.0 -0.322242 0.586299 0.144234 -0.322242 1.0
multi(df, cov) |> display
4ร4 Matrix{Float64}: 1088.2 1056.58 -70.9385 218.521 1056.58 8110.52 -17.946 229.16 -70.9385 -17.946 12.4115 -15.2721 218.521 229.16 -15.2721 89.5913
ๅคๅค้็ตฑ่จยถ
ๅค้ใฏใญใน้่จ่กจยถ
3 ้๏ผ4 ้...ใฎใฏใญใน้่จใ๏ผ2.1. ใง็จใใ freqtable()
ใง่กใใ
REPL ใชใฉ๏ผ็ฐๅขใซใใฃใฆใฏ้่จ่กจใในใฆใ่กจ็คบใใใฎใซๅทฅๅคซใๅฟ ่ฆใชใใจใใใใ
x = freqtable(ESOPH.agegp, ESOPH.alcgp, ESOPH.tobgp)
for i in 1:size(x, 3)
println("\nESOPH.tobgp: ", names(x)[3][i])
display(x[:, :, i])
end
ESOPH.tobgp: 0-9g/day
6ร4 Named Matrix{Int64} Dim1 โฒ Dim2 โ 0-39g/day 40-79 80-119 120+ โโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ 25-34 โ 40 27 2 1 35-44 โ 60 35 11 3 45-54 โ 46 38 16 4 55-64 โ 49 40 18 10 65-74 โ 48 34 13 4 75+ โ 18 5 1 2
ESOPH.tobgp: 10-19
6ร4 Named Matrix{Int64} Dim1 โฒ Dim2 โ 0-39g/day 40-79 80-119 120+ โโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ 25-34 โ 10 7 1 1 35-44 โ 14 23 6 3 45-54 โ 18 21 14 4 55-64 โ 22 21 15 7 65-74 โ 14 10 12 2 75+ โ 6 3 1 1
ESOPH.tobgp: 20-29
6ร4 Named Matrix{Int64} Dim1 โฒ Dim2 โ 0-39g/day 40-79 80-119 120+ โโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ 25-34 โ 6 4 0 1 35-44 โ 7 14 2 4 45-54 โ 10 15 5 3 55-64 โ 12 17 6 3 65-74 โ 7 9 3 1 75+ โ 0 3 0 0
ESOPH.tobgp: 30+
6ร4 Named Matrix{Int64} Dim1 โฒ Dim2 โ 0-39g/day 40-79 80-119 120+ โโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ 25-34 โ 5 7 2 2 35-44 โ 8 8 1 0 45-54 โ 4 7 4 4 55-64 โ 6 6 4 6 65-74 โ 2 0 1 1 75+ โ 3 1 0 0