[R] tabulation on dataframe question
Henrique Dallazuanna
wwwhsd at gmail.com
Mon Feb 18 16:58:03 CET 2008
Try this:
with(x,
{tmp <- table(x[Dist==0.2,c('GrpA', 'GrpB')])
tmp[lower.tri(tmp)] <- tmp[upper.tri(tmp)]
tmp})
On 18/02/2008, Karin Lagesen <karin.lagesen at medisin.uio.no> wrote:
>
> I have a data frame with data similar to this:
>
> NameA GrpA NameB GrpB Dist
> A Alpha B Alpha 0.2
> A Alpha C Beta 0.2
> A Alpha D Beta 0.4
> B Alpha C Beta 0.2
> B Alpha D Beta 0.1
> C Beta D Beta 0.3
>
> Dist is a distance measure between two entities. The table displays
> all to all distances, but the distance between two entities only
> appears once. What I would like to get is a table where I get a count
> of entities per group where the distance satisfies a certain condition
> ( equal to zero for instance).
>
> In this case, if the requirement was Distances == 0.2
>
> Alpha Beta
> Alpha 1 2
> Beta 2 0
>
> This resulting table would be symmetrical.
>
> I hope I am able to convey what I would like, and TIA for your help!
>
> Karin
> --
> Karin Lagesen, PhD student
> karin.lagesen at medisin.uio.no
> http://folk.uio.no/karinlag
>
> ______________________________________________
> R-help at r-project.org 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.
>
--
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O
More information about the R-help
mailing list