I'm using the bystat function from the Hmisc package in R. How can I extract attribute values and place them into variables. For example, I want to calculate mean and SD for variable aaf and put them in a dataframe or matrix.
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"
The way I'm doing it is by first converting "t" into a dataframe, which I do not think is very efficient. Thanks for your suggestions.