Re: [R] package mgcv - predict with bam: Error in X[ind, ] : subscript out of bounds

2014-02-03 Thread Katharina May
Hi Simon,

many thanks for looking into this and making me understand the problem!
I'll adjust my factor levels right away...

Best, Katharina

On 3 February 2014 12:42, Simon Wood s.w...@bath.ac.uk wrote:
 Hi Katharina,

 Thanks for sending this.

 The problem is that the prediction data for site contain levels not
 available in the (useable non-NA) fit data...

 levels(m$model$site)
 [1] KRB NP.FOR  WKS.FRE WKS.KRE WKS.RIE WKS.WUE
 levels(gapData$site)
 [1] KRB NP.FOR  RIE.2   WKS.BBR WKS.FRE WKS.HOE WKS.KRE
 [8] WKS.RIE WKS.WUE

 predict.lm has a check for this, and so fails with a rather more informative
 error message. e.g.

 m0 - lm(sensor1 ~ sensor2 + site + site:NthSampling,
 data=xylemRohWeekXnn2011,na.action=na.omit)
 predict(m0,gapData)
 ... factor site has new levels RIE.2, WKS.BBR

 I'll add a better check to predict.gam.

 best,
 Simon

 ps. if you want predictions with the random effects for site set to zero
 then one trick is to use terms like s(site,bs=re,by=dum) in fitting with
 dum set to 1. Then in prediction you can set 'site' to any existing level,
 and dum to zero, in order to get a prediction for the missing level, with
 the 'site' effect set to zero.



 On 02/02/14 17:52, Katharina May wrote:

 Hi Simon,

 thank you for your reply, I really appreciate any help to understand
 the problem here...
 Unluckily the package upgrade didn't help with this issue.
 An example reproducing the error, and a current sessionInfo() Output
 can be found below.

 Many thanks once again,

 Katharina


 R Code Example
 snip
   library(RCurl)
   library(mgcv)
   #retrieve xylemRohWeekXnn2011 test data frame
   eval( expr = parse( text =

 getURL(https://webdisk.ads.mwn.de/Handlers/AnonymousDownload.ashx?folder=1a7cbaa4path=xylemRohWeekXnn2011.R;)
 ))

   xylemRohWeekXnn.fit.bam  - bam(sensor1 ~ sensor2 + s(site, bs=re)
 + s(site, NthSampling, bs=re) ,  data=xylemRohWeekXnn2011,
 na.action=na.omit)

   #subset data containing gaps for predicting
   gapData - xylemRohWeekXnn2011[is.na(xylemRohWeekXnn2011[,2]) 
 !is.na(xylemRohWeekXnn2011[,11]),c(2:3,6:7, 11)]

   xylemRohWeekXnnSite.fit -
 predict.gam(xylemRohWeekXnn.fit.bam,gapData, type=response, se=F)
 /snap



 My current Session Information (sessionInfo() Output - also confirming
 that the problem exists on both Windows and Mac OS X):
 snip
 R version 3.0.2 (2013-09-25)
 Platform: x86_64-apple-darwin10.8.0 (64-bit)

 locale:
 [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

 attached base packages:
 [1] stats graphics  grDevices utils datasets  methods   base

 other attached packages:
 [1] mgcv_1.7-28nlme_3.1-113   RCurl_1.95-4.1 bitops_1.0-6

 loaded via a namespace (and not attached):
 [1] grid_3.0.2  lattice_0.20-24 Matrix_1.1-2tools_3.0.2
 /snap




 On 31/01/14 12:57, Simon Wood wrote:


 Hi Katharina,

 Could you try upgrading to mgcv_1.7-28, please? There was an occasional
 problem to do with matching factor levels, which is fixed, but I'm not
 very confident that is what is going on.

 If upgrading doesn't work, is there any chance you could send me a small
 example dataset and code that produces the error, and I'll look at it?

 best,
 Simon

 --
 Simon Wood, Mathematical Science, University of Bath BA2 7AY UK
 +44 (0)1225 386603   http://people.bath.ac.uk/sw283



 --
 Simon Wood, Mathematical Science, University of Bath BA2 7AY UK
 +44 (0)1225 386603   http://people.bath.ac.uk/sw283



-- 
Katharina May
BSc. Forest Science and Resource Management
IT Specialist (CCI)

Prinz-Ludwig-Str. 7
85354 Freising
Germany

Mobile: +49-176-24031809
www: m3y.de

__
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] package mgcv - predict with bam: Error in X[ind, ] : subscript out of bounds

2014-02-02 Thread Katharina May
Hi Simon,

thank you for your reply, I really appreciate any help to understand
the problem here...
Unluckily the package upgrade didn't help with this issue.
An example reproducing the error, and a current sessionInfo() Output
can be found below.

Many thanks once again,

   Katharina


R Code Example
snip
 library(RCurl)
 library(mgcv)
 #retrieve xylemRohWeekXnn2011 test data frame
 eval( expr = parse( text =
getURL(https://webdisk.ads.mwn.de/Handlers/AnonymousDownload.ashx?folder=1a7cbaa4path=xylemRohWeekXnn2011.R;)
))

 xylemRohWeekXnn.fit.bam  - bam(sensor1 ~ sensor2 + s(site, bs=re)
+ s(site, NthSampling, bs=re) ,  data=xylemRohWeekXnn2011,
na.action=na.omit)

 #subset data containing gaps for predicting
 gapData - xylemRohWeekXnn2011[is.na(xylemRohWeekXnn2011[,2]) 
!is.na(xylemRohWeekXnn2011[,11]),c(2:3,6:7, 11)]

 xylemRohWeekXnnSite.fit -
predict.gam(xylemRohWeekXnn.fit.bam,gapData, type=response, se=F)
/snap



My current Session Information (sessionInfo() Output - also confirming
that the problem exists on both Windows and Mac OS X):
snip
R version 3.0.2 (2013-09-25)
Platform: x86_64-apple-darwin10.8.0 (64-bit)

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats graphics  grDevices utils datasets  methods   base

other attached packages:
[1] mgcv_1.7-28nlme_3.1-113   RCurl_1.95-4.1 bitops_1.0-6

loaded via a namespace (and not attached):
[1] grid_3.0.2  lattice_0.20-24 Matrix_1.1-2tools_3.0.2
/snap




On 31/01/14 12:57, Simon Wood wrote:

Hi Katharina,

Could you try upgrading to mgcv_1.7-28, please? There was an occasional
problem to do with matching factor levels, which is fixed, but I'm not
very confident that is what is going on.

If upgrading doesn't work, is there any chance you could send me a small
example dataset and code that produces the error, and I'll look at it?

best,
Simon

--
Simon Wood, Mathematical Science, University of Bath BA2 7AY UK
+44 (0)1225 386603   http://people.bath.ac.uk/sw283

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


[R] package mgcv - predict with bam: Error in X[ind, ] : subscript out of bounds

2014-01-30 Thread Katharina May
Dear R-Community,

I`m trying to apply the mgcv package to fill gaps in sensor data from
different sites (9 sites, 2 sensors per site) and do the filling on a
site-wise level.
Based on 
http://r.789695.n4.nabble.com/mgcv-gamm-predict-to-reflect-random-s-effects-td3622738.html
my model looks like this:
 xylemRohWeekXnn.fit.bam  - bam(sensor1 ~ sensor2 + s(site, bs=re)
+ s(site, NthSampling, bs=re) ,  data=xylemRohWeekXnn2011,
na.action=na.omit)

However, than I try to use predict, I get an error:
gapData - xylemRohWeekXnn2011[is.na(xylemRohWeekXnn2011[,2]) 
!is.na(xylemRohWeekXnn2011[,11]),c(2:3,6:7, 11)]
xylemRohWeekXnnSite.fit -
predict.gam(xylemRohWeekXnn.fit.bam,gapData, type=response, se=F)
Error in X[ind, ] : subscript out of bounds

I was hoping that someone might be able to provide a quick hint on if
there is an obvious problem or mistake  within my model
declaration/approach?
I attached the sessionInfo() Output below and the xylemRohWeekXnn2011
dump can be downloaded here:
https://webdisk.ads.mwn.de/Handlers/AnonymousDownload.ashx?folder=1a7cbaa4path=xylemRohWeekXnn2011.txt
I`m appreciating any help and hints!

Thank you very much, Katharina

-
sessionInfo()
-
R version 3.0.2 (2013-09-25)
Platform: x86_64-w64-mingw32/x64 (64-bit)

locale:
[1] LC_COLLATE=German_Germany.1252  LC_CTYPE=German_Germany.1252
LC_MONETARY=German_Germany.1252
[4] LC_NUMERIC=CLC_TIME=German_Germany.1252

attached base packages:
[1] splines   stats graphics  grDevices utils datasets
methods   base

other attached packages:
 [1] mgcv_1.7-27 plyr_1.8ggplot2_0.9.3.1 lattice_0.20-24
gdata_2.13.2nlme_3.1-113
 [7] zoo_1.7-10  xlsx_0.5.5  xlsxjars_0.5.0  rJava_0.9-6

loaded via a namespace (and not attached):
 [1] colorspace_1.2-4   dichromat_2.0-0digest_0.6.4
grid_3.0.2 gtable_0.1.2
 [6] gtools_3.2.1   labeling_0.2   MASS_7.3-29
Matrix_1.1-2   munsell_0.4.2
[11] proto_0.3-10   RColorBrewer_1.0-5 reshape2_1.2.2
scales_0.2.3   stringr_0.6.2
[16] tools_3.0.2

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


[R] Package zoo - na.rm ignored?

2013-06-17 Thread Katharina May
Dear R Users,

I've got a strange problem, which I do not really understand:

when I use na.spline from the zoo package, the option na.rm is just being
ignored, see this adjusted example from the na.spline help page:

d0 - as.Date(2000-01-01)
z - zoo(c(NA, 11, 13, NA, 15, NA), d0 + 1:6)
na.spline(z)
na.spline(z, na.rm = FALSE)
na.spline(z, na.rm = T)
###

In all 3 cases, the output looks like this with the trailing NA being
replaced:
2000-01-02 2000-01-03 2000-01-04 2000-01-05 2000-01-06 2000-01-07
  8.33  11.00  13.00  14.33  15.00  15.00

Am I missing something here?
Any help is very much appreciated...

Thanks,

   Katharina





###
Background Info:
###
sessionInfo()
R version 3.0.1 (2013-05-16)
Platform: x86_64-w64-mingw32/x64 (64-bit)

locale:
[1] LC_COLLATE=German_Germany.1252  LC_CTYPE=German_Germany.1252
 LC_MONETARY=German_Germany.1252
[4] LC_NUMERIC=CLC_TIME=German_Germany.1252

attached base packages:
[1] stats graphics  grDevices utils datasets  methods   base

other attached packages:
[1] nlme_3.1-109   zoo_1.7-10 xlsx_0.5.1 xlsxjars_0.5.0 rJava_0.9-5


loaded via a namespace (and not attached):
[1] grid_3.0.1  lattice_0.20-15 tools_3.0.1

[[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] Package zoo - na.rm ignored?

2013-06-17 Thread Katharina May
many thanks for the enlightenment - I guess I completely misunderstood the
na.rm option here...


On 18 June 2013 00:50, Gabor Grothendieck ggrothendi...@gmail.com wrote:

 On Mon, Jun 17, 2013 at 6:23 PM, Katharina May
 may.kathar...@googlemail.com wrote:
  Dear R Users,
 
  I've got a strange problem, which I do not really understand:
 
  when I use na.spline from the zoo package, the option na.rm is just being
  ignored, see this adjusted example from the na.spline help page:
  
  d0 - as.Date(2000-01-01)
  z - zoo(c(NA, 11, 13, NA, 15, NA), d0 + 1:6)
  na.spline(z)
  na.spline(z, na.rm = FALSE)
  na.spline(z, na.rm = T)
  ###
 
  In all 3 cases, the output looks like this with the trailing NA being
  replaced:
  2000-01-02 2000-01-03 2000-01-04 2000-01-05 2000-01-06 2000-01-07
8.33  11.00  13.00  14.33  15.00  15.00
 
  Am I missing something here?
  Any help is very much appreciated...
 

 If the result of the spline interpolation still results in NAs then
 na.rm=TRUE will remove any leading NAs.  It may be that all currently
 supported methods produce no NAs in which case this argument would
 only be there for compatability with na.approx and in case future
 additional spline methods do produce NAs.


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


[R] round Date object to 10 minutes intervals?

2011-12-12 Thread Katharina May
Hello *,

I'm trying to round time stamps, consisting of a date and time part, to 10
minutes intervals
The timestamps have the following format: %d.%m.%Y %H:%M

*timeStamp - c(31.03.2011 09:30, 31.03.2011 09:41, 31.03.2011 10:04,
31.03.2011 10:10, 31.03.2011 10:28, 31.03.2011 10:35, 31.03.2011
10:49, 31.03.2011 23:59)*

should look like this:
*timeStamp2 - c(31.03.2011 09:30, 31.03.2011 09:40, 31.03.2011
10:00, 31.03.2011 10:10, 31.03.2011 10:30, 31.03.2011 10:40,
31.03.2011 10:55, 01.04.2011 00:00)*

I've found this topic on the web:
http://stats.stackexchange.com/questions/5305/how-to-re-sample-an-xts-time-series-in-r

library(xts)
align.time(as.POSIXct(timeStamp, format=%d.%m.%Y %H:%M), 10 * 60)

which uses the align.time function from the library xts BUT as far as I can
see only supports either all timestamps being either  rounded up or down
(not both, depending on the minutes 0-9 being either  or  5 line the way
I need it)

As I'm really struggling with this topic, any help and hint is  awarded
with greatest thankfulness from my side…

Best regards, Katharina

[[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] linear model: Test difference between coefficients and given values (t.test?)

2009-08-09 Thread Katharina May
Thanks to somebody I got the hint to use offset for the purpose of
validating if there's
a difference between the intercept and slope of a model and some
provided values for
the coefficients intercept and slope.

I read ?model.offset and I'm still struggling to use it for my
purpose. If I understood
the concepts correctly, offset can be used to define a known
coefficient of a model,
so therefore I could create two models based on the same data like my
original one
 with an additional offset term (one model with intercept specified
and one with the
slope specified)?

Sorry for troubling you: I struggling with the data analysis of my
bachelor thesis and
just want to compare the coefficients of my linear regression to
published ones...
a method often used I guess, but still I cannot find any appropriate
documentations.

Thanks,

 Katharina


 On Aug 8, 2009, Katharina May may.kathar...@googlemail.com wrote:

 Hi there,

 I've got a question which is really trivial for sure but still I have
 to ask as I'm not
 making any progress solving it by myself (please be patient with an
 undergraduate
 student):

 I've got a linear model (lm and lmer fitted with method=ML).
 Now I want to compare the coefficients (slope, intercept, not the
 random effects)
 of both models with a given value (e.g. intercept=0.5, slope=2) to see
 if the values
 estimated with the models are significantly different from the given values.

 I heard about t.test, but I'm sorry to say that I'm not quite
 understanding what I have
 to provide as arguments.

 I would be more than happy if somebody can point out an example similar to
 the
 comparison I have to do...

 Thanks,

 Katharina

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


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


[R] linear model: Test difference between coefficients and given values (t.test?)

2009-08-08 Thread Katharina May
Hi there,

I've got a question which is really trivial for sure but still I have
to ask as I'm not
making any progress solving it by myself (please be patient with an
undergraduate
student):

I've got a linear model (lm and lmer fitted with method=ML).
Now I want to compare the coefficients (slope, intercept, not the
random effects)
of both models with a given value (e.g. intercept=0.5, slope=2) to see
if the values
estimated with the models are significantly different from the given values.

I heard about t.test, but I'm sorry to say that I'm not quite
understanding what I have
to provide as arguments.

I would be more than happy if somebody can point out an example similar to the
comparison I have to do...

Thanks,

 Katharina

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


[R] package lmodel2: p-value RMA fitting?

2009-07-20 Thread Katharina May
Hi *,

is there a way to obtain some kind of p-value for a model fitted with RMA
using the lmodel2 package?
I know that p-values are discussed and criticized a lot and as you can image
from my question I'm not
very much of a statistican (only writing my bachelor thesis).

As fare as I understood the confidence interval statistic correctly, a
coefficient is regarded as statistically
significant if the corresponding CI does not include 0 (null hypothesis).
But can I obtain some kind of a
p-value to say that it is highly significant ( 0.01), significant
(0.05),... like in the output of lm?

Sorry for bothering everybody with this, well, probably rather idiotic
question, but I don't know where to
continue from this point...

Thanks,

  Katharina


Here the output of my lmodel2 regression:


Model II regression

Call: lmodel2(formula = log(AGB) ~ log(BM_roots), data = biomass_data,
range.y = interval, range.x = interval, nperm = 99)

n = 1969   r = 0.9752432   r-square = 0.9510993
Parametric P-values:   2-tailed = 01-tailed = 0
Angle between the two OLS regression lines = 1.433308 degrees

Permutation tests of OLS, MA, RMA slopes: 1-tailed, tail corresponding to
sign
A permutation test of r is equivalent to a permutation test of the OLS slope
P-perm for SMA = NA because the SMA slope cannot be tested

Regression results
  Method Intercept Slope  Angle (degrees)  P-perm (1-tailed)
1OLS 0.6122146  1.038792 46.09002   0.01
2 MA 0.5787299  1.066868 46.85300   0.01
3SMA 0.5807645  1.065162 46.80725 NA
4RMA 0.5792123  1.066463 46.84216   0.01

Confidence intervals
  Method  2.5%-Intercept 97.5%-Intercept  2.5%-Slope 97.5%-Slope
1OLS   0.5779465   0.64648281.0283761.049207
2 MA   0.5659033   0.59142031.0562271.077622
3SMA   0.5682815   0.59312601.0547971.075628
4RMA   0.5663916   0.59189891.0558261.077213

Eigenvalues: 19.83213 0.2475542

H statistic used for computing C.I. of MA: 2.502866e-05

[[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] package lmodel2: p-value RMA fitting?

2009-07-20 Thread Katharina May
sorry for spaming, but IU just had an idea not sure if that may be a way of
doing it:

1. calculate the standrad error of e.g. intercept as mean of the standards
errors obtained from the upper/lower
confidence intervals of the intercept
 error_intercept1 = (allo.lmodel2$confidence.intervals[4,2] -
mean(log(biomass_data$BM_roots)))/1.96
 error_intercept2 = (allo.lmodel2$confidence.intervals[4,3] -
mean(log(biomass_data$BM_roots)))/1.96
 stderr_intercept = round((error_intercept1+error_intercept2)/2,
digits=8)

2. Calculate the t-value as intercept estimate divided by the standard error
from 1. and using
 the following for calculating a two-tailed p-value
  p_intercept = 2 * (1 - pt(abs(intercept/stderr_intercept),
df=length(biomass_data)-1))

Might this a reasonable approach for a 'rough' estimation of an p-value? I
glad for every suggestion...



2009/7/20 Katharina May may.kathar...@googlemail.com

 Hi *,

 is there a way to obtain some kind of p-value for a model fitted with RMA
 using the lmodel2 package?
 I know that p-values are discussed and criticized a lot and as you can
 image from my question I'm not
 very much of a statistican (only writing my bachelor thesis).

 As fare as I understood the confidence interval statistic correctly, a
 coefficient is regarded as statistically
 significant if the corresponding CI does not include 0 (null hypothesis).
 But can I obtain some kind of a
 p-value to say that it is highly significant ( 0.01), significant
 (0.05),... like in the output of lm?

 Sorry for bothering everybody with this, well, probably rather idiotic
 question, but I don't know where to
 continue from this point...

 Thanks,

   Katharina


 Here the output of my lmodel2 regression:


 Model II regression

 Call: lmodel2(formula = log(AGB) ~ log(BM_roots), data = biomass_data,
 range.y = interval, range.x = interval, nperm = 99)

 n = 1969   r = 0.9752432   r-square = 0.9510993
 Parametric P-values:   2-tailed = 01-tailed = 0
 Angle between the two OLS regression lines = 1.433308 degrees

 Permutation tests of OLS, MA, RMA slopes: 1-tailed, tail corresponding to
 sign
 A permutation test of r is equivalent to a permutation test of the OLS
 slope
 P-perm for SMA = NA because the SMA slope cannot be tested

 Regression results
   Method Intercept Slope  Angle (degrees)  P-perm (1-tailed)
 1OLS 0.6122146  1.038792 46.09002   0.01
 2 MA 0.5787299  1.066868 46.85300   0.01
 3SMA 0.5807645  1.065162 46.80725 NA
 4RMA 0.5792123  1.066463 46.84216   0.01

 Confidence intervals
   Method  2.5%-Intercept 97.5%-Intercept  2.5%-Slope 97.5%-Slope
 1OLS   0.5779465   0.64648281.0283761.049207
 2 MA   0.5659033   0.59142031.0562271.077622
 3SMA   0.5682815   0.59312601.0547971.075628
 4RMA   0.5663916   0.59189891.0558261.077213

 Eigenvalues: 19.83213 0.2475542

 H statistic used for computing C.I. of MA: 2.502866e-05





-- 
Time flies like an arrow, fruit flies like bananas.

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


[R] distinguish regression lines in grouped, black and white lattice xyplot

2009-06-24 Thread Katharina May
Hi,

I've got the following problem which I cannot think of a solution right now:

if got a lattice xyplot in black and white and a grouping variable
with many (more than 8
values) and I plot it as regression lines (type=r), just like this
one (not reproducable but that's
I guess not the point here):

xyplot(log(AGWB) ~ log(BM_roots), data=sub_agwb_data, groups=species,
type=r, lty=c(1:6),panel=allo.panel.5)

The problem is that I've got 26 different values for the grouping
variable species and only 6 default values for the line type
lty (and according to the par {graphics} help page customizable to up
to 8 different line types).

Does anybody have any idea how these 26 different lines can be made
distinguishable from each other without the use
of colors?

Thanks,

 Katharina

__
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] distinguish regression lines in grouped, black and white lattice xyplot

2009-06-24 Thread Katharina May
That's a point. I justed wanted to provide an overview for myself to
see the tendencies in a direct comparement
and with an easy way to distinct them, but maybe the text panel can
help me with that...

Well anyway, is it right that a grouped black and white plot can
contain a maxinum of 8 distinguishable  lines or might
there be a way to increase that?
I know some graphics from papers containing lines with equally
distance points on the lines (one type of point per line)
as a form of distinction. Can this be realised using grouped lattice
plots with regression lines?


2009/6/24 Bert Gunter gunter.ber...@gene.com:
 Don't be silly. They can't be made distinguishable by any number of line
 types and/or colors. The brain can't keep that many different symbol
 representations straight. Referring back and forth to a legend is also
 similarly useless. You need to think more creatively about how to make a
 more meaningful display to provide viewers interpretable information.

 Bert Gunter
 Genentech Nonclinical Biostatistics


 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On
 Behalf Of Katharina May
 Sent: Wednesday, June 24, 2009 12:28 PM
 To: r-help@r-project.org
 Subject: [R] distinguish regression lines in grouped,black and white lattice
 xyplot

 Hi,

 I've got the following problem which I cannot think of a solution right now:

 if got a lattice xyplot in black and white and a grouping variable
 with many (more than 8
 values) and I plot it as regression lines (type=r), just like this
 one (not reproducable but that's
 I guess not the point here):

 xyplot(log(AGWB) ~ log(BM_roots), data=sub_agwb_data, groups=species,
 type=r, lty=c(1:6),panel=allo.panel.5)

 The problem is that I've got 26 different values for the grouping
 variable species and only 6 default values for the line type
 lty (and according to the par {graphics} help page customizable to up
 to 8 different line types).

 Does anybody have any idea how these 26 different lines can be made
 distinguishable from each other without the use
 of colors?

 Thanks,

         Katharina

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





-- 
Time flies like an arrow, fruit flies like bananas.

__
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] lattice logaritmic scale (basis e ), rewriting labels using xscale.component

2009-06-22 Thread Katharina May
thanks Deepayan, that works great!


2009/6/19 Deepayan Sarkar deepayan.sar...@gmail.com:
 On 6/18/09, Katharina May may.kathar...@googlemail.com wrote:
 Hi there,

  sorry for troubling everybody once again, I've got a problem rewriting
  Sarkar's function for
  rewriting the tick locations in a logaritmic way (s.
  http://lmdvr.r-forge.r-project.org/code/Chapter08.R):

  His example works for log 2 but I need log e (natural logarithm). My
  problem is that if I replace
  2 with e (using paste()), I get the error message that the location
  isn't a numeric value.

 R doesn't have a constant that represents e, but

  tick.at - logTicks(exp(lim), loc = c(1, 3))

 instead of

  tick.at - logTicks(paste(e^,lim,sep=), loc = c(1, 3))

 should give you e^lim. Or, if it makes it easier,

  e - exp(1)
  tick.at - logTicks(e^lim, loc = c(1, 3))

 I don't think you need to change the logTicks function.

 -Deepayan

  Is there any way to get this working somehow or do I have to take a
  different approach?

  Thanks, Katharina

  Here my failing approach:

  require(lattice)
  data(Earthquake, package = MEMSS)

  xscale.components.log - function(lim, ...) {
     ans - xscale.components.default(lim = lim, ...)
     tick.at - logTicks(paste(e^,lim,sep=), loc = c(1, 3))
     ans$bottom$ticks$at - log(tick.at, 2)
     ans$bottom$labels$at - log(tick.at, 2)
     ans$bottom$labels$labels - as.character(tick.at)
     ans
  }

  logTicks - function (lim, loc = c(1, 5)) {
     ii - floor(log(range(lim))) + c(-1, 2)
     main - paste(e^,(ii[1]:ii[2]),sep=)
     r - as.numeric(outer(loc, main, *))
     r[lim[1] = r  r = lim[2]]
  }
  xyplot(accel ~ distance, data=Earthquake, scales = list(log = e),
  xscale.components = xscale.components.log,




  Here is the original  code of Sarkar:

  logTicks - function (lim, loc = c(1, 5)) {
     ii - floor(log10(range(lim))) + c(-1, 2)
     main - 10^(ii[1]:ii[2])
     r - as.numeric(outer(loc, main, *))
     r[lim[1] = r  r = lim[2]]
  }
  xscale.components.log2 - function(lim, ...) {
     ans - xscale.components.default(lim = lim, ...)
     tick.at - logTicks(2^lim, loc = c(1, 3))
     ans$bottom$ticks$at - log(tick.at, 2)
     ans$bottom$labels$at - log(tick.at, 2)
     ans$bottom$labels$labels - as.character(tick.at)
     ans
  }

  __
  r-h...@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.





-- 
Time flies like an arrow, fruit flies like bananas.

__
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] lattice: axis ticks, axis alignment and remove axis from plot

2009-06-18 Thread Katharina May
 on either side. (May not
 always work as expected.)



 --
 Sorn Norng
 Biometrician
 Department of Primary Industries
 Knoxfield Centre
 621 Burwood Highway, Ferntree Gully 3156
 Ph: (03) 9210 9358
 Mob: 0428344515
 Fax: (03) 9800 3521
 Email: sorn.no...@dpi.vic.gov.au

 -



  *Katharina May may.kathar...@googlemail.com*
 Sent by: r-help-boun...@r-project.org

 17/06/2009 07:24 PM
   To
 r-help@r-project.org  cc
   Subject
 [R] lattice: axis ticks, axis alignment and remove axis from plot




 Hi there,

 I'm a bit confused concerning the axis tck setting in the lattice
 package as the ticks on left sided axis aren't
 drawn at all with the following setting:

 dados - data.frame(varsep = factor(rep(1:2,10)),
i = runif(20))

 library(lattice)

 my.theme - list(
axis.components = list(left = list(tck = 1, pad1 = 1, pad2 =
 2), top = list(tck = 0, pad1 = 1, pad2 = 0), right = list(tck = 0,
 pad1 = 1, pad2 = 0), bottom = list(tck = +0.5, pad1 = 1, pad2 = 2)))

 trellis.par.set(theme = my.theme)


 bwplot(varsep ~ i, dados,
   xlab = names(dados)[1],
   ylab = names(dados)[2],
   panel = function(...) {
 panel.grid(v = -1, h = 0)
 panel.bwplot(...)
   })



 Maybe somebody can help me recognise the problem why the left sided
 ticks are not drawn.

 I'm also wondering how to tell the trellis object not to draw the
 right and top axes at all an how to align the y axis
 that it goes through x=0?

 Thanks,

Katharina

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

 Notice:
 This email and any attachments may contain information...{{dropped:30}}

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


[R] lattice logaritmic scale (basis e ), rewriting labels using xscale.component

2009-06-18 Thread Katharina May
Hi there,

sorry for troubling everybody once again, I've got a problem rewriting
Sarkar's function for
rewriting the tick locations in a logaritmic way (s.
http://lmdvr.r-forge.r-project.org/code/Chapter08.R):

His example works for log 2 but I need log e (natural logarithm). My
problem is that if I replace
2 with e (using paste()), I get the error message that the location
isn't a numeric value.

Is there any way to get this working somehow or do I have to take a
different approach?

Thanks, Katharina

Here my failing approach:

require(lattice)
data(Earthquake, package = MEMSS)

xscale.components.log - function(lim, ...) {
ans - xscale.components.default(lim = lim, ...)
tick.at - logTicks(paste(e^,lim,sep=), loc = c(1, 3))
ans$bottom$ticks$at - log(tick.at, 2)
ans$bottom$labels$at - log(tick.at, 2)
ans$bottom$labels$labels - as.character(tick.at)
ans
}

logTicks - function (lim, loc = c(1, 5)) {
ii - floor(log(range(lim))) + c(-1, 2)
main - paste(e^,(ii[1]:ii[2]),sep=)
r - as.numeric(outer(loc, main, *))
r[lim[1] = r  r = lim[2]]
}
xyplot(accel ~ distance, data=Earthquake, scales = list(log = e),
xscale.components = xscale.components.log,




Here is the original  code of Sarkar:

logTicks - function (lim, loc = c(1, 5)) {
ii - floor(log10(range(lim))) + c(-1, 2)
main - 10^(ii[1]:ii[2])
r - as.numeric(outer(loc, main, *))
r[lim[1] = r  r = lim[2]]
}
xscale.components.log2 - function(lim, ...) {
ans - xscale.components.default(lim = lim, ...)
tick.at - logTicks(2^lim, loc = c(1, 3))
ans$bottom$ticks$at - log(tick.at, 2)
ans$bottom$labels$at - log(tick.at, 2)
ans$bottom$labels$labels - as.character(tick.at)
ans
}

__
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] lattice: axis ticks, axis alignment and remove axis from plot

2009-06-18 Thread Katharina May
Hi Jim,

thanks, that sounds like a good idea!
The only problem is that axis and pos are a far as I know not for
lattice or at least I
cannot find an appropriate function and way to do this in lattice.
Maybe I have to keep on searching for how to realize that with lattice...

Best wishes,
   Katharina



2009/6/18 Jim Lemon j...@bitwrit.com.au:
 Katharina May wrote:

 What I sort of looking for is a xyplot with both the x axis at the bottom
 and y axis at the
 left going through 0, but continuing  in the positive and negative area
 (forming a kind of cross
 like e.g.

 http://upload.wikimedia.org/wikipedia/commons/thumb/2/2c/Erf_plot.svg/600px-Erf_plot.svg.png

 I'm not sure if this possible at all or if I just have to add to reference
 lines at x=0 and y =0 as a
 workaround even though not fully satisfying...?


 Hi Katharina,
 I'm not sure if you can do this in lattice, but if you do the original plot
 with axes=FALSE, you can specify where the x and y axis are placed with the
 pos= argument.

 Jim





-- 
Time flies like an arrow, fruit flies like bananas.

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


[R] lattice: axis ticks, axis alignment and remove axis from plot

2009-06-17 Thread Katharina May
Hi there,

I'm a bit confused concerning the axis tck setting in the lattice
package as the ticks on left sided axis aren't
drawn at all with the following setting:

dados - data.frame(varsep = factor(rep(1:2,10)),
i = runif(20))

library(lattice)

my.theme - list(
axis.components = list(left = list(tck = 1, pad1 = 1, pad2 =
2), top = list(tck = 0, pad1 = 1, pad2 = 0), right = list(tck = 0,
pad1 = 1, pad2 = 0), bottom = list(tck = +0.5, pad1 = 1, pad2 = 2)))

trellis.par.set(theme = my.theme)


bwplot(varsep ~ i, dados,
   xlab = names(dados)[1],
   ylab = names(dados)[2],
   panel = function(...) {
 panel.grid(v = -1, h = 0)
 panel.bwplot(...)
   })



Maybe somebody can help me recognise the problem why the left sided
ticks are not drawn.

I'm also wondering how to tell the trellis object not to draw the
right and top axes at all an how to align the y axis
that it goes through x=0?

Thanks,

Katharina

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


[R] color in grouped lattice xyplot plot

2009-06-11 Thread Katharina May
Hi,

I've got a data.frame object which I would like to plot in a lattice
xyplot grouped by a variable and using a value for the color of each
point which is stored in a variable in the same data.frame.

I tried the following code:

my.panel.xy - function(x, y, ...){
  panel.xyplot(x, y,  ...)
  panel.lmline(x, y, lwd = 2)
  panel.abline(0, 1, col=red, lty=2)
  panel.grid(h = -1, v = -1, lty=1)
  }

xyplot(log(AGB) ~ log(BM_roots) | as.character(taxa),
data=sub_agb_data,main=list(AGB in dependence of BM_root [per
taxa!],cex=0.7),

ylab=list(log(AGB),cex=0.7),xlab=list(log(BM_root),cex=0.7),col=sub_agb_data$color,
panel = my.panel.xy)

xyplot(log(AGB) ~ log(BM_roots) | as.character(species),
data=sub_agb_data,main=list(AGB in dependence of BM_root [per
species!],cex=0.7),

ylab=list(log(AGB),cex=0.7),xlab=list(log(BM_root),cex=0.7),col=sub_agb_data$color,
panel = my.panel.xy)



Somehow the colors are not displayed correctly (it works if I use plot
in a for loop for each value for the variables for which I group my
lattice plots. The color variable is of type character so this
shouldn't be the reason)

The object sub_agb_object can be downloaded here:
http://www.wzw.tum.de/oekophys/fileadmin/sub_agb_data.rData

Maybe somebody has any idea how to make this work or what the problem might be?

Thanks,

Katharina

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


[R] wrong labels and colors of points in graph/plot

2009-06-04 Thread Katharina May
Hi there,

I trying to solve this problem for the whole day not going anywhere,
so I  really hope maybe somebody can help
me in this community...
I've got an object coefficient2 which I want to plot in differerent
ways, with colors and labels added to the points,
but somehow there seems to be a problem if a value is NA within the
independent variable, resulting in false labels and false colors for
the points.

plot(coefficient2$intercept ~ coefficient2$average_height,
main=intercepts ::: height, ylab=intercepts, xlab=average height
per site [cm], xlim=c(20,3020), ylim=c(-2,5), col=coefficient2$color)
highlight(coefficient2$intercept ~ coefficient2$average_height,
lbls=coefficient2$site_no,col=Red, cex = .6)

plot(coefficient2$intercept ~ coefficient2$average_dbh,
main=intercepts ::: dbh, ylab=intercepts, xlab=average dbh per
site [mm], xlim=c(-10,360), ylim=c(-2,5),col=coefficient2$color )
highlight(coefficient2$intercept ~ coefficient2$average_dbh,
lbls=coefficient2$site_no,col=Red, cex = .6


If I create a temporary object for each plot excluding any NA values
for the x axis variable, somehow all points are displayed and the
labels are correct except for the color (I have e.g. no clue why some
points are red which I do not define at all and no ones are yellow
which I use several times).

#create temp container for all coefficients with average heights for plotting
coef_avheight - coefficient2[which(!is.na(coefficient2$average_height)),]
plot(coef_avheight$intercept ~ coef_avheight$average_height,
main=intercepts ::: height, ylab=intercepts, xlab=average height
per site [cm], xlim=c(20,3020), ylim=c(-2,5),
col=coef_avheight$color)
highlight(coef_avheight$intercept ~ coef_avheight$average_height,
lbls=coef_avheight$site_no,col=Red, cex = .6)

#create temp container for all coefficients with average dbh for plotting
coef_avdbh- coefficient2[which(!is.na(coefficient2$average_dbh)),]
plot(coef_avdbh$intercept ~ coef_avdbh$average_dbh,  main=intercepts
::: dbh, ylab=intercepts, xlab=average dbh per site [mm],
xlim=c(-10,360), ylim=c(-2,5),col=coef_avdbh$color )
highlight(coef_avdbh$intercept ~ coef_avdbh$average_dbh,
lbls=coef_avdbh$site_no,col=Red, cex = .6)


Maybe someone can explain me the color issue and the problem with the
NA values which results in a wrong labeling and to few
points being displayed? I'm new to R as you can guess and my code
isn't really elegant but I really cannot get faults within it...


Attached you can find the referred R object (coefficient2).
highlight requires library(NCStats)...

Thank you very, very much,

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


[R] write values of points beside points in plot

2009-06-01 Thread Katharina May
Hi everyone,

is it possible to write a certain value beside a point in a plot?

I'm plotting the following:
plot(coefficient$intercept ~ coefficient$average_BM_leaves_needles,
main=intercepts ::: BM_leaves_needles,
 ylab=intercepts, xlab=average BM_leaves_needles per site [kg])

and I want to have the value of coefficient$site_no written beside
each point within the plot (to recognize them)

sorry for troubling you with this question, but I somehow can't find
any information on it
(maybe because I'm not quite sure what to search for)

Thanks a lot,

  Katharina

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


[R] remove empty objects from workspace

2009-05-19 Thread Katharina May
Hi,

how can I remove all empty objects (which are NA or have zero rows)
from my workspace?

Thanks,

 Katharina

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


[R] Remove objects names like character String

2009-05-19 Thread Katharina May
Hi,

how can I use rm() on objects named like:
paste(site,i,_data,sep=) while looping
through i?
I tried rm(paste(site,i,_data,sep=)) but I get the error that
rm() must contain names or
text strings which is confusing me as I thought paste() would create
something like that...?

Thanks,


 Katharina



-- 
Time flies like an arrow, fruit flies like bananas.

__
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] remove empty objects from workspace

2009-05-19 Thread Katharina May
Thanks Jim, the removal of objects which are NA works perfectly!

For my second problem it didn't express myself correctly:
I  actually meant objects with rows (attributes?) but no data in it
but I solved this
adjusting your approach:

for(object in objects()) if(is.null(dim(get(object))[1]) ||
dim((get(object)))[1] == 0) rm(list=object)

Thanks a lot!


2009/5/19 Jim Lemon j...@bitwrit.com.au:
 Katharina May wrote:

 Hi,

 how can I remove all empty objects (which are NA or have zero rows)
 from my workspace?



 Hi Katharina,
 To remove objects that are all NA:

 for(object in objects()) if(all(is.na(get(object rm(list=object)

 If by zero rows you mean objects that do not have a dimension:

 for(object in objects()) if(is.null(dim(get(object rm(list=object)

 Jim





-- 
Time flies like an arrow, fruit flies like bananas.

__
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] Remove objects names like character String

2009-05-19 Thread Katharina May
thanks to all your solutions, works out perfectly!


2009/5/19 Henrique Dallazuanna www...@gmail.com:
 Try this:

 rm(list=ls(patt=site[0-9]$))

 On Tue, May 19, 2009 at 7:47 AM, Katharina May
 may.kathar...@googlemail.com wrote:

 Hi,

 how can I use rm() on objects named like:
 paste(site,i,_data,sep=) while looping
 through i?
 I tried rm(paste(site,i,_data,sep=)) but I get the error that
 rm() must contain names or
 text strings which is confusing me as I thought paste() would create
 something like that...?

 Thanks,


         Katharina



 --
 Time flies like an arrow, fruit flies like bananas.

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



 --
 Henrique Dallazuanna
 Curitiba-Paraná-Brasil
 25° 25' 40 S 49° 16' 22 O




-- 
Time flies like an arrow, fruit flies like bananas.

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


[R] create string of comma-separated content of vector

2009-05-19 Thread Katharina May
Hi,

how do I create a string of the comma-separated content of a vector?

I've got the vector i with several numeric values as content:
str(i)
num 99

and want to create a SQL statement to look like the following where
the part '(2, 4, 6, 7)' should be
the content of the vector i:
select * from  [biomass_data$] where site_no in (2, 4, 6, 7)

Here my approach (which doesn't work):
site_all_data =  sqlQuery(channel, select * from  [biomass_data$]
where site_no in (,paste(i,sep=,),) )


sorry for spaming so much today to the mailing list...

-Katharina

-- 
Time flies like an arrow, fruit flies like bananas.

__
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] create objects in a loop and adding sqlQuery content to them

2009-04-21 Thread Katharina May

I finally found the problem within my site_data object...
this works well:
snip
site_data  -  sqlQuery(channel, select site_no from  [biomass_data$]  
group by site_no)$site_no


for(i in site_data) {
	assign(paste(site,i,_data,sep=), sqlQuery(channel,  
paste(select * from  [biomass_data$] where site_no = ,i,sep=)))

}
/snap

Thanks for all your solution proposals!

Katharina


On 21.04.2009, at 02:43, David Winsemius wrote:



On Apr 20, 2009, at 8:04 PM, Katharina May wrote:


Hi there,

I've got a database or rather spreadsheet with several columns and  
rows.
For one column named sites I want to loop through all possible  
values and retrieve
all data out of the database where site = x and write it into an  
object named 'sitex_data'.


Somehow I'm really missing something as I'm not able to create  
these sitex_data objects with

the database values, neither using list nor assign...

Here some code snipplets:
library (RODBC)
channel - odbcConnectExcel2007 (biomass_data.xlsx)
site_data  -  sqlQuery(channel, select site_no from   
[biomass_data$] group by site_no)


#Here the values I want to loop through
str(site_data)
'data.frame':   44 obs. of  1 variable:
$ site_no: num  4 7 9 10 15 16 17 18 19 20 ...

#Here my first try [error message on the line within the loop,  
saying something like:

# 'recursive indexing on level 2 failed']
sites_object_list - vector(list,99)
for(i in site_data) {
 sites_object_list[[i]] - sqlQuery(channel, paste(select * from   
[biomass_data$] where site_no = ,i,sep=))

}


This does not appear to be a dataset to which we have access, so I  
will take an untested stab at this. What happens if you assign the  
results of the function unique() around site_data$site_no to your  
index, i? That way you would stand a chance of referring to the  
sites in a manner that R might understand and to only use the site  
numbers once apiece in the loop. I'm not a competent SQL programmer  
so i have no comments on that part.


David Winsemius, MD
Heritage Laboratories
West Hartford, CT



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


[R] create objects in a loop and adding sqlQuery content to them

2009-04-20 Thread Katharina May

Hi there,

I've got a database or rather spreadsheet with several columns and rows.
For one column named sites I want to loop through all possible values  
and retrieve
all data out of the database where site = x and write it into an  
object named 'sitex_data'.


Somehow I'm really missing something as I'm not able to create these  
sitex_data objects with

the database values, neither using list nor assign...

Here some code snipplets:
library (RODBC)
channel - odbcConnectExcel2007 (biomass_data.xlsx)
site_data  -  sqlQuery(channel, select site_no from  [biomass_data 
$] group by site_no)


#Here the values I want to loop through
str(site_data)
'data.frame':   44 obs. of  1 variable:
 $ site_no: num  4 7 9 10 15 16 17 18 19 20 ...

#Here my first try [error message on the line within the loop, saying  
something like:

# 'recursive indexing on level 2 failed']
 sites_object_list - vector(list,99)
 for(i in site_data) {
   sites_object_list[[i]] - sqlQuery(channel, paste(select * from   
[biomass_data$] where site_no = ,i,sep=))

 }

#Here my second try [error message  on the line within the loop,  
saying something like:

# 'only the first element will be used as variable name']
for(i in site_data) {
	assign(paste(site,i,_data,sep=), sqlQuery(channel,  
paste(select * from  [biomass_data$] where site_no = ,i,sep=)))


}

I would be very, very glad if anybody sends me a clue about this, as  
I'm a obviuos Newbie using

R...

Thanks,

 Katharina

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