0
我在R中使用Hmisc包中的bystat函數。如何提取屬性值並將它們放入變量中。例如,我想計算變量aaf的平均值和標準差,並將它們放在數據框或矩陣中。R問題 - 如何從bystat對象中提取屬性值並將它們放入變量中
t <- with(d.aaf,bystats(y=aaf,plot_bid,fun=function(x) {
c(Mean = round(mean(x),digits=2),SD = round(sd(x),digits=2))
}))
> str(t)
bystats [1:121, 1:3] 5 5 5 5 5 4 5 5 3 4 ...
- attr(*, "dimnames")=List of 2
..$ : chr [1:121] "P00000000006001288020278" "P00000000006001288085814"
"P00000000006001288151350" "P00000000006001288216886" ...
..$ : chr [1:3] "N" "Mean" "SD"
- attr(*, "heading")= chr "function(x) { c(Mean = round(mean(x),digits=2),
SD = round(sd(x),digits=2)) }
of aaf by plot_bid"
- attr(*, "byvarnames")= chr "plot_bid"
我這樣做的方式是先將「t」轉換爲數據幀,我認爲這不是很有效。 感謝您的建議。
非常好,我不知道這個軟件包。非常感謝你。 – Fernando 2010-10-25 20:24:54