[R] basic table statistics
Jim Lemon
jim at bitwrit.com.au
Sat Apr 24 14:20:57 CEST 2010
On 04/24/2010 05:48 AM, Maxim wrote:
> Hi,
>
>
> I have a very simple question, but I'm obviously not able to solve the
> problem on my own.
>
>
> I have a data.frame like
>
>
> sample(c("A","B","C"),size=20,replace = T)->type
>
> rnorm(20)->value
>
> data.frame(ty=type,val=value)->test
>
>
> There must be some built in functions, that will do some descriptive
> statistics with tabular output, in the end I like to have something like
>
>
> number of samples mean sd .............
>
> A 5
>
> B 9
>
> C 6
>
>
>
> So I need a function that counts the number of occurrences of factors in
> type and then does something like the *summary* function, but factor
> specific.
>
>
> I tried:
>
>
> vector()->Median
>
> vector()->SD
>
> vector()->Mean
>
>
> as.data.frame(table(type))->int
>
>
> for (count in c(1:(nrow(int))))
>
> {
>
> subset(test, ty==as.character(int$type[count])) -> subtest
>
> median(subtest$val)->Median[count]
>
> sd(subtest$val)->SD[count]
>
> mean(subtest$val)->Mean[count]
>
> }
>
>
> cbind(int,Median,SD,Mean)
>
>
> This works, but: isn't this much too complicated, I bet there is such
> functionality embedded in the base packages, but I cannot find it.
>
>
Hi Maxim,
Look at:
describe (psych)
describe (Hmisc)
describe (prettyR)
and you will probably find something useful.
Jim
More information about the R-help
mailing list