[R] "tapply" and "data.frame"?

jim holtman jholtman at gmail.com
Tue Jan 23 15:05:38 CET 2007


Is this what you want:

> tst
   p1   p10  p100 p1000 p1001 p1002 p1003 p1004 p1005 p1006
    1     5     1     8     6     5     8     7     4     4
> data.frame(point=names(tst), ind=tst)
      point ind
p1       p1   1
p10     p10   5
p100   p100   1
p1000 p1000   8
p1001 p1001   6
p1002 p1002   5
p1003 p1003   8
p1004 p1004   7
p1005 p1005   4
p1006 p1006   4
>


On 1/23/07, Zhang Jian <jzhang1982 at gmail.com> wrote:
> I want to transform the data by "tapply" to one dataframe. But I can not get
> it.
> For example:
> > tst=tapply(point,pp,length)
> > tst[1:10]
>  p1   p10 p100 p1000 p1001 p1002 p1003 p1004 p1005 p1006
>  1   5   1   8   6   5   8   7   4   4
> > res=as.data.frame(tst)  # I try to transform it
> > res[1:10,]
>  p1   p10 p100 p1000 p1001 p1002 p1003 p1004 p1005 p1006
>  1   5   1   8   6   5   8   7   4   4
> How to transfrom it like the following:
> >res
> point ind
> 1   p1   1
> 2   p10   5
> 3 p100   1
> 4 p1000   8
> 5 p1001   6
>
> Thanks!
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>


-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem you are trying to solve?



More information about the R-help mailing list