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]]
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. >
Steven's solution is great, but it will only work if the rows are really duplicates. If the data frame contains another variable whose values vary, it will not work because then the rows are obviously unique. df<-data.frame(df,value=rnorm(11)) unique(df) You would then have to make a decision, which row to select for each species at the same longitude and latitude, e.g., by first index number or min/max "value," etc. This would become slightly more complicated. Let us know if Steven's solution is what you were looking for. Kumar Mainali 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. >-- View this message in context: http://r.789695.n4.nabble.com/Selecting-unique-values-tp3694856p3695083.html Sent from the R help mailing list archive at Nabble.com.