Re: [R] Proper Syntax for Logical Subset in Subset()

2011-11-02 Thread Rich Shepard

On Wed, 2 Nov 2011, Rich Shepard wrote:


 I want a subset of this with only 7 chemicals: Ca, Cl, Cond, Mg, Na, SO4,
and TDS.


  I should have also written that what I ultimately want is to create a
box-and-whisker plot for these 7 chemicals in a single panel. If that can be
done directly from the source data frame without creating another subset, I
want to learn the syntax for that.

Rich

__
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.


Re: [R] Proper Syntax for Logical Subset in Subset()

2011-11-02 Thread Seeliger . Curt
I have measured values for 47 chemicals in a stream. After processing
 the original data frame through reshape2, the recast data frame has this
 structure:
 
 'data.frame':   256 obs. of  47 variables:
   $ site : Factor w/ 143 levels BC-0.5,BC-1,..: 1 1 1 2 2 2 2 2 
2 2...
   $ sampdate : Date, format: 1996-04-19 1996-05-21 ...
   $ Acid : num  NA NA NA NA NA NA NA NA NA NA ...
...
 
I want a subset of this with only 7 chemicals: Ca, Cl, Cond, Mg, Na, 
SO4,
 and TDS. The subset help page tells me that I can use a logical subset 
to
 extract these 7 rows while keeping all columns, but I do not know how to
 write that logical subset. 

Wow, I don't see how you wound up with the code you tried based on the 
instructions.  I guess for some of us the best instruction is a bloody 
nose, myself often included.

It sounds like you want to get rid of some columns in the reshaped 
dataframe, not rows.

   new - old[c('site', 'Ca', 'Cl', 'Cond', 'Mg', 'Na', 'SO4', 'TDS')] 

will work, as will the following if you insist on using the subset 
function.

   new - subset(old, c(site, Ca, Cl, Cond, Mg, Na, SO4, TDS))

If you actually want to get rid of rows that aren't the minerals of 
interest, then work with your unreshaped dataframe:

   new - subset(reallyOld, parameter in c('Ca', 'Cl', 'Cond', 'Mg', 'Na', 
'SO4', 'TDS'))


-- 
Curt Seeliger, Data Ranger
Raytheon Information Services - Contractor to ORD
seeliger.c...@epa.gov
541/754-4638


[[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.


Re: [R] Proper Syntax for Logical Subset in Subset()

2011-11-02 Thread Bert Gunter
To make such a plot, I would have thought your want your data structure to
be:

yourdat:

Column A: Date
Column B; Chemical
Column C: Result


After subsetting this to the chemicals you want or doing the subsetting in
your plot command, something like (base R)

boxplot(Result ~ Chemical, subset=yourdat$Chemical %in% c(Ca,Cl,
Cond,Mg,Na,SO2,TDS))

You probably can get what you want one way or the other with your current
data structure -- though you may have to use ggplot or trellis -- but it
does appear to be inconvenient.

Whether I'm correct or not in my understanding of your situation, an
important message is: you should choose your data structure to facilitate
the analysis that you have in mind. IMHO, this is one of R's great
strengths: it provides rich facilities for manipulating data tightly
integrated with plotting and analytical capabilities.

Cheers,
Bert

On Wed, Nov 2, 2011 at 9:46 AM, Rich Shepard rshep...@appl-ecosys.comwrote:

 On Wed, 2 Nov 2011, Rich Shepard wrote:

   I want a subset of this with only 7 chemicals: Ca, Cl, Cond, Mg, Na, SO4,
 and TDS.


  I should have also written that what I ultimately want is to create a
 box-and-whisker plot for these 7 chemicals in a single panel. If that can
 be
 done directly from the source data frame without creating another subset, I
 want to learn the syntax for that.

 Rich

 __**
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/**listinfo/r-helphttps://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/**
 posting-guide.html http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.




-- 

Bert Gunter
Genentech Nonclinical Biostatistics

Internal Contact Info:
Phone: 467-7374
Website:
http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm

[[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.


Re: [R] Proper Syntax for Logical Subset in Subset()

2011-11-02 Thread Bert Gunter
Of course I left out the data argument:

boxplot(Result ~ Chemical, data= yourdat,subset=yourdat$Chemical %in%
c(Ca,Cl, Cond,Mg,Na,SO2,TDS))

-- Bert

On Wed, Nov 2, 2011 at 10:08 AM, Bert Gunter bgun...@gene.com wrote:

 To make such a plot, I would have thought your want your data structure to
 be:

 yourdat:

 Column A: Date
 Column B; Chemical
 Column C: Result
 

 After subsetting this to the chemicals you want or doing the subsetting in
 your plot command, something like (base R)

 boxplot(Result ~ Chemical, subset=yourdat$Chemical %in% c(Ca,Cl,
 Cond,Mg,Na,SO2,TDS))

 You probably can get what you want one way or the other with your current
 data structure -- though you may have to use ggplot or trellis -- but it
 does appear to be inconvenient.

 Whether I'm correct or not in my understanding of your situation, an
 important message is: you should choose your data structure to facilitate
 the analysis that you have in mind. IMHO, this is one of R's great
 strengths: it provides rich facilities for manipulating data tightly
 integrated with plotting and analytical capabilities.

 Cheers,
 Bert

 On Wed, Nov 2, 2011 at 9:46 AM, Rich Shepard rshep...@appl-ecosys.comwrote:

 On Wed, 2 Nov 2011, Rich Shepard wrote:

   I want a subset of this with only 7 chemicals: Ca, Cl, Cond, Mg, Na,
 SO4,
 and TDS.


  I should have also written that what I ultimately want is to create a
 box-and-whisker plot for these 7 chemicals in a single panel. If that can
 be
 done directly from the source data frame without creating another subset,
 I
 want to learn the syntax for that.

 Rich

 __**
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/**listinfo/r-helphttps://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/**
 posting-guide.html http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.




 --

 Bert Gunter
 Genentech Nonclinical Biostatistics

 Internal Contact Info:
 Phone: 467-7374
 Website:

 http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm





-- 

Bert Gunter
Genentech Nonclinical Biostatistics

Internal Contact Info:
Phone: 467-7374
Website:
http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm

[[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.


Re: [R] Proper Syntax for Logical Subset in Subset()

2011-11-02 Thread Rich Shepard

On Wed, 2 Nov 2011, Bert Gunter wrote:


To make such a plot, I would have thought your want your data structure to
be:



Column A: Date
Column B; Chemical
Column C: Result


  Thanks, Bert. I have a data frame in that format.


After subsetting this to the chemicals you want or doing the subsetting in
your plot command, something like (base R)

boxplot(Result ~ Chemical, subset=yourdat$Chemical %in% c(Ca,Cl,
Cond,Mg,Na,SO2,TDS))


  Great! I'll work with this. I tend to use lattice so I can learn its
capabilities better.


Whether I'm correct or not in my understanding of your situation, an
important message is: you should choose your data structure to facilitate
the analysis that you have in mind. IMHO, this is one of R's great
strengths: it provides rich facilities for manipulating data tightly
integrated with plotting and analytical capabilities.


  I recognize this and continue to learn how best to represent the same data
for different analyses and plots.

Much appreciated,

Rich

__
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.