Re: [R] selecting only specific rows in R

From: Charles C. Berry <cberry_at_tajo.ucsd.edu>
Date: Sat, 05 Jun 2010 10:10:27 -0700

On Sat, 5 Jun 2010, stephen sefick wrote:

> Reproducible dummy example, as to the posting guide. look at unique-
> you want to subset the data frame on all of the non-unique entries in
> the species column...
>
> x[x!=unique(x[,"species"]),]
>
> Something like that, maybe. If I had some data then I could probably
> figure it out. Use dput() or fake data to make a cut and paste-able
> example.
> HTH,
>
> Stephen

Or use one of the built in datasets - there are several that pertain to trees. Try

         ??tree

But yes, Adrienne, you should (as per Posting Guide) "provide commented, minimal, self-contained, reproducible code".

For example:

> ?Orange # find out about 'Orange' tree dataset
> ## rows with more than one tree of a given circumference:
> subset( Orange, xtabs(~circumference)[ as.character(circumference) ] > 1
)

    Tree age circumference

1     1  118            30
4     1 1004           115
6     1 1372           142
13    2 1372           203
14    2 1582           203
15    3  118            30
19    3 1231           115
29    5  118            30
33    5 1231           142

>

> # more detail to suggest why this works:
> with( Orange, xtabs(~circumference)[as.character(circumference)] > 1 )
[output deleted]

Chuck

>
> On Sat, Jun 5, 2010 at 10:00 AM, Adrienne Keller
> <adrienne.keller_at_umontana.edu> wrote:
>> Hi, I have a data frame with columns as follows: tree species (independent
>> variable) and several dependent variables (e.g. carbon, nitrogen,
>> phosphorus). Each row represents one tree sample. Some tree samples are
>> unique species in the data frame while other species were replicated (i.e.
>> rows 1,2,3 may be identical for the "tree species" column but have different
>> values for the other dependent variable columns). I want to create a new
>> data frame that selects only the tree species that have replicates. In other
>> words, I want to select all rows that have at least one replicate in the
>> column "tree species".
>>
>> Ideas on how to write such a function?
>>
>> Thanks,
>>
>> Adrienne Keller
>>
>> ______________________________________________
>> 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.
>>
>
>
>
> --
> Stephen Sefick
> ____________________________________
> | Auburn University |
> | Department of Biological Sciences |
> | 331 Funchess Hall |
> | Auburn, Alabama |
> | 36849 |
> |___________________________________|
> | sas0025_at_auburn.edu |
> | http://www.auburn.edu/~sas0025 |
> |___________________________________|
>
> Let's not spend our time and resources thinking about things that are
> so little or so large that all they really do for us is puff us up and
> make us feel like gods. We are mammals, and have not exhausted the
> annoying little problems of being mammals.
>
> -K. Mullis
>
> ______________________________________________
> 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.
>

Charles C. Berry                            (858) 534-2098
                                             Dept of Family/Preventive Medicine
E mailto:cberry_at_tajo.ucsd.edu	            UC San Diego
http://famprevmed.ucsd.edu/faculty/cberry/ La Jolla, San Diego 92093-0901

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. Received on Sat 05 Jun 2010 - 17:12:38 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sat 05 Jun 2010 - 18:10:29 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive