Thanks to David's help I subset my large data set and produced a smaller
one for a single stream and 7 factors of interest. The structure of this
data frame is:
str(burns.tds.anal)
'data.frame': 718 obs. of 4 variables:
$ site : Factor w/ 143 levels "BC-0.5","BC-1",..: 1 1 4 6 4 4 4 5 5 5
$ sampdate: Date, format: "1996-06-02" "1996-06-02" ...
$ param : Factor w/ 7 levels "Ca","Cl","Cond",..: 6 7 3 6 3 3 3 3 3 3
$ quant : num 194 530 826 36 848 ...
and a summary of it shows:
summary(burns.tds.anal)
site sampdate param quant
BC-3 :460 Min. :1992-03-27 Ca : 65 Min. : 1.00
BC-2 :107 1st Qu.:1994-09-21 Cl :148 1st Qu.: 14.03
BC-1 : 62 Median :1996-05-21 Cond: 94 Median : 64.40
BC-4 : 38 Mean :1998-11-19 Mg : 65 Mean : 189.47
BC-1.5 : 28 3rd Qu.:2002-10-31 Na : 34 3rd Qu.: 285.75
BC-0.5 : 12 Max. :2011-05-18 SO4 :155 Max. :2058.00
(Other): 11 TDS :157 NA's : 8.00
a sample of the data in burns.tds.anal is:
burns.tds.anal
site sampdate param quant
82 BC-0.5 1996-06-02 SO4 194.00
83 BC-0.5 1996-06-02 TDS 530.00
6903 BC-2 1994-07-25 Cond 826.00
6905 BC-4 1996-08-23 SO4 36.00
6977 BC-2 1994-10-19 Cond 848.00
6980 BC-2 1995-03-16 Cond 1795.00
6983 BC-2 1995-06-21 Cond 640.00
7833 BC-3 1994-01-20 Cond 406.00
7838 BC-3 1994-02-17 Cond 401.00
7847 BC-3 1994-03-24 Cond 441.00
7854 BC-3 1994-06-13 Cond 400.00
7866 BC-3 1994-07-25 Cond 393.00
7871 BC-3 1994-08-18 Cond 420.00
7877 BC-3 1994-10-20 Cond 438.00
Perhaps because it's Monday I'm not successfully writing the xyplot()
command to show the quant, for example, for TDS by site. What I need to do
is plot the quant values for TDS vs. Cond, TDS vs. SO4, etc.
Have I incorrectly subset the data? I know that I've missed something but
cannot determine what it is.
Rich
Syntax Help for xyplot()
12 messages · Bert Gunter, Dennis Murphy, Daniel Nordlund +2 more
On Mon, 24 Oct 2011, Rich Shepard wrote:
Perhaps because it's Monday I'm not successfully writing the xyplot() command to show the quant, for example, for TDS by site. What I need to do is plot the quant values for TDS vs. Cond, TDS vs. SO4, etc.
I should have provided some of the attempts:
xyplot(quant ~ TDS | site, data = burns.tds.anal)
Error in eval(expr, envir, enclos) : object 'TDS' not found
xyplot(quant ~ 'TDS' | site, data = burns.tds.anal)
Warning messages:
1: In order(as.numeric(x)) : NAs introduced by coercion
2: In diff(as.numeric(x[ord])) : NAs introduced by coercion
3: In function (x, y, type = "p", groups = NULL, pch = if (is.null(groups))
plot.symbol$pch else superpose.symbol$pch, :
NAs introduced by coercion
This produces a plot with no data in each panel.
And I cannot see how to specify, for example, 'TDS' x 'Cond' because
xyplot('TDS'$quant ~ 'Cond'$quant | site, data = burns.tds.anal)
Error in "TDS"$quant : $ operator is invalid for atomic vectors
and
xyplot('TDS'[quant] ~ 'Cond'[quant] | site, data = burns.tds.anal)
There were 25 warnings (use warnings() to see them)
produces the panels without data in them.
Rich
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20111024/75fa9abe/attachment.pl>
Hi:
You should perhaps do the following in the xyplot() call (untested
because the TDS and Cond data frames are missing):
xyplot('TDS'$quant ~ 'Cond'$quant | burns.tds.anal$site )
assuming that all three atomic objects have the same length. Caveat emptor.
Dennis
On Mon, Oct 24, 2011 at 2:17 PM, Rich Shepard <rshepard at appl-ecosys.com> wrote:
On Mon, 24 Oct 2011, Rich Shepard wrote:
?Perhaps because it's Monday I'm not successfully writing the xyplot() command to show the quant, for example, for TDS by site. What I need to do is plot the quant values for TDS vs. Cond, TDS vs. SO4, etc.
?I should have provided some of the attempts:
xyplot(quant ~ TDS | site, data = burns.tds.anal)
Error in eval(expr, envir, enclos) : object 'TDS' not found
xyplot(quant ~ 'TDS' | site, data = burns.tds.anal)
Warning messages:
1: In order(as.numeric(x)) : NAs introduced by coercion
2: In diff(as.numeric(x[ord])) : NAs introduced by coercion
3: In function (x, y, type = "p", groups = NULL, pch = if (is.null(groups))
plot.symbol$pch else superpose.symbol$pch, ?:
?NAs introduced by coercion
This produces a plot with no data in each panel.
And I cannot see how to specify, for example, 'TDS' x 'Cond' because
xyplot('TDS'$quant ~ 'Cond'$quant | site, data = burns.tds.anal)
Error in "TDS"$quant : $ operator is invalid for atomic vectors
and
xyplot('TDS'[quant] ~ 'Cond'[quant] | site, data = burns.tds.anal)
There were 25 warnings (use warnings() to see them)
produces the panels without data in them.
Rich
______________________________________________ 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.
On Mon, 24 Oct 2011, Bert Gunter wrote:
Where's TDS? -- 'cause it's sure not in your data frame.
Bert,
summary(burns.tds.anal)
site sampdate param quant
BC-3 :460 Min. :1992-03-27 Ca : 65 Min. : 1.00
BC-2 :107 1st Qu.:1994-09-21 Cl :148 1st Qu.: 14.03
BC-1 : 62 Median :1996-05-21 Cond: 94 Median : 64.40
BC-4 : 38 Mean :1998-11-19 Mg : 65 Mean : 189.47
BC-1.5 : 28 3rd Qu.:2002-10-31 Na : 34 3rd Qu.: 285.75
BC-0.5 : 12 Max. :2011-05-18 SO4 :155 Max. :2058.00
(Other): 11 TDS :157 NA's : 8.00
Bottom row of the 'param' column.
Rich
On Mon, 24 Oct 2011, Dennis Murphy wrote:
xyplot('TDS'$quant ~ 'Cond'$quant | burns.tds.anal$site )
Dennis,
xyplot('TDS'$quant ~ 'Cond'$quant | burns.tds.anal$site)
Error in "TDS"$quant : $ operator is invalid for atomic vectors
I tried that earlier today.
Rich
Why not format the data like this: site sampledate SO4 TDS NA Mg Cond Cl Ca i.e. with a column for each parameter? It seems to me that you summary doesn't make any sense. Those quantiles are meaningless as they encompass all the parameters. Am I missing something?
Rich Shepard wrote:
Thanks to David's help I subset my large data set and produced a smaller
one for a single stream and 7 factors of interest. The structure of this
data frame is:
str(burns.tds.anal)
'data.frame': 718 obs. of 4 variables:
$ site : Factor w/ 143 levels "BC-0.5","BC-1",..: 1 1 4 6 4 4 4 5 5 5
$ sampdate: Date, format: "1996-06-02" "1996-06-02" ...
$ param : Factor w/ 7 levels "Ca","Cl","Cond",..: 6 7 3 6 3 3 3 3 3 3
$ quant : num 194 530 826 36 848 ...
and a summary of it shows:
summary(burns.tds.anal)
site sampdate param quant
BC-3 :460 Min. :1992-03-27 Ca : 65 Min. : 1.00
BC-2 :107 1st Qu.:1994-09-21 Cl :148 1st Qu.: 14.03
BC-1 : 62 Median :1996-05-21 Cond: 94 Median : 64.40
BC-4 : 38 Mean :1998-11-19 Mg : 65 Mean : 189.47
BC-1.5 : 28 3rd Qu.:2002-10-31 Na : 34 3rd Qu.: 285.75
BC-0.5 : 12 Max. :2011-05-18 SO4 :155 Max. :2058.00
(Other): 11 TDS :157 NA's : 8.00
a sample of the data in burns.tds.anal is:
burns.tds.anal
site sampdate param quant
82 BC-0.5 1996-06-02 SO4 194.00
83 BC-0.5 1996-06-02 TDS 530.00
6903 BC-2 1994-07-25 Cond 826.00
6905 BC-4 1996-08-23 SO4 36.00
6977 BC-2 1994-10-19 Cond 848.00
6980 BC-2 1995-03-16 Cond 1795.00
6983 BC-2 1995-06-21 Cond 640.00
7833 BC-3 1994-01-20 Cond 406.00
7838 BC-3 1994-02-17 Cond 401.00
7847 BC-3 1994-03-24 Cond 441.00
7854 BC-3 1994-06-13 Cond 400.00
7866 BC-3 1994-07-25 Cond 393.00
7871 BC-3 1994-08-18 Cond 420.00
7877 BC-3 1994-10-20 Cond 438.00
Perhaps because it's Monday I'm not successfully writing the xyplot()
command to show the quant, for example, for TDS by site. What I need to do
is plot the quant values for TDS vs. Cond, TDS vs. SO4, etc.
Have I incorrectly subset the data? I know that I've missed something
but
cannot determine what it is.
Rich
______________________________________________ R-help@ 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/Syntax-Help-for-xyplot-tp3934533p3934721.html Sent from the R help mailing list archive at Nabble.com.
-----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of Rich Shepard Sent: Monday, October 24, 2011 2:17 PM To: r-help at r-project.org Subject: Re: [R] Syntax Help for xyplot() On Mon, 24 Oct 2011, Rich Shepard wrote:
Perhaps because it's Monday I'm not successfully writing the xyplot() command to show the quant, for example, for TDS by site. What I need to
do
is plot the quant values for TDS vs. Cond, TDS vs. SO4, etc.
I should have provided some of the attempts:
xyplot(quant ~ TDS | site, data = burns.tds.anal)
Error in eval(expr, envir, enclos) : object 'TDS' not found
xyplot(quant ~ 'TDS' | site, data = burns.tds.anal)
Warning messages:
1: In order(as.numeric(x)) : NAs introduced by coercion
2: In diff(as.numeric(x[ord])) : NAs introduced by coercion
3: In function (x, y, type = "p", groups = NULL, pch = if
(is.null(groups))
plot.symbol$pch else superpose.symbol$pch, :
NAs introduced by coercion
This produces a plot with no data in each panel.
And I cannot see how to specify, for example, 'TDS' x 'Cond' because
xyplot('TDS'$quant ~ 'Cond'$quant | site, data = burns.tds.anal)
Error in "TDS"$quant : $ operator is invalid for atomic vectors
and
xyplot('TDS'[quant] ~ 'Cond'[quant] | site, data = burns.tds.anal)
There were 25 warnings (use warnings() to see them)
produces the panels without data in them.
Rich
Rich, you need to reorganize your data so that you have a single record (i.e. row) for each site/sampdate combination with the quant value for each of your params save in a column named by the param value (I don't remember all the param names so I used pn). For example your first two lines should be collapsed into a single line, e.g. site sampdate TDS Cond SO4 p4 p5 p6 p7 BC-0.5 1996-06-02 530 NA 194 NA NA NA NA if you have other lines for site/sampdate BC-0.5 / 1996-06-02 then you would use the quant values to fill in for Cond and the other paramenters. Then your xyplot code should work. Someone else will need to show you how to do that manipulation. Dan Daniel Nordlund Bothell, WA USA
On Mon, 24 Oct 2011, Daniel Nordlund wrote:
you need to reorganize your data so that you have a single record (i.e. row) for each site/sampdate combination with the quant value for each of your params save in a column named by the param value (I don't remember all the param names so I used pn). For example your first two lines should be collapsed into a single line, e.g. site sampdate TDS Cond SO4 p4 p5 p6 p7 BC-0.5 1996-06-02 530 NA 194 NA NA NA NA
Daniel, Thank you. I thought that the data frame was not in the proper format. I'm re-reading Phil Spctor's "Data Manipulation with R" and not seeing how to reformat my base data frame to yield a data frame as defined above. Learning how to do this reformating is my highest priority because the books I have (and have read) tell me how to plot and do analyses but they all assume data in the proper format. Mine isn't. I'm sure a combination of subset() and select() will do the trick, but I'm too new to R to have sufficient experience to get it right the first time. Much appreciated, Rich
On Mon, 24 Oct 2011, B77S wrote:
Why not format the data like this: site sampledate SO4 TDS NA Mg Cond Cl Ca
Because I don't know how to reformat the base data frame (chemdata) to achieve this.
It seems to me that you summary doesn't make any sense. Those quantiles are meaningless as they encompass all the parameters. Am I missing something?
One site/sampdate/param has one value associated with it.
82 BC-0.5 1996-06-02 SO4 194.00 83 BC-0.5 1996-06-02 TDS 530.00 6903 BC-2 1994-07-25 Cond 826.00 6905 BC-4 1996-08-23 SO4 36.00 6977 BC-2 1994-10-19 Cond 848.00 6980 BC-2 1995-03-16 Cond 1795.00 6983 BC-2 1995-06-21 Cond 640.00 7833 BC-3 1994-01-20 Cond 406.00 7838 BC-3 1994-02-17 Cond 401.00 7847 BC-3 1994-03-24 Cond 441.00 7854 BC-3 1994-06-13 Cond 400.00 7866 BC-3 1994-07-25 Cond 393.00 7871 BC-3 1994-08-18 Cond 420.00 7877 BC-3 1994-10-20 Cond 438.00
I acknowledge that if the chemicals ('param') were in a vector, their associated
concentrations ('quant') in another vector following it, and both associated
with a site and sampdate life would be much better.
Thanks,
Rich
The following might not be exactly the way to do this, but see the package
"reshape" and the line of code following your data:
df <- structure(list(site = structure(c(1L, 1L, 2L, 4L, 2L, 2L, 2L,
3L, 3L, 3L, 3L, 3L, 3L, 3L), .Label = c("BC-0.5", "BC-2", "BC-3",
"BC-4"), class = "factor"), sampdate = structure(c(11L, 11L,
5L, 12L, 7L, 9L, 10L, 1L, 2L, 3L, 4L, 5L, 6L, 8L), .Label = c("1994-01-20",
"1994-02-17", "1994-03-24", "1994-06-13", "1994-07-25", "1994-08-18",
"1994-10-19", "1994-10-20", "1995-03-16", "1995-06-21", "1996-06-02",
"1996-08-23"), class = "factor"), param = structure(c(2L, 3L,
1L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = c("Cond",
"SO4", "TDS"), class = "factor"), quant = c(194, 530, 826, 36,
848, 1795, 640, 406, 401, 441, 400, 393, 420, 438)), .Names = c("site",
"sampdate", "param", "quant"), class = "data.frame", row.names = c("82",
"83", "6903", "6905", "6977", "6980", "6983", "7833", "7838",
"7847", "7854", "7866", "7871", "7877"))
library(reshape)
cast(melt(df), site + sampdate ~ param )
Using site, sampdate, param as id variables
site sampdate Cond SO4 TDS
1 BC-0.5 1996-06-02 NA 194 530
2 BC-2 1994-07-25 826 NA NA
3 BC-2 1994-10-19 848 NA NA
4 BC-2 1995-03-16 1795 NA NA
5 BC-2 1995-06-21 640 NA NA
6 BC-3 1994-01-20 406 NA NA
7 BC-3 1994-02-17 401 NA NA
8 BC-3 1994-03-24 441 NA NA
9 BC-3 1994-06-13 400 NA NA
10 BC-3 1994-07-25 393 NA NA
11 BC-3 1994-08-18 420 NA NA
12 BC-3 1994-10-20 438 NA NA
13 BC-4 1996-08-23 NA 36 NA
Rich Shepard wrote:
On Mon, 24 Oct 2011, B77S wrote:
Why not format the data like this: site sampledate SO4 TDS NA Mg Cond Cl Ca
Because I don't know how to reformat the base data frame (chemdata) to achieve this.
It seems to me that you summary doesn't make any sense. Those quantiles are meaningless as they encompass all the parameters. Am I missing something?
One site/sampdate/param has one value associated with it.
82 BC-0.5 1996-06-02 SO4 194.00 83 BC-0.5 1996-06-02 TDS 530.00 6903 BC-2 1994-07-25 Cond 826.00 6905 BC-4 1996-08-23 SO4 36.00 6977 BC-2 1994-10-19 Cond 848.00 6980 BC-2 1995-03-16 Cond 1795.00 6983 BC-2 1995-06-21 Cond 640.00 7833 BC-3 1994-01-20 Cond 406.00 7838 BC-3 1994-02-17 Cond 401.00 7847 BC-3 1994-03-24 Cond 441.00 7854 BC-3 1994-06-13 Cond 400.00 7866 BC-3 1994-07-25 Cond 393.00 7871 BC-3 1994-08-18 Cond 420.00 7877 BC-3 1994-10-20 Cond 438.00
I acknowledge that if the chemicals ('param') were in a vector, their
associated
concentrations ('quant') in another vector following it, and both
associated
with a site and sampdate life would be much better.
Thanks,
Rich
______________________________________________ R-help@ 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/Syntax-Help-for-xyplot-tp3934533p3934857.html Sent from the R help mailing list archive at Nabble.com.
On Mon, 24 Oct 2011, B77S wrote:
The following might not be exactly the way to do this, but see the package "reshape" and the line of code following your data:
Thank you, B77S. Bert pointed me to reshape and reshape2. I'll read the help pages for them before responding. I'll be out of the office all tomorrow morning so it will be after lunch (PST) that I get back to this.
df <- structure(list(site = structure(c(1L, 1L, 2L, 4L, 2L, 2L, 2L,
3L, 3L, 3L, 3L, 3L, 3L, 3L), .Label = c("BC-0.5", "BC-2", "BC-3",
"BC-4"), class = "factor"), sampdate = structure(c(11L, 11L,
5L, 12L, 7L, 9L, 10L, 1L, 2L, 3L, 4L, 5L, 6L, 8L), .Label = c("1994-01-20",
"1994-02-17", "1994-03-24", "1994-06-13", "1994-07-25", "1994-08-18",
"1994-10-19", "1994-10-20", "1995-03-16", "1995-06-21", "1996-06-02",
"1996-08-23"), class = "factor"), param = structure(c(2L, 3L,
1L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = c("Cond",
"SO4", "TDS"), class = "factor"), quant = c(194, 530, 826, 36,
848, 1795, 640, 406, 401, 441, 400, 393, 420, 438)), .Names = c("site",
"sampdate", "param", "quant"), class = "data.frame", row.names = c("82",
"83", "6903", "6905", "6977", "6980", "6983", "7833", "7838",
"7847", "7854", "7866", "7871", "7877"))
The sample helps. My base data frame has 47045 rows, 148 sites, 66 parameters, and 1056 distinct sample dates. I'm going to study reshape/reshape2 thoroughly as I don't want to enter all those data by hand. :-) Regards, Rich