Dear Sarah, What you will need is a series of logical conditions. ?Logic or ?"|" should pull up the documentation on the logical operators available to use. Because this list does not accept HTML emails (see the posting guide), your data frame did not come through in any coherent form. Can you resend the data using the following procedure:
Suppose your data frame is named "dfrm" (but substitute its actual name). At the R console, type: dput(dfrm) this will output how R "sees" the data to the console, then copy and paste that whole jumble of text from R to your email and send it to us. This is one of the easiest way for us to read in small amounts of data, and it should be easy for you to provide too. Cheers, Josh On Mon, Jan 31, 2011 at 6:22 AM, sarah bauduin <sarahbaud...@hotmail.fr> wrote: > > My data frame looks like: > SightingID PA1 PA2 PlotID InOverlap Area1 2001 1 -99 392 > Y 0.22 2002 1 -99 388 Y 0.253 2008 > 1 NA 104 N 0.344 2010 1 NA 71 N > 0.185 2012 1 NA 61 N 0.166 2013 1 > NA 61 N 0.227 2014 1 NA 62 N > 0.258 2015 1 NA 63 N 0.199 2016 1 > NA 63 N 0.310 2017 1 NA 63 N > 0.2511 2018 1 NA 63 N 0.2612 2019 1 NA > 63 N 0.2613 2020 1 NA 64 N > 0.33 14 2021 1 NA 64 N 0.4215 2022 1 > NA 85 N 0.0816 2023 0 1 95 Y > 0.11 17 2024 1 NA 93 N 0.2318 2025 1 > NA 106 N 0.419 2026 1 NA 134 ! > N 0.28 > The only unique values in the data frame are the SightingID. I would like to > obtain a new data frame with unique PlotID values based on several > conditions:- return the row if there is only one SightingID for the PlotID- > if there is several SightingID for the same PlotID value: -select first > the SightingID for which PA1=0, if there is several SightingID with > PA1=0 for the same PlotID select the one with the highest value in Area, > if there is several SightingID with PA1=0 for the same PlotID with the > highest value for Area select one SightingID at random - select the > SightingID for which PA1 is not equal to 0 based on the highest value in Area > (and at random if there are several with the highest value in Area) > I have no idea how to do that, can someone help me please ? Sarah > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@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. > -- Joshua Wiley Ph.D. Student, Health Psychology University of California, Los Angeles http://www.joshuawiley.com/ ______________________________________________ R-help@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.