[R] Subset a data frame for plotting

David Winsemius dwinsemius at comcast.net
Fri Apr 10 04:19:27 CEST 2009


Jim's points are well taken. I wonder if you might get greater  
efficiency by examining the opportunities in the lattice or ggplot2  
packages that allow specification of grouping variables. It might get  
tedious creating all those micro-data.frames and might not really be  
necessary.
 From the first example on the xyplots help page:

library(lattice)
Depth <- equal.count(quakes$depth, number=8, overlap=.1) # Depth is  
used for grouping
xyplot(lat ~ long | Depth, data = quakes)
update(trellis.last.object(),
        strip = strip.custom(strip.names = TRUE, strip.levels = TRUE),
        par.strip.text = list(cex = 0.75),
        aspect = "iso")

-- 
David Winsemius
On Apr 9, 2009, at 9:32 PM, jim holtman wrote:

> I am not sure what you are trying to assign a value to '200706183<-';
> does not look like a valid object name.  This should work:
>
> x200706183<-subset(AllData, ID == 200706183)
>
> Notice the use of the '==' for the logical compare.
>
> On Thu, Apr 9, 2009 at 8:58 PM, Paul Warren Simonin
> <Paul.Simonin at uvm.edu> wrote:
>> Hello,
>>
>>  I have a question regarding how to subset/select parts of a data  
>> frame
>> (matrix) in order to plot data associated only with this subset.
>> Specifically I have a large data frame in which one column contains  
>> ID
>> values (dates), and other columns contain data I would like to plot
>> (temperature, light, etc.). I would like to break up this large  
>> matrix so as
>> to plot data associated with specific ID values (dates) separately.  
>> I have
>> learned of several commands that supposedly subset matrices in this  
>> manner
>> and have tried the following code with no success:
>>
>> 200706183<-subset(AllData, ID = 200706183)
>> 200706183<-gx.subset(AllData, ID == 200706183)
>> 200706183<-subset(x=AllData, AllData$ID = 200706183)
>> 200706183<-gx.subset(x=AllData, AllData$ID == 200706183)
>>
>> In using this code my plan was to create smaller data frame objects  
>> which I
>> could then plot. My first question, though, is whether this is the  
>> correct
>> approach. Is there a more efficient way I can create plots  
>> conditional on
>> certain criteria such as "code = 200706183" ?
>>  If I do need to first create separate smaller data frames, how do  
>> I go
>> about doing this? Am I missing something in the above commands?
>>  Any other advice is certainly welcome too, as I admit to being a  
>> bit new to
>> R. Thank you very much for any answers, tips, suggestions, etc.!
>>
>> Best wishes,
>> Paul Simonin
>>
>> --
>> Paul W. Simonin
>> Graduate Research Assistant, MS Program
>> Vermont Cooperative Fish and Wildlife Research Unit
>> The Rubenstein School of Environment and Natural Resources
>> University of Vermont
>> 81 Carrigan Dr.
>> Burlington, VT 05405
>> Ph:802-656-3153
>>
>> ______________________________________________
>> 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.
>>
>
>
>
> -- 
> Jim Holtman
> Cincinnati, OH
> +1 513 646 9390
>
> What is the problem that you are trying to solve?
>
> ______________________________________________
> 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.

David Winsemius, MD
Heritage Laboratories
West Hartford, CT




More information about the R-help mailing list