[R] Selecting unique values

Steven Kennedy stevenkennedy2263 at gmail.com
Tue Jul 26 06:31:13 CEST 2011


use unique()

df <- data.frame(Species_name=c(rep('Abies concolor',4),rep('Accipiter
cooperi',7)),
                  Longitude=c(-106.601, -106.493, -106.489, -106.496,
-119.688, -119.792,
-118.797,-77.38333,-77.38333,-75.99153,-75.99153),
                  Latitude=c(35.868, 35.9682, 35.892, 35.8542,
34.4339, 34.5069, 34.2581, 39.68333, 39.68333, 40.633335, 40.633335))
>
> unique(df)
        Species_name  Longitude Latitude
1     Abies concolor -106.60100 35.86800
2     Abies concolor -106.49300 35.96820
3     Abies concolor -106.48900 35.89200
4     Abies concolor -106.49600 35.85420
5  Accipiter cooperi -119.68800 34.43390
6  Accipiter cooperi -119.79200 34.50690
7  Accipiter cooperi -118.79700 34.25810
8  Accipiter cooperi  -77.38333 39.68333
10 Accipiter cooperi  -75.99153 40.63334
> dim(df)
[1] 11  3
> dim(unique(df))
[1] 9 3

On Tue, Jul 26, 2011 at 8:07 AM, Kumar Mainali <kpmainali at gmail.com> wrote:
> Greetings
>
> I have a dataset with occurrence records of multiple species. I need to get
> rid of multiple listings of the same occurrence point for a species (as you
> see below in red and blue typeface). How do I create a dataset only with
> unique set of longitude and latitude for each species? Thanks in advance.
>
> Species_name Longitude Latitude
> Abies concolor -106.601 35.868
> Abies concolor -106.493 35.9682
> Abies concolor -106.489 35.892
> Abies concolor -106.496 35.8542
> Accipiter cooperi -119.688 34.4339
> Accipiter cooperi -119.792 34.5069
> Accipiter cooperi -118.797 34.2581
> Accipiter cooperi -77.38333 39.68333
> Accipiter cooperi -77.38333 39.68333
> Accipiter cooperi -75.99153 40.633335
> Accipiter cooperi -75.99153 40.633335
>
> - Kumar
>
> --
> Section of Integrative Biology
> University of Texas at Austin
> Austin, Texas 78712, USA
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> 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.
>



More information about the R-help mailing list