Re: [R] Postscript graphs

2010-01-26 Thread Gavin Simpson
On Mon, 2010-01-25 at 14:05 -0800, Lu Wang wrote:
 Hi,
 
 I tried to use the following commands to create a postscript pie chart using 
 R:
 
 postscript(file=H:/piechart.eps)
 # then I wrote my commands to generate the pie chart
 pie(filename,labels=,col=,radius=0.6)
 dev.off()
 
 After I ran those commands, instead of giving the pie chart, it showed 
  dev.off()
 postscript 
  2 
  
 In my H drive, there is a file called piechart.eps, but I want to look
 at it. Is there any way I can see the figure and import it to word or
 pdf file? I am writing a paper that needs this graph. It would be more
 helpful If I can see it.

Word accepts eps files - did you try importing it? (It may look rubbish
on screen as it displays a low-res preview of the figure and in my
experience doesn't do a very good job on the preview, but it will print
on a postscript printer at high quality, as it will on any printer when
converted your word files is converted to PDF.)

You also need to add some arguments to your postscript call to get EPS:

postscript(file=H:/piechart.eps, height = X, width = Y,
   onefile = FALSE, paper = special)

With X and Y your desired heights in inches.

GSView is a application that also runs on Windows that allows you to
open, view and convert postscript and EPS files. It requires the
Ghostscript interpreter to be installed as well.

How are you producing a pdf? Without knowing that it is difficult to say
how to import your postscript figure into it.

HTH

G

 
 Thanks,
 John
 
 
 
   
   [[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.
-- 
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
 Dr. Gavin Simpson [t] +44 (0)20 7679 0522
 ECRC, UCL Geography,  [f] +44 (0)20 7679 0565
 Pearson Building, [e] gavin.simpsonATNOSPAMucl.ac.uk
 Gower Street, London  [w] http://www.ucl.ac.uk/~ucfagls/
 UK. WC1E 6BT. [w] http://www.freshwaters.org.uk
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%

__
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] R2WinBUGS/ trap

2010-01-26 Thread Bob O'Hara
2010/1/26 Ben Bolker bol...@ufl.edu

 julien martin julemartin0320 at gmail.com writes:

 
  I am generating 1000 replicate data sets in R, each data set is then
  analyzed with WinBUGS in batch mode using R2WinBUGS. Unfortunately,
  occasionally some data sets lead WinBUGS to open a trap window; and the
  simulations are interrupted as result of the message. Is there any ways
 to
  set R2WinBUGS so that it would ignore the trap message and  proceed with
 the
  simulations?

  I'm not sure -- I don't think so -- I don't remember if R hangs
 or returns an error on a trap -- but you could try (1) try()
 and (2) JAGS/R2jags

 A practical suggestion - run this in a loop, and save the output to a file
at the end of each loop.

Also, if you're getting several trap messages with 100 replicates, you might
want to tweak the what you're doing.  e.g. set up initial values close to
the posterior, and make sure your priors aren't too vague.

Bob

-- 
Bob O'Hara

Biodiversity and Climate Research Centre
Senckenberganlage 25
D-60325 Frankfurt am Main,
Germany

Tel: +49 69 798 40216
Mobile: +49 1515 888 5440
WWW:  http://www.RNI.Helsinki.FI/~boh/
Blog: http://network.nature.com/blogs/user/boboh
Google Wave: rni@googlewave.com
Journal of Negative Results - EEB: www.jnr-eeb.org

[[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] Help

2010-01-26 Thread Kanak Choudhury
 Dear All

 I have data as follows.

 D   TM   L
 0.20 1   03   141
 0.321   07   62
 0.50 1   05   49
 0.80 1   04   46
 0.20 2   14  130
 0.322   17  52
 0.50 2   13  41
 0.80 2   14  36
 0.20 3   24  120
 0.323   28  41
 0.50 3   24  30
 0.80 3   22  28
 0.20 4   31  113
 0.324   44  25
 0.50 4   39  15
 0.80 4   36  14
 0.20 5   35  109
 0.325   47  22
 0.50 5   43  11
 0.80 5   44  06
 0.20 6   38  106
 0.326   49  20
 0.50 6   45  09
 0.80 6   46  04

 I want to fit a negative binomial regression model where M is the
 required success and L is number of units to have the required
 success.

 I want to fit the following model

 GLM link, log(1-M / (M+L)) = constant + theta 1 * log(D) + theta 2 *
 1/T + theta 3 * log(D) * 1 / T

 I wrote the function as

  dat = read.table(N_d_t_F.txt,header=T)

  N_D = 4
  N_T = 6

  dat$x= log(dat$D)
  dat$p= dat$M / (dat$L+dat$M)
  dat$InvT = 1/dat$T
  dat$glm1= log(1-dat$p)

  negloglike = function(parms, dat){

  pp   = design%*%parms
  p= 1-exp(pp)

  obj  = 0
  t_D = 0
  for(d in 1:N_D){
  for(t in 1:N_T){
t_D = t_D+1

  obj = obj + dat$M[t_D]*log(p[t_D])
obj = obj + dat$L[t_D]*log(1-p[t_D])

  }
  }
  -obj
  }

  design = cbind(1, dat$x, dat$InvT, dat$x*dat$InvT)
  g = lm(glm1~design-1, dat, subset=c(p0))
  mle.fit = optim(coef(g),  negloglike,
 dat=dat, hessian=T)

 However, this function does not optimize properly. It always creates
 some errors.

 How can I optimize this model?

 This is not a count data. That's why I can not use the function
 glm.nb or aod package.

 Would you please give me some suggestions so that I can optimize the
 function?


[[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] StructTS hang?

2010-01-26 Thread Uwe Ligges



On 25.01.2010 11:03, richard.kie...@rwe.com wrote:

Hi!

You have probably sorted out your problem a different way.
However I have tried dealing with the same problem for a while and writing down 
the reason for this here may be of use to someone.

In some other help-mail I read that time series objects behave unexpectedly in 
some situations if the frequency is too high. As a result of this, a call of 
StructTS (with seasonality) hangs if and only if the frequency is larger than 
24 (if I remember the number right). This is what I found with my own time 
series using several frequencies.

So, this may not be helpful using StructTS on a time series, but it may save 
somebody some time.



Even better: report a reproducible example to the package maintainer who 
is certainly happy to fix bugs in the package.


Best wishes,
Uwe Ligges



Regards,
Richard





Irgendwann kommt jeder drauf! WWW.ENERGIEWELT.DE
---
Vorsitzender des Aufsichtsrates: Dr. Rolf Martin Schmitz
Vorstand: Dr. Johannes Lambertz (Vorsitzender),
Prof. Dr. Gerd Jaeger, Antonius Voss,
Erwin Winkel

Sitz der Gesellschaft: Essen und Koeln
Eingetragen beim Amtsgericht Essen
Handelsregister-Nr. HRB 17420
Eingetragen beim Amtsgericht Koeln
Handelsregister-Nr. HRB 117

[[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-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] question on sqldf syntax

2010-01-26 Thread Christian Schulz
Maybe that's a problem with the  RSQLite package , probably detaching 
the package help.

detach(package:RSQLite)

HTH, Christian



trying to structure sql to merge two datasets. structure follows:

dbs.possible.combos (all possible combinations of dates and places)
Date Place
1/1/10 N-01
1/1/10 S-02
1/2/10 N-01
1/2/10 S-02
etc...

dbs.aggregate (the raw data aggregated by date and location)
Date Place Days
1/1/10 N-01 6
1/1/10 S-02 10
1/2/10 S-02 5


Trying to merge so I look-up the values for each possible combo 
dbs.final - sqldf(select dbs.possible.combos$Date,

dbs.possible.combos$Place, dbs.possible.combos$Days FROM dbs.possible.combos
LEFT JOIN dbs.aggregate ON (dbs.possible.combos$Place = dbs.aggregate$Place)
AND (dbs.possible.combos$Date = dbs.aggregate$Date))

Resulting in: 
Error in sqliteExecStatement(con, statement, bind.data) : 
  RS-DBI driver: (error in statement: near .: syntax error)


What am I getting wrong in the syntax?
  







__
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] R Output and ArcGIS

2010-01-26 Thread Steve Murray

Dear all,

Thanks for the replies so far.

Just to emphasise, I'm not using Excel in any way. I have many many files to 
output, so it'd take considerable time to export from R, reprocess in Excel, 
then load into Arc! On a PC I'm able to go directly from R to ArcMap (9.3) 
without having to go via Excel. I've simply been viewing the data in Notepad, 
which was fine for observing the removal of the end-of-line characters and 
general format of the data (3 columns).

My data are structured as follows:

 str(mrunoff)
'data.frame':    61538 obs. of  3 variables:
 $ Latitude : chr  5.75 6.25 6.75 7.25 ...
 $ Longitude: Factor w/ 720 levels 0.25,0.75,..: 1 1 1 1 1 1 1 1 1 1 ...
 $ Runoff   : num  0.687 2.661 0 0 0 ...

I can't use col.names=NA, as I do have column names! These are also required by 
Arc as identifiers. Also, as you can see, there are no complications in the 
variable names which, as you rightly say, can cause problems in Arc.

If anyone has any further suggestions regarding how to overcome this problem of 
generating data from R on a Mac for input to ArcGIS on a PC, then I'd be very 
grateful to hear them.

Many thanks again,

Steve


  
_
Got a cool Hotmail story? Tell us now

__
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] StructTS hang?

2010-01-26 Thread Richard.Kiefer
No problem!

Working:
z-ts(sin(1:1000), start=1, freq=10)
x-StructTS(z, type='BSM')
Hang:
z-ts(sin(1:1000), start=1, freq=100)
x-StructTS(z, type='BSM')
(Both on WinXP, R 2.9.2)

I don't, however, know who the package maintainer is, nor can I track down 
where exactly the hang is caused.

Maybe somebody else can help me with that.

Cheers,
Richard Kiefer


-Ursprüngliche Nachricht-
Von: Uwe Ligges [mailto:lig...@statistik.tu-dortmund.de]
Gesendet: Dienstag, 26. Januar 2010 10:32
An: Kiefer, Richard
Cc: r-help@r-project.org
Betreff: Re: [R] StructTS hang?



On 25.01.2010 11:03, richard.kie...@rwe.com wrote:
 Hi!

 You have probably sorted out your problem a different way.
 However I have tried dealing with the same problem for a while and writing 
 down the reason for this here may be of use to someone.

 In some other help-mail I read that time series objects behave unexpectedly 
 in some situations if the frequency is too high. As a result of this, a call 
 of StructTS (with seasonality) hangs if and only if the frequency is larger 
 than 24 (if I remember the number right). This is what I found with my own 
 time series using several frequencies.

 So, this may not be helpful using StructTS on a time series, but it may save 
 somebody some time.


Even better: report a reproducible example to the package maintainer who
is certainly happy to fix bugs in the package.

Best wishes,
Uwe Ligges


 Regards,
 Richard




 
 Irgendwann kommt jeder drauf! WWW.ENERGIEWELT.DE
 ---
 Vorsitzender des Aufsichtsrates: Dr. Rolf Martin Schmitz
 Vorstand: Dr. Johannes Lambertz (Vorsitzender),
 Prof. Dr. Gerd Jaeger, Antonius Voss,
 Erwin Winkel

 Sitz der Gesellschaft: Essen und Koeln
 Eingetragen beim Amtsgericht Essen
 Handelsregister-Nr. HRB 17420
 Eingetragen beim Amtsgericht Koeln
 Handelsregister-Nr. HRB 117

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


Irgendwann kommt jeder drauf! WWW.ENERGIEWELT.DE
---
Vorsitzender des Aufsichtsrates: Dr. Rolf Martin Schmitz
Vorstand: Dr. Johannes Lambertz (Vorsitzender), 
Prof. Dr. Gerd Jaeger, Antonius Voss, 
Erwin Winkel

Sitz der Gesellschaft: Essen und Koeln
Eingetragen beim Amtsgericht Essen
Handelsregister-Nr. HRB 17420
Eingetragen beim Amtsgericht Koeln
Handelsregister-Nr. HRB 117

__
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] Same y-axis on multiple plots?

2010-01-26 Thread Jim Lemon

On 01/26/2010 01:52 AM, Andreas Bergstrøm wrote:

Greetings,

I am attempting to use R throug PL/R in PostgreSQL to make several graphs (they 
show usage over time for radiochannels).

However, as some never go above 100 in a 24 hour period, and others go well 
over 500, they get different y-axis values (which normally would be a good 
thing). However, as I want to overlay the graphs to add/remove channels in CSS 
on a webpage, I need a set y-axis.

I have looked through the documentation, google and the mailinglist as ylim, 
setting xpd=F and modifying clip, plot.window, but I can't seem to find what I 
am looking for. I am certain that it is something simple, and would be 
gratefull if someone could point me in the right direction.


Hi Andreas,
I didn't see an answer to your question, so I'll suggest that you take 
these warnings seriously:


Warning messages:
1: In plot.window(...) : ylim.max is not a graphical parameter
2: In plot.xy(xy, type, ...) : ylim.max is not a graphical parameter
3: In title(...) : ylim.max is not a graphical parameter

and try this:

plot(str,type=b,main=mymain,xlab=myxlab,ylab=myylab,lwd=2,
 axes=F,ylim=c(0,600))

as the plot command.

Jim

__
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] [Fwd: Re: question on sqldf syntax]

2010-01-26 Thread Christian Schulz
Sorry mistake from me. This was another problem in my mind , but with 
RMySQL.

Christian

 library(RMySQL)
 library(sqldf)
 sqldf(Select * from mtcars)
Fehler in mysqlNewConnection(drv, ...) :
 RS-DBI driver: (Failed to connect to database: Error: Access denied 
for user 'user'@'localhost' (using password: NO)

)
Fehler in if (dbname == :memory:) dbDisconnect(connection) else if 
(!dbPreExists   :

 Argument hat Länge 0
 detach(package:RMySQL)
 sqldf(Select * from mtcars)
   mpg cyl  disp  hp dratwt  qsec vs am gear carb
1  21.0   6 160.0 110 3.90 2.620 16.46  0  144
2  21.0   6 160.0 110 3.90 2.875 17.02  0  144
3  22.8   4 108.0  93 3.85 2.320 18.61  1  141
4  21.4   6 258.0 110 3.08 3.215 19.44  1  031
5  18.7   8 360.0 175 3.15 3.440 17.02  0  032
.
---BeginMessage---
Maybe that's a problem with the  RSQLite package , probably detaching 
the package help.

detach(package:RSQLite)

HTH, Christian



trying to structure sql to merge two datasets. structure follows:

dbs.possible.combos (all possible combinations of dates and places)
Date Place
1/1/10 N-01
1/1/10 S-02
1/2/10 N-01
1/2/10 S-02
etc...

dbs.aggregate (the raw data aggregated by date and location)
Date Place Days
1/1/10 N-01 6
1/1/10 S-02 10
1/2/10 S-02 5


Trying to merge so I look-up the values for each possible combo 
dbs.final - sqldf(select dbs.possible.combos$Date,

dbs.possible.combos$Place, dbs.possible.combos$Days FROM dbs.possible.combos
LEFT JOIN dbs.aggregate ON (dbs.possible.combos$Place = dbs.aggregate$Place)
AND (dbs.possible.combos$Date = dbs.aggregate$Date))

Resulting in: 
Error in sqliteExecStatement(con, statement, bind.data) : 
  RS-DBI driver: (error in statement: near .: syntax error)


What am I getting wrong in the syntax?
  




  



---End Message---
__
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] StructTS hang?

2010-01-26 Thread Uwe Ligges



On 26.01.2010 10:55, richard.kie...@rwe.com wrote:

No problem!

Working:
z-ts(sin(1:1000), start=1, freq=10)
x-StructTS(z, type='BSM')
Hang:
z-ts(sin(1:1000), start=1, freq=100)
x-StructTS(z, type='BSM')
(Both on WinXP, R 2.9.2)

I don't, however, know who the package maintainer is, nor can I track down 
where exactly the hang is caused.

Maybe somebody else can help me with that.



Apologies, thought that code was from a contributed package rather than 
from the base distribution of R.

In this case, and given the code, we should try to debug a little bit.

My first impression is that it will take some time given experiments 
with smaller numbers it looks roughly exponential in runtime. I'll be 
off for a meeting now and will look at results in 1-2 hours (when I 
expect them to appear on my machine).


Uwe Ligges





Cheers,
Richard Kiefer


-Ursprüngliche Nachricht-
Von: Uwe Ligges [mailto:lig...@statistik.tu-dortmund.de]
Gesendet: Dienstag, 26. Januar 2010 10:32
An: Kiefer, Richard
Cc: r-help@r-project.org
Betreff: Re: [R] StructTS hang?



On 25.01.2010 11:03, richard.kie...@rwe.com wrote:

Hi!

You have probably sorted out your problem a different way.
However I have tried dealing with the same problem for a while and writing down 
the reason for this here may be of use to someone.

In some other help-mail I read that time series objects behave unexpectedly in 
some situations if the frequency is too high. As a result of this, a call of 
StructTS (with seasonality) hangs if and only if the frequency is larger than 
24 (if I remember the number right). This is what I found with my own time 
series using several frequencies.

So, this may not be helpful using StructTS on a time series, but it may save 
somebody some time.



Even better: report a reproducible example to the package maintainer who
is certainly happy to fix bugs in the package.

Best wishes,
Uwe Ligges



Regards,
Richard





Irgendwann kommt jeder drauf! WWW.ENERGIEWELT.DE
---
Vorsitzender des Aufsichtsrates: Dr. Rolf Martin Schmitz
Vorstand: Dr. Johannes Lambertz (Vorsitzender),
Prof. Dr. Gerd Jaeger, Antonius Voss,
Erwin Winkel

Sitz der Gesellschaft: Essen und Koeln
Eingetragen beim Amtsgericht Essen
Handelsregister-Nr. HRB 17420
Eingetragen beim Amtsgericht Koeln
Handelsregister-Nr. HRB 117

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



Irgendwann kommt jeder drauf! WWW.ENERGIEWELT.DE
---
Vorsitzender des Aufsichtsrates: Dr. Rolf Martin Schmitz
Vorstand: Dr. Johannes Lambertz (Vorsitzender),
Prof. Dr. Gerd Jaeger, Antonius Voss,
Erwin Winkel

Sitz der Gesellschaft: Essen und Koeln
Eingetragen beim Amtsgericht Essen
Handelsregister-Nr. HRB 17420
Eingetragen beim Amtsgericht Koeln
Handelsregister-Nr. HRB 117



__
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] R Output and ArcGIS

2010-01-26 Thread Rainer M Krug
On Tue, Jan 26, 2010 at 11:42 AM, Steve Murray smurray...@hotmail.comwrote:


 Dear all,

 Thanks for the replies so far.

 Just to emphasise, I'm not using Excel in any way. I have many many files
 to output, so it'd take considerable time to export from R, reprocess in
 Excel, then load into Arc! On a PC I'm able to go directly from R to ArcMap
 (9.3) without having to go via Excel. I've simply been viewing the data in
 Notepad, which was fine for observing the removal of the end-of-line
 characters and general format of the data (3 columns).

 My data are structured as follows:

  str(mrunoff)
 'data.frame':61538 obs. of  3 variables:
  $ Latitude : chr  5.75 6.25 6.75 7.25 ...
  $ Longitude: Factor w/ 720 levels 0.25,0.75,..: 1 1 1 1 1 1 1 1 1 1
 ...
  $ Runoff   : num  0.687 2.661 0 0 0 ...


what about changing the class from Longitude and Latitude to numeric? This
could probably solve the problem?




 I can't use col.names=NA, as I do have column names! These are also
 required by Arc as identifiers. Also, as you can see, there are no
 complications in the variable names which, as you rightly say, can cause
 problems in Arc.

 If anyone has any further suggestions regarding how to overcome this
 problem of generating data from R on a Mac for input to ArcGIS on a PC, then
 I'd be very grateful to hear them.


In addition, as far as I know, Arc can read dbf and from R, you can export
to dbf, via the package foreign - might be worth a try.

Cheers,

Rainer


 Many thanks again,

 Steve



 _
 Got a cool Hotmail story? Tell us now

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




-- 
NEW GERMAN FAX NUMBER!!!

Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation Biology,
UCT), Dipl. Phys. (Germany)

Centre of Excellence for Invasion Biology
Natural Sciences Building
Office Suite 2039
Stellenbosch University
Main Campus, Merriman Avenue
Stellenbosch
South Africa

Cell:   +27 - (0)83 9479 042
Fax:+27 - (0)86 516 2782
Fax:+49 - (0)321 2125 2244
email:  rai...@krugs.de

Skype:  RMkrug
Google: r.m.k...@gmail.com

[[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] Data Manipulation

2010-01-26 Thread Peter Rote

I still struggling with this:

 error massage:

  by(AlexETF,AlexETF$Industry,function(a) {filename = paste(C:/ab/,gsub(
 ,,a$Industry[1]),.txt,sep=)
+ print(filename)
+ write.table(a[,3,drop=FALSE],quote=FALSE,col.names=FALSE,row.names=FALSE)
+ }
+  )  

[1] C:/ab/AccidentHealthInsurance.txt
Error in `[.data.frame`(a, , 3, drop = FALSE) :
  undefined columns selected

Best,
Peter 
-- 
View this message in context: 
http://n4.nabble.com/Data-Manipulation-tp1018249p1290191.html
Sent from the R help mailing list archive at Nabble.com.

__
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] Same y-axis on multiple plots?

2010-01-26 Thread Andreas Bergstrøm

On 26. jan. 2010, at 11:07, Jim Lemon wrote:

 On 01/26/2010 01:52 AM, Andreas Bergstrøm wrote:
 Hi Andreas,
 I didn't see an answer to your question, so I'll suggest that you take these 
 warnings seriously:
 
 Warning messages:
 1: In plot.window(...) : ylim.max is not a graphical parameter
 2: In plot.xy(xy, type, ...) : ylim.max is not a graphical parameter
 3: In title(...) : ylim.max is not a graphical parameter
 
 and try this:
 
 plot(str,type=b,main=mymain,xlab=myxlab,ylab=myylab,lwd=2,
 axes=F,ylim=c(0,600))


Thank you. I got two replies offlist where the gist was the same as your reply, 
and it now works.
I see now that I don't get those warnings when I run R though pl/R in 
postgresql, so I'll try running it through the R binary next time I am stuck.

Thank you for your assistance.

--
Andreas Bergstrøm
Østfold University College
Dept. of Computer Sciences
Tel: +47 69 21 53 71
http://media.hiof.no/

__
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] R-forge getting the wrong package

2010-01-26 Thread Barry Rowlingson
On Sun, Jan 24, 2010 at 10:09 AM, Barry Rowlingson
b.rowling...@lancaster.ac.uk wrote:
 After accusing someone of typing 'install.packages(weather)' instead
 of 'install.packages(webmaps)', I discovered that R-forge really is
 currently returning the wrong source tarball for packages after
 'Repitools' in the alphabet.

  I'm hypothesizing it's in the way the PACKAGES file is being
 constructed, but haven't tested that hypothesis yet - I'm sure the
 R-forge admins will fix this.

Stefan Theussl has now fixed this, so if anyone wants to try
install.packages(webmaps,repos=http://R-Forge.R-project.org;) they
now can, without getting the 'weather' package installed instead.

Barry

__
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] Data Manipulation

2010-01-26 Thread Peter Dalgaard
Peter Rote wrote:
 I still struggling with this:
 
  error massage:
 
  by(AlexETF,AlexETF$Industry,function(a) {filename = paste(C:/ab/,gsub(
 ,,a$Industry[1]),.txt,sep=)
 + print(filename)
 + write.table(a[,3,drop=FALSE],quote=FALSE,col.names=FALSE,row.names=FALSE)   
  
 + }
 +  )  
 
 [1] C:/ab/AccidentHealthInsurance.txt
 Error in `[.data.frame`(a, , 3, drop = FALSE) :
   undefined columns selected

The message says that you haven't got three columns in a, so try
inserting print(dim(a)). Perhaps what you showed earlier was rownames
plus two columns?

-- 
   O__   Peter Dalgaard Øster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark  Ph:  (+45) 35327918
~~ - (p.dalga...@biostat.ku.dk)  FAX: (+45) 35327907

__
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] Data Manipulation

2010-01-26 Thread Jim Lemon

On 01/26/2010 09:15 PM, Peter Rote wrote:


I still struggling with this:

  error massage:


  by(AlexETF,AlexETF$Industry,function(a) {filename = paste(C:/ab/,gsub(
,,a$Industry[1]),.txt,sep=)

+ print(filename)
+ write.table(a[,3,drop=FALSE],quote=FALSE,col.names=FALSE,row.names=FALSE)
+ }
+  )

[1] C:/ab/AccidentHealthInsurance.txt
Error in `[.data.frame`(a, , 3, drop = FALSE) :
   undefined columns selected


Hi Peter,
I would suggest that you print the first say 10 rows of a and see if 
it has three columns.


Jim

__
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] Two == expressions in bquote

2010-01-26 Thread Henrique Dallazuanna
You are rigth Bert.

Thanks for the clarification.

On Mon, Jan 25, 2010 at 7:00 PM, Bert Gunter gunter.ber...@gene.com wrote:
 I think that careful examination will show that Henrique's solution is not
 quite right: the text '=' character is slightly different than the symbol
 font character. This is admittedly nitpicking, but ...

 try instead:

 text(2,8,bquote(paste(delta==mu^2,phantom()==.(mu^2

 Cheers,

 Bert Gunter
 Genentech Nonclinical Biostatistics


 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On
 Behalf Of Henrique Dallazuanna
 Sent: Monday, January 25, 2010 12:10 PM
 To: Larry Hotchkiss
 Cc: r-help@r-project.org
 Subject: Re: [R] Two == expressions in bquote

 Try this:

 text(2,8, bquote(delta~'='~mu^2 == .(mu^2)))

 On Mon, Jan 25, 2010 at 6:00 PM, Larry Hotchkiss lar...@udel.edu wrote:
 Hi,

 I want to put text on a plot containing something like: a = b^2 = squared
 numeric value of b using bquote.

 Example:

  mu = 5
  plot(1:10,1:10)
  text(2,8, bquote(delta == mu^2))            # This works
  text(2.5,8, bquote(phantom(0) == .(mu^2)))  # but is unpredictable

  text(2,8, bquote(delta == mu^2 == .(mu^2))) # This doesn't work

 The last text function returns the error:

     Error: unexpected '==' in   text(2,8, bquote(delta == mu^2 ==

 The first two text functions work in this example, using a default
 graphics window on a 64-bit Windows machine, and either R 2.11.0 development
 edition for 64-bit Windows or R 9.2.2 on the same machine ((x 86)).

 I don't mind the two statements except that when trying to automate this
 by using the base x coordinate + epsilon*max(x), for example --

  x - 1:10
  epsilon=0.05
  text(2+esilon*max(x),8, bquote(phantom(0) == .(mu^2)))

 for the x position on the 2nd text function, the position of the
 additional text is not predictable.

 Thanks,

 Larry Hotchkiss

 __
 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

 __
 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

__
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] StructTS hang?

2010-01-26 Thread Richard.Kiefer
Exponential, you say?

Maybe I am just not patient enough.
After being unresponsive for several minutes, which in the larger examples that 
I work with has probably appeared like a hang, the code I just mentioned has 
given a result (a convergence error, but still).
So, I must say I can no longer reproduce the hang.

I remember to be able to reproduce a significant change in behaviour upon the 
frequency passing some threshold. Maybe by chance, this threshold parting 
hang from normal operation agreed with a number someone claimed ts-objects 
could not handle properly.
But I can't reproduce this now. I'm sorry...



-Ursprüngliche Nachricht-
Von: Uwe Ligges [mailto:lig...@statistik.tu-dortmund.de]
Gesendet: Dienstag, 26. Januar 2010 11:15
An: Kiefer, Richard
Cc: r-help@r-project.org
Betreff: Re: AW: [R] StructTS hang?



On 26.01.2010 10:55, richard.kie...@rwe.com wrote:
 No problem!

 Working:
 z-ts(sin(1:1000), start=1, freq=10)
 x-StructTS(z, type='BSM')
 Hang:
 z-ts(sin(1:1000), start=1, freq=100)
 x-StructTS(z, type='BSM')
 (Both on WinXP, R 2.9.2)

 I don't, however, know who the package maintainer is, nor can I track down 
 where exactly the hang is caused.

 Maybe somebody else can help me with that.


Apologies, thought that code was from a contributed package rather than
from the base distribution of R.
In this case, and given the code, we should try to debug a little bit.

My first impression is that it will take some time given experiments
with smaller numbers it looks roughly exponential in runtime. I'll be
off for a meeting now and will look at results in 1-2 hours (when I
expect them to appear on my machine).

Uwe Ligges




 Cheers,
 Richard Kiefer


 -Ursprüngliche Nachricht-
 Von: Uwe Ligges [mailto:lig...@statistik.tu-dortmund.de]
 Gesendet: Dienstag, 26. Januar 2010 10:32
 An: Kiefer, Richard
 Cc: r-help@r-project.org
 Betreff: Re: [R] StructTS hang?



 On 25.01.2010 11:03, richard.kie...@rwe.com wrote:
 Hi!

 You have probably sorted out your problem a different way.
 However I have tried dealing with the same problem for a while and writing 
 down the reason for this here may be of use to someone.

 In some other help-mail I read that time series objects behave unexpectedly 
 in some situations if the frequency is too high. As a result of this, a call 
 of StructTS (with seasonality) hangs if and only if the frequency is larger 
 than 24 (if I remember the number right). This is what I found with my own 
 time series using several frequencies.

 So, this may not be helpful using StructTS on a time series, but it may save 
 somebody some time.


 Even better: report a reproducible example to the package maintainer who
 is certainly happy to fix bugs in the package.

 Best wishes,
 Uwe Ligges


 Regards,
 Richard




Irgendwann kommt jeder drauf! WWW.ENERGIEWELT.DE
---
Vorsitzender des Aufsichtsrates: Dr. Rolf Martin Schmitz
Vorstand: Dr. Johannes Lambertz (Vorsitzender), 
Prof. Dr. Gerd Jaeger, Antonius Voss, 
Erwin Winkel

Sitz der Gesellschaft: Essen und Koeln
Eingetragen beim Amtsgericht Essen
Handelsregister-Nr. HRB 17420
Eingetragen beim Amtsgericht Koeln
Handelsregister-Nr. HRB 117

__
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] AIC for comparing GLM(M) with (GAM(M)

2010-01-26 Thread Andrea Meyer
Hello

I'm analyzing a dichotomous dependent variable (dv) with more than 100  
measurements (within-subjects variable: hours24) per subject and more  
than 100 subjects. The high number of measurements allows me to model  
more complex temporal trends.
I would like to compare different models using GLM, GLMM, GAM and  
GAMM, basically do demonstrate the added value of GAMs/GAMMs relative  
to GLMs/GLMMs, by fitting splines. GLMMs/GAMMs are used to possibly  
improve fits from GLMs/GAMs by accounting for serial dependence.
My idea is to use AIC to compare the different models. I’ve noticed  
that when setting up two seemingly identical models using the two  
functions gam (of the package mgcv) and gamm4 (of the package with  
same name), the AIC turns out to be different:

  gam.0-gam(dv ~  
s(hours24,fx=F,k=-1,bs=“cc“),method=ML,data=sdata, family=binomial)

  gamm.0-gamm4(dv ~  
s(hours24,fx=F,k=-1,bs=“cc“),method=ML,data=sdata, family=binomial)

Fit indices using the commands as shown are:
  logLik(gam.0)[1];deviance(gam.0);AIC(gam.0)
  logLik(gamm.0$mer);deviance(gamm.0$mer);attributes(summary(gamm. 
0$mer))$AICtab[1]

gam.0: logLik=1149.6, deviance=2299.3, AIC=2316.0
gamm.0: logLik=1169.0, deviance=2338.0, AIC=2342.0

The differences between the two AIC values seem to be based on two  
factors. First, gam uses the effective degrees of freedom
  sum(gam.0$edf)
[1] 8.372517
whereas gamm4 uses the value 2. Second the two log-likelihood values  
already differ, probably because different estimation methods are used  
but here is were my understanding ends. In any case from gamm4 I can  
get the same value for the deviance as for gam by referring to the  
deviance slot:

  gamm.0$...@deviance[disc], which returns the value 2299.3, which  
is the deviance without compensation for the null deviance.

My questions are:
- Is my suggested method of comparing fits among GLM, GLMM, GAM and  
GAMM using AIC legitimate? Of course I will do additional model  
plotting using residuals etc. as well but it seems important to me to  
have a more direct method of comparing these models (I’m aware of the  
fact that AIC is a rough estimate when it comes to generalized mixed  
models).
- If so, how can I compute the AICs using gam and gamm4 such that they  
can be compared A) with each other and B) with AICs obtained from GLM/ 
GLMM?

Any suggestions are welcome

Andrea









[[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] Formatting cgroup and factor level labels in Hmisc latex function

2010-01-26 Thread Stefan Petersson

I'm trying to typeset at simple crosstable with the Hmisc latex function. And I 
have two problems.

1. How do I make all columns the same width? The Latex function seems very 
unwilling to break the 'cgroup' labels and the factor level labels. Please have 
look at this screenshot that shows my problem:

  http://hem.passagen.se/stpe9096/table.png

So, how can I make sure that the cgroup labels and the factor level labels are 
sufficiently line breaked and/or hyphenated to make the columns evenly spaced?

2. Is there something like a 'widetable' package that can break a wide table 
into several tables with repeated 'rgroup' labels? As You can see in the 
screenshot, the table runs way off the page. And I know that there is a 
'longtable' package that can do exactly this, but for tables with long rgroup 
lists.

__
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] StructTS hang?

2010-01-26 Thread Uwe Ligges



On 26.01.2010 11:52, richard.kie...@rwe.com wrote:

Exponential, you say?

Maybe I am just not patient enough.
After being unresponsive for several minutes, which in the larger examples that 
I work with has probably appeared like a hang, the code I just mentioned has 
given a result (a convergence error, but still).
So, I must say I can no longer reproduce the hang.

I remember to be able to reproduce a significant change in behaviour upon the frequency 
passing some threshold. Maybe by chance, this threshold parting hang from 
normal operation agreed with a number someone claimed ts-objects could not handle 
properly.
But I can't reproduce this now. I'm sorry...



Right, your example takes roughly 30 minutes on my machine.

Uwe





-Ursprüngliche Nachricht-
Von: Uwe Ligges [mailto:lig...@statistik.tu-dortmund.de]
Gesendet: Dienstag, 26. Januar 2010 11:15
An: Kiefer, Richard
Cc: r-help@r-project.org
Betreff: Re: AW: [R] StructTS hang?



On 26.01.2010 10:55, richard.kie...@rwe.com wrote:

No problem!

Working:
z-ts(sin(1:1000), start=1, freq=10)
x-StructTS(z, type='BSM')
Hang:
z-ts(sin(1:1000), start=1, freq=100)
x-StructTS(z, type='BSM')
(Both on WinXP, R 2.9.2)

I don't, however, know who the package maintainer is, nor can I track down 
where exactly the hang is caused.

Maybe somebody else can help me with that.



Apologies, thought that code was from a contributed package rather than
from the base distribution of R.
In this case, and given the code, we should try to debug a little bit.

My first impression is that it will take some time given experiments
with smaller numbers it looks roughly exponential in runtime. I'll be
off for a meeting now and will look at results in 1-2 hours (when I
expect them to appear on my machine).

Uwe Ligges





Cheers,
Richard Kiefer


-Ursprüngliche Nachricht-
Von: Uwe Ligges [mailto:lig...@statistik.tu-dortmund.de]
Gesendet: Dienstag, 26. Januar 2010 10:32
An: Kiefer, Richard
Cc: r-help@r-project.org
Betreff: Re: [R] StructTS hang?



On 25.01.2010 11:03, richard.kie...@rwe.com wrote:

Hi!

You have probably sorted out your problem a different way.
However I have tried dealing with the same problem for a while and writing down 
the reason for this here may be of use to someone.

In some other help-mail I read that time series objects behave unexpectedly in 
some situations if the frequency is too high. As a result of this, a call of 
StructTS (with seasonality) hangs if and only if the frequency is larger than 
24 (if I remember the number right). This is what I found with my own time 
series using several frequencies.

So, this may not be helpful using StructTS on a time series, but it may save 
somebody some time.



Even better: report a reproducible example to the package maintainer who
is certainly happy to fix bugs in the package.

Best wishes,
Uwe Ligges



Regards,
Richard





Irgendwann kommt jeder drauf! WWW.ENERGIEWELT.DE
---
Vorsitzender des Aufsichtsrates: Dr. Rolf Martin Schmitz
Vorstand: Dr. Johannes Lambertz (Vorsitzender),
Prof. Dr. Gerd Jaeger, Antonius Voss,
Erwin Winkel

Sitz der Gesellschaft: Essen und Koeln
Eingetragen beim Amtsgericht Essen
Handelsregister-Nr. HRB 17420
Eingetragen beim Amtsgericht Koeln
Handelsregister-Nr. HRB 117



__
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] R Output and ArcGIS

2010-01-26 Thread Corey Sparks

Yes, R thinks the coordinates are characters, that needs to change.  Also,
alternatively you could use the write .dbf function in the foreign()
library, ArcGis likes dbf files (just no long names)
Corey


-
Corey Sparks, PhD
Assistant Professor
Department of Demography and Organization Studies
University of Texas at San Antonio
501 West Durango Blvd
Monterey Building 2.270C
San Antonio, TX 78207
210-458-3166
corey.sparks 'at' utsa.edu
https://rowdyspace.utsa.edu/users/ozd504/www/index.htm
-- 
View this message in context: 
http://n4.nabble.com/R-Output-and-ArcGIS-tp1289606p1290310.html
Sent from the R help mailing list archive at Nabble.com.

__
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] Error with toString

2010-01-26 Thread anna

Hello there, I want to create a string from strings and numbers, here is my
code:
str - name  toString(20)
but it returns me this error: 
Error in toString(20) : could not find function .jcall
what did I do wrong? I couldn't find this error anywhere...
-- 
View this message in context: 
http://n4.nabble.com/Error-with-toString-tp1290327p1290327.html
Sent from the R help mailing list archive at Nabble.com.

__
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] R Output and ArcGIS

2010-01-26 Thread Steve Murray

Dear all,

Just to let you know that thanks to your help, I've managed to solve it.

For future reference, if anyone's interested (!), if you're having problems 
reading R-generated data from a Mac, into ArcMap on a PC, then ensure that 
you're using eol=\r\n in the write.table command and that you don't have 
factor or character data when they're really meant to be numeric! To overcome 
the latter, I did:

mrunoff$Longitude - as.numeric(levels(mrunoff$Longitude))[mrunoff$Longitude]

Hope this is of use to someone, somewhere, someday!

Thanks again for your advice,

Steve

  
_
Got a cool Hotmail story? Tell us now

__
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] Formatting cgroup and factor level labels in Hmisc latex function

2010-01-26 Thread Ista Zahn
Hi Stefan,
See comments in line below.

On Tue, Jan 26, 2010 at 6:21 AM, Stefan Petersson
stefan.peters...@inizio.se wrote:

 I'm trying to typeset at simple crosstable with the Hmisc latex function. And 
 I have two problems.

 1. How do I make all columns the same width?

Use cgroup.just=p{widthunit} For example, for column groups 2
inches wide, use cgroup.just=p{2in}

The Latex function seems very unwilling to break the 'cgroup' labels
and the factor level labels. Please have look at this screenshot that
shows my problem:

The latex() function will do whatever you tell it to...


   http://hem.passagen.se/stpe9096/table.png

 So, how can I make sure that the cgroup labels and the factor level labels 
 are sufficiently line breaked and/or hyphenated to make the columns evenly 
 spaced?

 2. Is there something like a 'widetable' package that can break a wide table 
 into several tables with repeated 'rgroup' labels? As You can see in the 
 screenshot, the table runs way off the page. And I know that there is a 
 'longtable' package that can do exactly this, but for tables with long rgroup 
 lists.

I would stick with long table. Use R to re-organize you data so that
it is long instead of wide, and use longtable.

HTH,
Ista


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




-- 
Ista Zahn
Graduate student
University of Rochester
Department of Clinical and Social Psychology
http://yourpsyche.org

__
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] Graph color

2010-01-26 Thread Jose Narillos de Santos
Hi all I want to apply different colors on a simple plot:

If I type par(br=gray) before a plot it puts all the image in gray but
(imagine I run a simple plot) want to let the centrall box (where the dots
are plotted) in white or image in lightblue.

Can anyone guide me to apply this second step (make the box where the series
are plotted in different colours).

Thanks in advance.

[[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] Error with toString

2010-01-26 Thread Romain Francois

On 01/26/2010 03:09 PM, anna wrote:

Hello there, I want to create a string from strings and numbers, here is my
code:
str- name  toString(20)


Where did you get that syntax from ? You need to use paste.

 paste( name, 20 )
[1] name 20


but it returns me this error:
Error in toString(20) : could not find function .jcall
what did I do wrong? I couldn't find this error anywhere...


.jcall is in rJava, but rJava never calls toString. Can you attach a bit 
more information as requested by the posting guide :

http://www.r-project.org/posting-guide.html

Romain

--
Romain Francois
Professional R Enthusiast
+33(0) 6 28 91 30 30
http://romainfrancois.blog.free.fr
|- http://tr.im/KfKn : Rcpp 0.7.2
|- http://tr.im/JOlc : External pointers with Rcpp
`- http://tr.im/JFqa : R Journal, Volume 1/2, December 2009

__
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] update.packages on MS Windows with //server/share paths

2010-01-26 Thread Keith Jewell
Hi,

 update.packages(ask='graphics')

  gives me  multiple warning (one per updated package?) similar to ...

Warning: unable to move temporary installation 
'\\Server02\stats\R\library\2.10\file3de56e0d\locfit' to 
'\\Server02\stats\R\library\2.10\locfit'

The final, updated, folders do not end up where they should be. I can move 
them 'by hand', but it is an inconvenience.

Checking the archives I find 
http://finzi.psych.upenn.edu/Rhelp08/2008-April/160963.html where Prof 
Ripley opines The issue appears to be that your OS is garbling file names, 
and it surely does seem to be a filename problem - in combination R and 
Windows don't seem to be handling the '//server/share' path construction. I 
have:
 .libPaths()
[1] //Server02/stats/R/library/2.10 
//Server02/stats/R/R-Current/library

I can work around by mapping a drive letter to the '//server/share', but 
prefer not to (for local reasons).

In CHANGES.R-2.10.1pat I find
  CHANGES IN R VERSION 2.7.2 patched
o dir.create(recursive = TRUE) was not working on //server/share  paths.

In CHANGES.R-2.11.0dev I find
  CHANGES IN R VERSION 2.11.0
NEW FEATURES
o file.rename() can work across volumes (by copy-and-delete)

In another R function I've hit a similar problem and solved it using the 
construction:
  file.path(dirname(x), basename(x))
to convert  '//server/share' to (printed as) 'server/share' which worked 
in that function. In this case:
 file.path(dirname(.libPaths()), basename(.libPaths()))
[1] Server02/stats/R/library/2.10 
Server02/stats/R/R-Current/library
which looks OK but
 .libPaths(file.path(dirname(.libPaths()), basename(.libPaths(
 .libPaths()
[1] //Server02/stats/R/library/2.10 
//Server02/stats/R/R-Current/library
doesn't actually change the internal paths.

I don't see the problem in V2.9.2 .
I do see the problem in
   V2.10.1,
   V2.10.1 Patched (2010-01-24 r51030)
   V2.11.0 Under development (unstable) (2010-01-24 r51030)

Grateful for any suggestions,

Keith Jewell
-
Version:
 platform = i386-pc-mingw32
 arch = i386
 os = mingw32
 system = i386, mingw32
 status = Patched
 major = 2
 minor = 10.1
 year = 2010
 month = 01
 day = 24
 svn rev = 51030
 language = R
 version.string = R version 2.10.1 Patched (2010-01-24 r51030)

Windows Server 2003 x64 (build 3790) Service Pack 2

Locale:
LC_COLLATE=English_United Kingdom.1252;LC_CTYPE=English_United 
Kingdom.1252;LC_MONETARY=English_United 
Kingdom.1252;LC_NUMERIC=C;LC_TIME=English_United Kingdom.1252

Search Path:
 .GlobalEnv, package:stats, package:graphics, package:grDevices, 
package:utils, package:datasets, package:methods, Autoloads, package:base

__
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] reading a string vector

2010-01-26 Thread bia.estat

Hi, I need to read a string vector in R which is like this
atgctctaatcgtcccaacaattatattactaccac, but R seems to understand it as
a unique vector input when I read in like x -
atgctctaatcgtcccaacaattatattactaccac. How do I unconcatenate it, so I
can use each of the letters on my reading?

Thanks,
Beatriz
-- 
View this message in context: 
http://n4.nabble.com/reading-a-string-vector-tp1290289p1290289.html
Sent from the R help mailing list archive at Nabble.com.

[[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] create custom function to annotate a levelplot

2010-01-26 Thread Jaime R. Garcia M.
Dear list users,

I modeled the probability of occurrence of one species: Cyperus
dilatatus.

I modeled the species using three different approaches:
c(random,target,index)

What I want to achieve is to make a plot of all prediction maps in a row
with to conditional variables, that is, with the species and the
approach

I prepared a data.frame to try with the 'levelplot' function. Please
find attached a file (levelplot.RData) where I saved the following
objects:

all.df   a data frame with coordinates (s1 and s2), predictions (z),
approach used (name), species name (spname)

var  a numeric vector with the validation value of each model

This is my initial code:

# 
library(lattice);library(RColorBrewer)
load(levelplot.RData)

# gray colors for display
mypalette = brewer.pal(9, Greys)

# plot
levelplot(z ~ s1 + s2 | name * spname, data=df,
col.regions=mypalette, at=c(0,.1,.2,.3,.4,.5,.6,.7,.8,1), layout=c(3,1),
xlab=NULL, ylab=NULL,
scales=list(draw=FALSE))
# -

But now I would like to do some adjustments. For example, I would like
to make the font type of the strip where the species name is italic. So
I tried initially:

#
update(trellis.last.object(),
strip=function(...,style,par.strip.text)
strip.default(...,style=1,par.strip.text = list(cex=.8, font=3)))
#--

But then also the strip with the model approach turns into italic font
type. So I tried to customize my own strip function like this:

#--
mystrip - 
  function(which.given,which.panel,factor.levels,par.strip.text,...){
if (which.given == 1){
  par.strip.text = list(cex=.8, font=3)

panel.text(x=0.1,y=0,pos=3,lab=factor.levels[which.panel[which.given]])
}
if (which.given == 2){
  par.strip.text = list(cex=.6, font=1)
  panel.text(x=0.5, y=0,lab=factor.levels[which.panel[which.given]])
}
  }

update(trellis.last.object(), strip=mystrip)
#

And then everything started going crazy!!!

I would also like to add to each panel, as text, the validation value
for each prediction. So I tried something like this

#-
mypanel = function(x,y,z,subscripts,...){
panel.levelplot(x,y,z,subscripts,...)
ltext(15, 160, labels=paste(AUC =, var[subscripts], sep= ),
cex=.7)}

update(trellis.last.object(), panel=mypanel)
# --

but it displays only the value for the first map, so something is
telling me that the use of subscripts is not good. So I tried also with
which.packet insted of subscripts with no success.

Finally, I would like to make the strip where the name of the species is
to appear as a large unique strip and not three times repeated.

I hope I am making sense of what I want and looking forward for any
help or directions...

Best,

Jaime -R

__
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] Error with toString

2010-01-26 Thread jim holtman
?paste

 is a logical operator, not string concatenation.

On Tue, Jan 26, 2010 at 9:09 AM, anna lippelann...@hotmail.com wrote:

 Hello there, I want to create a string from strings and numbers, here is my
 code:
 str - name  toString(20)
 but it returns me this error:
 Error in toString(20) : could not find function .jcall
 what did I do wrong? I couldn't find this error anywhere...
 --
 View this message in context: 
 http://n4.nabble.com/Error-with-toString-tp1290327p1290327.html
 Sent from the R help mailing list archive at Nabble.com.

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




-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem that you are trying to solve?

__
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] reading a string vector

2010-01-26 Thread Ista Zahn
Like this?
strsplit(atgctctaatcgtcccaacaattatattactaccac, split=)

-Ista

On Tue, Jan 26, 2010 at 8:08 AM, bia.estat bia@live.com wrote:

 Hi, I need to read a string vector in R which is like this
 atgctctaatcgtcccaacaattatattactaccac, but R seems to understand it as
 a unique vector input when I read in like x -
 atgctctaatcgtcccaacaattatattactaccac. How do I unconcatenate it, so I
 can use each of the letters on my reading?

 Thanks,
 Beatriz
 --
 View this message in context: 
 http://n4.nabble.com/reading-a-string-vector-tp1290289p1290289.html
 Sent from the R help mailing list archive at Nabble.com.

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




-- 
Ista Zahn
Graduate student
University of Rochester
Department of Clinical and Social Psychology
http://yourpsyche.org

__
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] reading a string vector

2010-01-26 Thread Romain Francois

On 01/26/2010 02:08 PM, bia.estat wrote:

Hi, I need to read a string vector in R which is like this
atgctctaatcgtcccaacaattatattactaccac, but R seems to understand it as
a unique vector input when I read in like x-
atgctctaatcgtcccaacaattatattactaccac. How do I unconcatenate it, so I
can use each of the letters on my reading?

Thanks,
Beatriz


See ?strsplit

 strsplit( x, )[[1]]

Romain

--
Romain Francois
Professional R Enthusiast
+33(0) 6 28 91 30 30
http://romainfrancois.blog.free.fr
|- http://tr.im/KfKn : Rcpp 0.7.2
|- http://tr.im/JOlc : External pointers with Rcpp
`- http://tr.im/JFqa : R Journal, Volume 1/2, December 2009

__
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] Error with toString

2010-01-26 Thread S Ellison
 name  toString(20)
is from Excel or OpenOffice;  means 'logical and' in R, not string
concatenation.

paste() is simpler; sprintf() is more precise as to decimal places and
format.




 anna lippelann...@hotmail.com 26/01/2010 14:09:15 

Hello there, I want to create a string from strings and numbers, here
is my
code:
str - name  toString(20)
but it returns me this error: 
Error in toString(20) : could not find function .jcall
what did I do wrong? I couldn't find this error anywhere...
-- 

***
This email and any attachments are confidential. Any use...{{dropped:8}}

__
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] Error with toString

2010-01-26 Thread anna

thanks! I thought it was a concatenator like in vb
-- 
View this message in context: 
http://n4.nabble.com/Error-with-toString-tp1290327p1292949.html
Sent from the R help mailing list archive at Nabble.com.

__
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] Error with toString

2010-01-26 Thread anna

Romain, I used the paste for numbers to as you told me and it worked. For the
toString() function well I called it from the R console and that's what it
returned me...
-- 
View this message in context: 
http://n4.nabble.com/Error-with-toString-tp1290327p1293039.html
Sent from the R help mailing list archive at Nabble.com.

__
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] update.packages on MS Windows with //server/share paths

2010-01-26 Thread Gabor Grothendieck
Try mapping a drive letter to \\Server02 and then use that.  For more,
google for: map network drive

On Tue, Jan 26, 2010 at 10:01 AM, Keith Jewell k.jew...@campden.co.uk wrote:
 Hi,

 update.packages(ask='graphics')

  gives me  multiple warning (one per updated package?) similar to ...

 Warning: unable to move temporary installation
 '\\Server02\stats\R\library\2.10\file3de56e0d\locfit' to
 '\\Server02\stats\R\library\2.10\locfit'

 The final, updated, folders do not end up where they should be. I can move
 them 'by hand', but it is an inconvenience.

 Checking the archives I find
 http://finzi.psych.upenn.edu/Rhelp08/2008-April/160963.html where Prof
 Ripley opines The issue appears to be that your OS is garbling file names,
 and it surely does seem to be a filename problem - in combination R and
 Windows don't seem to be handling the '//server/share' path construction. I
 have:
 .libPaths()
 [1] //Server02/stats/R/library/2.10
 //Server02/stats/R/R-Current/library

 I can work around by mapping a drive letter to the '//server/share', but
 prefer not to (for local reasons).

 In CHANGES.R-2.10.1pat I find
  CHANGES IN R VERSION 2.7.2 patched
    o dir.create(recursive = TRUE) was not working on //server/share  paths.

 In CHANGES.R-2.11.0dev I find
      CHANGES IN R VERSION 2.11.0
 NEW FEATURES
    o file.rename() can work across volumes (by copy-and-delete)

 In another R function I've hit a similar problem and solved it using the
 construction:
      file.path(dirname(x), basename(x))
 to convert  '//server/share' to (printed as) 'server/share' which worked
 in that function. In this case:
 file.path(dirname(.libPaths()), basename(.libPaths()))
 [1] Server02/stats/R/library/2.10
 Server02/stats/R/R-Current/library
 which looks OK but
 .libPaths(file.path(dirname(.libPaths()), basename(.libPaths(
 .libPaths()
 [1] //Server02/stats/R/library/2.10
 //Server02/stats/R/R-Current/library
 doesn't actually change the internal paths.

 I don't see the problem in V2.9.2 .
 I do see the problem in
   V2.10.1,
   V2.10.1 Patched (2010-01-24 r51030)
   V2.11.0 Under development (unstable) (2010-01-24 r51030)

 Grateful for any suggestions,

 Keith Jewell
 -
 Version:
  platform = i386-pc-mingw32
  arch = i386
  os = mingw32
  system = i386, mingw32
  status = Patched
  major = 2
  minor = 10.1
  year = 2010
  month = 01
  day = 24
  svn rev = 51030
  language = R
  version.string = R version 2.10.1 Patched (2010-01-24 r51030)

 Windows Server 2003 x64 (build 3790) Service Pack 2

 Locale:
 LC_COLLATE=English_United Kingdom.1252;LC_CTYPE=English_United
 Kingdom.1252;LC_MONETARY=English_United
 Kingdom.1252;LC_NUMERIC=C;LC_TIME=English_United Kingdom.1252

 Search Path:
  .GlobalEnv, package:stats, package:graphics, package:grDevices,
 package:utils, package:datasets, package:methods, Autoloads, package:base

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


Re: [R] Error with toString

2010-01-26 Thread Romain Francois

On 01/26/2010 04:19 PM, anna wrote:

Romain, I used the paste for numbers to as you told me and it worked. For the
toString() function well I called it from the R console and that's what it
returned me...


Yes. I understood that the first time. and I asked you to provide more 
details about your session to help diagnose the problem better. I can 
figure out on my own that you typed it at the console. What I cannot 
figure out is details of your session.


Please read the posting guide, follow it and come back with the details 
if you want someone to help. You might want to read An Introduction to 
R too, because R is nothing like vb.


Romain

--
Romain Francois
Professional R Enthusiast
+33(0) 6 28 91 30 30
http://romainfrancois.blog.free.fr
|- http://tr.im/KfKn : Rcpp 0.7.2
|- http://tr.im/JOlc : External pointers with Rcpp
`- http://tr.im/JFqa : R Journal, Volume 1/2, December 2009

__
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] Large dataset importing, columns merging and splitting

2010-01-26 Thread Manta

Dear All,
I have a large data set that looks like this:

CVX 20070201 9 30 51 73.25 81400 0
CVX 20070201 9 30 51 73.25 100 0
CVX 20070201 9 30 51 73.25 100 0
CVX 20070201 9 30 51 73.25 300 0

First, I would like to import it by merging column 3 4 and 5, since that is
the timestamp. Then, I would like to aggregate the data by splitting them in
bins of 5 minutes size, therefore from 93000 up to 93459 etc, givin as
output the average price and volume in the 5 minutes bin.

Hope this helps,
Best,

Marco
-- 
View this message in context: 
http://n4.nabble.com/Large-dataset-importing-columns-merging-and-splitting-tp1294668p1294668.html
Sent from the R help mailing list archive at Nabble.com.

__
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] hdf files

2010-01-26 Thread karine heerah

hello,

 

I have a problem to open an hdf file. i have downloaded the package 'hdf5' as 
it was advised on R seek. But when i try to load the file, the R console sends 
me an eror message:

 

setwd(C:/Documents and Settings/Karine/Bureau/data/)

#install.packages('hdf5')
library(hdf5)
 sea_ice - hdf5load(asi-s6250-20090704-v5i.hdf, load = TRUE, verbosity = 3, 
tidy = FALSE)
 Grid_ice - hdf5load(LongitudeLatitudeGrid-s6250-Antarctic.hdf, load = TRUE, 
verbosity = 3, tidy = FALSE)

 

  sea_ice - hdf5load(asi-s6250-20090704-v5i.hdf, load = TRUE, verbosity = 
 3, tidy = FALSE)
hdf5_global_verbosity=3 load=1
Erreur dans hdf5load(asi-s6250-20090704-v5i.hdf, load = TRUE, verbosity = 3,  
: 
  unable to open HDF file: asi-s6250-20090704-v5i.hdf
  Grid_ice - hdf5load(LongitudeLatitudeGrid-s6250-Antarctic.hdf, load = 
 TRUE, verbosity = 3, tidy = FALSE)
hdf5_global_verbosity=3 load=1
Erreur dans hdf5load(LongitudeLatitudeGrid-s6250-Antarctic.hdf, load = TRUE,  
: 
  unable to open HDF file: LongitudeLatitudeGrid-s6250-Antarctic.hdf


Thanks a lot,


Karine HEERAH
 
Master 2 mention océanographie et environnements marins, parcours océanique
 
42 rue Salvador Allende 
92000 Nanterre
06.61.50.97.47



  
_



[[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] reading a string vector

2010-01-26 Thread Henrique Dallazuanna
Try this:

strsplit(atgctctaatcgtcccaacaattatattactaccac, NULL)

On Tue, Jan 26, 2010 at 11:08 AM, bia.estat bia@live.com wrote:

 Hi, I need to read a string vector in R which is like this
 atgctctaatcgtcccaacaattatattactaccac, but R seems to understand it as
 a unique vector input when I read in like x -
 atgctctaatcgtcccaacaattatattactaccac. How do I unconcatenate it, so I
 can use each of the letters on my reading?

 Thanks,
 Beatriz
 --
 View this message in context: 
 http://n4.nabble.com/reading-a-string-vector-tp1290289p1290289.html
 Sent from the R help mailing list archive at Nabble.com.

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




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

__
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] problem with read.genepop function

2010-01-26 Thread Adam Peer
I'm trying to use the package ARES to produce allelic richness
estimates with extrapolation beyond the sample size.  I've begun by
testing the program with the butterfly_borneo data provided with the
package, but I seem to be having a problem with the read.genepop
function.  Below, I've included my R code along with the error I
receive after trying to read the genepop file.  I'm not familiar with
this error message and would appreciate any comments on how to resolve
this problem, or interpret the error.

Thank you,
Adam

 path - system.file ( package = 'ARES');
 file - paste (list (path, '/data/butterfly_borneo.txt'), collapse=);
 butterfly_data - read.genepop (filename=file);
Error in read.genepop(filename = file) :
  trying to get slot title from an object of a basic class (list)
with no slots
In addition: Warning message:
In readLines(con) :
  incomplete final line found on
'C:/PROGRA~1/R/R-29~1.2/library/ARES/data/butterfly_borneo.txt'


__
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] heatmap.2 color range

2010-01-26 Thread evgeny55

Hi,
I'm trying to create a heatmap with color ranges for different values in my
matrix. For example:
If  x  5 , use orange gradient
if  x  1.5, use red gradient
.

Right now I have the following:
orgPal-brewer.pal(3,Oranges)
bluPal-brewer.pal(3,Blues)
redPal-brewer.pal(3,Reds)

grad - ifelse(randMat  5,orgPal,ifelse(randMat1.5,redPal,bluPal))
hmap - heatmap(randMat,Rowv=NULL, Colv=NULL,dendrogram=none,col = grad,
scale=column,...)

the problem is that all the colors become very close to white on one end of
the spectrum and the orange colors, for example, start approaching red when
x reaches extreme values and the heatmap loses its effect.  Is there an easy
way to specify a start and end range for each of my colors so that the hue
does not change dramatically within each spectrum.  I'm sure that I can
explicitly specify all the colors within my ifelse statement but this is
rather time consuming.

thanks,
John
-- 
View this message in context: 
http://n4.nabble.com/heatmap-2-color-range-tp1293498p1293498.html
Sent from the R help mailing list archive at Nabble.com.

__
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] Strange tick in ggplot geom_area; and ordering, again

2010-01-26 Thread Dieter Menne

In the area plots below, I see 4 triangle ticks at both sides of the bar; I
believe these are non-stacked values for p, but they are definitively
confusing.

In addition, I would like to get the order of the colors in the plot the
same as in the legend, and not arranged alphabetically (the factor is
ordered, don't touch my order). Hadley once mentioned an undocumented
aestetics order, but I could not get it to work in the example.

Dieter


library(ggplot2)
cf1 = structure(list(dur = c(10L, 10L, 10L, 10L, 10L, 150L, 150L,
150L, 150L, 150L), score = structure(c(3L, 1L, 4L, 5L, 2L, 3L,
1L, 4L, 5L, 2L), .Label = c(none, weak, moderate, severe,
verysevere), class = c(ordered, factor)), p = c(0.04, 0.02,
0.26, 0.6, 0.07, 0.07, 0.05, 0.33, 0.42, 0.14)), .Names = c(dur,
score, p), class = c(cast_df, data.frame))

# columns do not ad to 100% because of rounding; never mind

qplot(dur,p,data=cf1, fill=score)+  geom_area()


-- 
View this message in context: 
http://n4.nabble.com/Strange-tick-in-ggplot-geom-area-and-ordering-again-tp1294692p1294692.html
Sent from the R help mailing list archive at Nabble.com.

__
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] Strange tick in ggplot geom_area; and ordering, again

2010-01-26 Thread hadley wickham
Hi Dieter,

It looks like a bug:

Order works fine with bars:
qplot(factor(dur),weight=p,data=cf1, fill=score, geom = bar, order =
rev(score))

but not with areas:
qplot(dur, p, data=cf1, fill=score, geom = area, order = rev(score))

I'll add it to my to do list.

Hadley

On Tue, Jan 26, 2010 at 10:05 AM, Dieter Menne
dieter.me...@menne-biomed.de wrote:

 In the area plots below, I see 4 triangle ticks at both sides of the bar; I
 believe these are non-stacked values for p, but they are definitively
 confusing.

 In addition, I would like to get the order of the colors in the plot the
 same as in the legend, and not arranged alphabetically (the factor is
 ordered, don't touch my order). Hadley once mentioned an undocumented
 aestetics order, but I could not get it to work in the example.

 Dieter


 library(ggplot2)
 cf1 = structure(list(dur = c(10L, 10L, 10L, 10L, 10L, 150L, 150L,
 150L, 150L, 150L), score = structure(c(3L, 1L, 4L, 5L, 2L, 3L,
 1L, 4L, 5L, 2L), .Label = c(none, weak, moderate, severe,
 verysevere), class = c(ordered, factor)), p = c(0.04, 0.02,
 0.26, 0.6, 0.07, 0.07, 0.05, 0.33, 0.42, 0.14)), .Names = c(dur,
 score, p), class = c(cast_df, data.frame))

 # columns do not ad to 100% because of rounding; never mind

 qplot(dur,p,data=cf1, fill=score)+  geom_area()


 --
 View this message in context: 
 http://n4.nabble.com/Strange-tick-in-ggplot-geom-area-and-ordering-again-tp1294692p1294692.html
 Sent from the R help mailing list archive at Nabble.com.

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




-- 
http://had.co.nz/

__
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] Large dataset importing, columns merging and splitting

2010-01-26 Thread Gabor Grothendieck
Try this using the development version of read.zoo in zoo (which we
source from the R-Forge on the fly).

We use NULL in colClasses for those columns we don't need but in
col.names we still have to include dummy names for
them.  Of what is left the index is the first three columns (1:3)
which we convert to chron class times in FUN and then truncate to 5
seconds in FUN2.  Finally we use aggregate = mean to average over the
5 second intervals.

Lines - CVX 20070201 9 30 51 73.25 81400 0
CVX 20070201 9 30 51 73.25 100 0
CVX 20070201 9 30 51 73.25 100 0
CVX 20070201 9 30 51 73.25 300 0
CVX 20070201 9 30 51 73.25 81400 0
CVX 20070201 9 40 51 73.25 100 0
CVX 20070201 9 40 52 73.25 100 0
CVX 20070201 9 40 53 73.25 300 0


library(zoo)
source(http://r-forge.r-project.org/plugins/scmsvn/viewcvs.php/*checkout*/pkg/zoo/R/read.zoo.R?rev=611root=zoo;)
library(chron)

z - read.zoo(textConnection(Lines),
colClasses = c(NULL, NULL, numeric, numeric, numeric, 
numeric,
numeric, NULL),
col.names = c(V1, V2, V3, V4, V5, Price, Volume, V8),
index = 1:3,
FUN = function(tt) times(paste(tt[,1], tt[,2], tt[,3], sep = :)),
FUN2 = function(tt) trunc(tt, 00:00:05),
aggregate = mean)

The result of running the above is:

 z
 Price Volume
09:30:50 73.25 32660.
09:40:50 73.25   166.6667

On Tue, Jan 26, 2010 at 10:48 AM, Manta mantin...@libero.it wrote:

 Dear All,
 I have a large data set that looks like this:

 CVX 20070201 9 30 51 73.25 81400 0
 CVX 20070201 9 30 51 73.25 100 0
 CVX 20070201 9 30 51 73.25 100 0
 CVX 20070201 9 30 51 73.25 300 0

 First, I would like to import it by merging column 3 4 and 5, since that is
 the timestamp. Then, I would like to aggregate the data by splitting them in
 bins of 5 minutes size, therefore from 93000 up to 93459 etc, givin as
 output the average price and volume in the 5 minutes bin.

 Hope this helps,
 Best,

 Marco
 --
 View this message in context: 
 http://n4.nabble.com/Large-dataset-importing-columns-merging-and-splitting-tp1294668p1294668.html
 Sent from the R help mailing list archive at Nabble.com.

 __
 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] tapply and more than one function, with different arguments

2010-01-26 Thread RINNER Heinrich
Dear R-users,

I am working with R version 2.10.1.

Say I have is a simple function like this:

 my.fun - function(x, mult) mult*sum(x)

Now, I want to apply this function along with some other (say 'max') to a 
simple data.frame, like:

 dat - data.frame(x = 1:4, grp = c(a,a,b,b))

Ideally, the result would look something like this (if mult = 10):
  max my.fun
a   2 30
b   4 70

I have tried it that way:

apply.more.functions - function(dat, FUN = c(max, my.fun), ...) {
  res - NULL
  for(f in FUN) res[[f]] - tapply(dat$x, dat$grp, FUN = f, ...)
  data.frame(res)
}

# let's test it:
 apply.more.functions(dat, FUN = c(max, min))
  max min
a   2   1
b   4   3
# perfect!

# now, with an additional argument:
 apply.more.functions(dat, FUN = c(max, my.fun), mult = 10)
  max my.fun
a  10 30
b  10 70
# uhuh!
Apparently, 'mult' has been used in the calculation of 'max' as well.
How can I modify apply.more.functions in order to avoid this?

Your advice would be appreciated;
Kind regards
Heinrich.

__
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] update.packages on MS Windows with //server/share paths

2010-01-26 Thread Keith Jewell
Thanks Gabor, but expanding on my remark...

 I can work around by mapping a drive letter to the '//server/share', but
 prefer not to (for local reasons).

R is installed on our network, used by others (with readonly access), 
maintained by me.
In 'Renviron.site' I have...
   R_LIBS_SITE=//Server02/stats/R/library/%v
...which works for everyone else (and for me as long as I don't try 
update.packages).

I (but not everyone else!) routinely have a drive (L:) mapped to 
//Server02/stats so that I can (and currently do) update.packages by
a) altering 'Renviron.site' to R_LIBS_SITE=L://R/library/%v
b) starting Rgui.exe from (e.g.)  L:\R\R-2.10.1\bin
BUT while 'Renviron.site' is altered, users who don't have the drive mapping 
don't get the site library, so I have to be quick and risk a couple of 
complaints.

I've tried putting a '.Renviron' file in my personal home directory 
containing R_LIBS_SITE=L://R/library/%v hoping I could implement a 
'personal' site library, but it doesn't seem to have any effect (not 
unreasonably?). As I outlined, my attempts to alter .libPaths() or 
.Library.site within my R session haven't worked.

Anyway, (although I say this with trepidation) this does look to me like a 
minor bug. It seems to me that (for example)...
 shell.exec(.libPaths()[1])
  and
 shell.exec(file.path(dirname(.libPaths()[1]), basename(.libPaths()[1])))
...should give the same result, especially when (as in this case) the syntax 
of the file spec...
 .libPaths()[1]
[1] //Server02/stats/R/library/2.10
... is controlled by R (in this example the former fails with ...not 
found, the latter opens the folder in Windows Explorer).

Best regards,

Keith Jewell
-
Gabor Grothendieck ggrothendi...@gmail.com wrote in message 
news:971536df1001260714i430b9ddcm37ffa12642321...@mail.gmail.com...

Try mapping a drive letter to \\Server02 and then use that.  For more,
google for: map network drive

On Tue, Jan 26, 2010 at 10:01 AM, Keith Jewell k.jew...@campden.co.uk 
wrote:
 Hi,

 update.packages(ask='graphics')

 gives me multiple warning (one per updated package?) similar to ...

 Warning: unable to move temporary installation
 '\\Server02\stats\R\library\2.10\file3de56e0d\locfit' to
 '\\Server02\stats\R\library\2.10\locfit'

 The final, updated, folders do not end up where they should be. I can move
 them 'by hand', but it is an inconvenience.

 Checking the archives I find
 http://finzi.psych.upenn.edu/Rhelp08/2008-April/160963.html where Prof
 Ripley opines The issue appears to be that your OS is garbling file 
 names,
 and it surely does seem to be a filename problem - in combination R and
 Windows don't seem to be handling the '//server/share' path construction. 
 I
 have:
 .libPaths()
 [1] //Server02/stats/R/library/2.10
 //Server02/stats/R/R-Current/library

 I can work around by mapping a drive letter to the '//server/share', but
 prefer not to (for local reasons).

 In CHANGES.R-2.10.1pat I find
 CHANGES IN R VERSION 2.7.2 patched
 o dir.create(recursive = TRUE) was not working on //server/share paths.

 In CHANGES.R-2.11.0dev I find
 CHANGES IN R VERSION 2.11.0
 NEW FEATURES
 o file.rename() can work across volumes (by copy-and-delete)

 In another R function I've hit a similar problem and solved it using the
 construction:
 file.path(dirname(x), basename(x))
 to convert '//server/share' to (printed as) 'server/share' which 
 worked
 in that function. In this case:
 file.path(dirname(.libPaths()), basename(.libPaths()))
 [1] Server02/stats/R/library/2.10
 Server02/stats/R/R-Current/library
 which looks OK but
 .libPaths(file.path(dirname(.libPaths()), basename(.libPaths(
 .libPaths()
 [1] //Server02/stats/R/library/2.10
 //Server02/stats/R/R-Current/library
 doesn't actually change the internal paths.

 I don't see the problem in V2.9.2 .
 I do see the problem in
 V2.10.1,
 V2.10.1 Patched (2010-01-24 r51030)
 V2.11.0 Under development (unstable) (2010-01-24 r51030)

 Grateful for any suggestions,

 Keith Jewell
 -
 Version:
 platform = i386-pc-mingw32
 arch = i386
 os = mingw32
 system = i386, mingw32
 status = Patched
 major = 2
 minor = 10.1
 year = 2010
 month = 01
 day = 24
 svn rev = 51030
 language = R
 version.string = R version 2.10.1 Patched (2010-01-24 r51030)

 Windows Server 2003 x64 (build 3790) Service Pack 2

 Locale:
 LC_COLLATE=English_United Kingdom.1252;LC_CTYPE=English_United
 Kingdom.1252;LC_MONETARY=English_United
 Kingdom.1252;LC_NUMERIC=C;LC_TIME=English_United Kingdom.1252

 Search Path:
 .GlobalEnv, package:stats, package:graphics, package:grDevices,
 package:utils, package:datasets, package:methods, Autoloads, package:base

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

[R] (list) object cannot be coerced to type 'double'

2010-01-26 Thread Muhammad Rahiz

Dear all,

My script returns the following error:

Error in storage.mode(test) - logical : 
 (list) object cannot be coerced to type 'double'


I've looked around and some suggest that it could be the way data have been 
imported. For my case, I don't think it is such. Rather I think it has to be 
the way I define x1 and in1. x1 is an object in which the values are written to 
which in turn serve as input.

The object, x, contain 32 files of 2x2 matrix.

Any guidance would be appreciated.


Muhammad

-


# Cleans workspace

rm(list=ls())

# -- DATA -- #

# Load DATA[1]: Monthly anomalies

f - list.files(C:/Documents and Settings/shil3148/Desktop/dsi, 
\\.txt$) # List files with pattern matching

x - lapply(f, read.table)# DATA[1]: Monthly anomalies

# Prepare DATA[2]: Rolling Sum

nt - 6   
ed - nt - 1 
fl - length(x)   
y0 - list()   
   
for (i in 1:(fl-ed))# Remove NA values

{
 y0[[i]] - Reduce(+, x[c(i:(i+ed))]) # RAW: Rolling Sum
}

# Data conversion

xx - list()
for (z in 1:length(x))
{
xx[[z]] - as.matrix(x[[z]])# convert data to matrix
}

yy - list()
for (f in 1:length(y0))
{
yy[[f]] - as.matrix(y0[[f]])# convert data to matrix
}

# -- ALGORITHM -- #

x1  - list() # Error here
in1 - list() # Error here
for (t in 1:27) # This is the length of yy
{
 in1[t+1] -
   ifelse(x1[t]  0, (
   ifelse(yy[t]  0, x1[t] + xx[t+5], 0)), (
   ifelse(yy[t+1] = 0, 0, (
   ifelse(xx[t+5] = 0, 0, xx[t+5])
   ))
   )
   )
 x1[t+1] - in1[t+1]   
}


__
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] [Fwd: Re: question on sqldf syntax]

2010-01-26 Thread Seth Falcon

On 1/26/10 2:11 AM, Christian Schulz wrote:

Sorry mistake from me. This was another problem in my mind , but with
RMySQL.
Christian

  library(RMySQL)
  library(sqldf)
  sqldf(Select * from mtcars)
Fehler in mysqlNewConnection(drv, ...) :
RS-DBI driver: (Failed to connect to database: Error: Access denied for
user 'user'@'localhost' (using password: NO)
)
Fehler in if (dbname == :memory:) dbDisconnect(connection) else if
(!dbPreExists  :
Argument hat Länge 0
  detach(package:RMySQL)
  sqldf(Select * from mtcars)


That sqldf only works if RMySQL is not attached seems like something 
worth investigating and fixing. It should be possible to avoid such 
conflicts by proper use of name spaces, but I have not looked into the 
details of what's going on.


+ seth

--
Seth Falcon | @sfalcon | http://userprimary.net/user

__
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] PNG resolution

2010-01-26 Thread Matthew Walker

Hi,

I expect that if I change only the resolution of an image, although the 
image would have more pixels, if viewed in the same physical size, the 
elements in the image would have the same physical size but with more 
detail.  However, when I use the res parameter of png() this is not 
what I see.  Would someone show me how I can just increase the 
resolution without changing the physical sizes of elements in my plot?


Maybe an example would help?  Below are three images.  I expect that if 
I print them out, let's say scaled to fit the page, then items such as 
the words Title Text would appear the same size.  Instead (for the 
last two) it appears that the same number of pixels are being used, thus 
the text size appears smaller.


What should I do to just increase the resolution?

png(72dpi.png, width=6+2/3, height=6+2/3, units=in, res=72)
plot(0,0, main=Title Text)
dev.off()

png(300dpi.png, width=6+2/3, height=6+2/3, units=in, res=300)
plot(0,0, main=Title Text)
dev.off()

png(600dpi.png, width=6+2/3, height=6+2/3, units=in, res=600)
plot(0,0, main=Title Text)
dev.off()

Thanks in advance,

Matthew Walker

__
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] Strange tick in ggplot geom_area; and ordering, again

2010-01-26 Thread Dieter Menne

Hi, Hadley,

 

can you also reproduce the “triangles” problem? Is it just a trivial 
corollary of the order-bug?

 

Dieter

 

 

From: hadley wickham [via R] [mailto:ml-node+1294703-876505...@n4.nabble.com] 
Sent: Tuesday, January 26, 2010 5:18 PM
To: Dieter Menne
Subject: Re: [R] Strange tick in ggplot geom_area; and ordering, again

 

Hi Dieter, 

It looks like a bug: 

Order works fine with bars: 
qplot(factor(dur),weight=p,data=cf1, fill=score, geom = bar, order = 
rev(score)) 

but not with areas: 
qplot(dur, p, data=cf1, fill=score, geom = area, order = rev(score)) 

I'll add it to my to do list. 



 


-- 
View this message in context: 
http://n4.nabble.com/Strange-tick-in-ggplot-geom-area-and-ordering-again-tp1294692p1294763.html
Sent from the R help mailing list archive at Nabble.com.

[[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] [Fwd: Re: question on sqldf syntax]

2010-01-26 Thread Gabor Grothendieck
On Tue, Jan 26, 2010 at 11:55 AM, Seth Falcon s...@userprimary.net wrote:

 That sqldf only works if RMySQL is not attached seems like something worth
 investigating and fixing. It should be possible to avoid such conflicts by
 proper use of name spaces, but I have not looked into the details of what's
 going on.


It does work without RMySQL and in fact that is the normal way it is
used since MySQL support has not been tested and you are really on
your own if you want to try sqldf with MySQL (as indicated in
documentation and home page).

The driver= argument of the sqldf function call determines which
database is used.  If you don't specify the driver= argument then it
uses the global option sqldf.driver to determine which database to
use.  If you have not set that either then it checks if RMySQL is
attached and uses the MySQL database if it is and uses the SQLite
database otherwise.

__
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] Graph color

2010-01-26 Thread Kyle.
If I understand what you want correctly, you'll probably want to use the
col argument in whatever base graphics function you're using, rather than
changing something in the graphical parameters.  For example, if I wanted to
add red points to an existing plot, I would use something like

 points(c(1:10), col=red)

Or, if I wanted to generate a barplot using a shading color other than gray,

 barplot(c(1:10), col=steelblue)

Does that answer your question?


Kyle H. Ambert
Fellow, National Library of Medicine
Department of Medical Informatics  Clinical Epidemiology
Oregon Health  Science University



On Tue, Jan 26, 2010 at 6:44 AM, Jose Narillos de Santos 
narillosdesan...@gmail.com wrote:

 Hi all I want to apply different colors on a simple plot:

 If I type par(br=gray) before a plot it puts all the image in gray but
 (imagine I run a simple plot) want to let the centrall box (where the dots
 are plotted) in white or image in lightblue.

 Can anyone guide me to apply this second step (make the box where the
 series
 are plotted in different colours).

 Thanks in advance.

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


[[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] newb question: chron and hist()

2010-01-26 Thread kensuguro

Hi all, I'm just getting started in R so bear with my newbness.
I am trying to create a very simple histogram of logins by time, with data
coming in from a MYSQL query.

the raw data looks like this:
id user_id experience_given created_at ip_aton
1 XXX 2445626 0 2010-01-21 00:00:01 1123632036
2 XXX 2444945 0 2010-01-21 00:00:01 1123632036

After searching around for how to deal with the timestamp, I settled with
converting to POSIXct, and creating a chron object with as.numeric().  So I
managed to replace the timestamps with chron objects.
command:
bt$created_at = chron(as.numeric(as.POSIXct(bt$created_at)))

Seems very roundabout, but gets the job done.  I also see that I could just
use the numerical value instead, if readability wasn't an issue.

The problem is, when I try to hist(bt$created_at), I get errors:
Error in axis(2, adj = adj, cex = cex, font = font, las = las, lab = lab,  : 
  'labels' is supplied and not 'at'
In addition: Warning messages:
1: In plot.window(xlim, ylim, log = log, ...) :
  histo is not a graphical parameter
2: In title(main = main, sub = sub, xlab = xlab, ylab = ylab, ...) :
  histo is not a graphical parameter

and the histogram looks busted like this:
http://n4.nabble.com/file/n1294762/picture236.png 

Any ideas?  I'm quite lost here, and having trouble finding date-time
specific info.  I do get the gist that chron is supposed to be the key, but
I'm having a hard time understanding an overview of all the different time
related classes.  thnx for any advice in advance.
-- 
View this message in context: 
http://n4.nabble.com/newb-question-chron-and-hist-tp1294762p1294762.html
Sent from the R help mailing list archive at Nabble.com.

__
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] Hypothsis simulation

2010-01-26 Thread Greg Snow
You can use the rbinom function to generate the random data.  What to feed that 
function depends on things that you did not state (is this a comparison of 2 
groups?, a logistic regression?, etc.).

-- 
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.s...@imail.org
801.408.8111


 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-
 project.org] On Behalf Of Jim Silverton
 Sent: Monday, January 25, 2010 9:44 PM
 To: r-help@r-project.org
 Subject: Re: [R] Hypothsis simulation
 
 I wish to simulate:
 
 Ho: Odds Ratio =1
 H1 Odds Ratio  1
 
 Can any of the R users show me how to generate this data for say 20%
 from Ho
 and 80% from H1?
 
 Thanks,
 
 Jim
 
   [[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-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] (no subject)

2010-01-26 Thread Kyle.
Something along these lines might do the trick:

 orig - rep(sapply(seq(from=, to=, by=),
as.character), times=c(1, 2, 3, 4))

I've shortened the number of repetitions, so you can test it out and see if
it's what you're looking for (just change the values in the vector assigned
to the times argument). It might be helpful to know a bit more about the
specific problem you're trying to solve though.


Kyle H. Ambert
Fellow, National Library of Medicine
Department of Medical Informatics  Clinical Epidemiology
Oregon Health  Science University

On Mon, Jan 25, 2010 at 10:46 AM, Chuck White chuckwhi...@charter.netwrote:

 Hello -- I would like to know of a more efficient way of writing the
 following piece of code. Thanks.

 options(stringsAsFactors=FALSE)
 orig -
 c(rep('',10),rep('',20),rep('',30),rep('',40))
 orig.unique - unique(orig)
 system.time(df - as.data.frame(sapply(orig.unique, function(x)
 ifelse(orig==x, 1, 0

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


[[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] tapply and more than one function, with different arguments

2010-01-26 Thread Peter Ehlers

Try replacing 'max' with 'mean' and see what you get.
Then have a look at ?max and see what max() does with
extra arguments.

I'm not sure it's relevant, but it might be useful
to check what Hmisc::summarize does.

 -Peter Ehlers

RINNER Heinrich wrote:

Dear R-users,

I am working with R version 2.10.1.

Say I have is a simple function like this:


my.fun - function(x, mult) mult*sum(x)


Now, I want to apply this function along with some other (say 'max') to a 
simple data.frame, like:


dat - data.frame(x = 1:4, grp = c(a,a,b,b))


Ideally, the result would look something like this (if mult = 10):
  max my.fun
a   2 30
b   4 70

I have tried it that way:

apply.more.functions - function(dat, FUN = c(max, my.fun), ...) {
  res - NULL
  for(f in FUN) res[[f]] - tapply(dat$x, dat$grp, FUN = f, ...)
  data.frame(res)
}

# let's test it:

apply.more.functions(dat, FUN = c(max, min))

  max min
a   2   1
b   4   3
# perfect!

# now, with an additional argument:

apply.more.functions(dat, FUN = c(max, my.fun), mult = 10)

  max my.fun
a  10 30
b  10 70
# uhuh!
Apparently, 'mult' has been used in the calculation of 'max' as well.
How can I modify apply.more.functions in order to avoid this?

Your advice would be appreciated;
Kind regards
Heinrich.

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




--
Peter Ehlers
University of Calgary

__
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] Strange tick in ggplot geom_area; and ordering, again

2010-01-26 Thread Dieter Menne

Hi, Hadley,

 

In case you have a temporary workaround, it would be nice to have it. It’s a 
show stopper for my report. Bars are not an option, because the curve looks too 
jaggy.

 

‘Dieter

 

 

From: hadley wickham [via R] [mailto:ml-node+1294703-876505...@n4.nabble.com] 
Sent: Tuesday, January 26, 2010 5:18 PM
To: Dieter Menne
Subject: Re: [R] Strange tick in ggplot geom_area; and ordering, again

 

Hi Dieter, 

It looks like a bug: 

Order works fine with bars: 
qplot(factor(dur),weight=p,data=cf1, fill=score, geom = bar, order = 
rev(score)) 

but not with areas: 



 


-- 
View this message in context: 
http://n4.nabble.com/Strange-tick-in-ggplot-geom-area-and-ordering-again-tp1294692p1295444.html
Sent from the R help mailing list archive at Nabble.com.

[[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] sp package coordinates and gridded problems with as.list()

2010-01-26 Thread Rhelp wanted
Dear All I hope that someone can help.

I am working with sp pakage and akima
library(akima)
library(sp)



imagine lots of different dataframes, of row = 100 columns = 3 of  x and y
coordinates with z values I will call these data frames for the sake of this
example akima

akima-as.list(1:100)

producing 100 dataframes dataframes of the form akima[[i]]

I then wish to interp this list of coordinates:

akima.li-as.list(1:100)
for (i in 1:100) akima.li[[i]]-interp(akima[[i]]$x, akima[[i]]$y, akima
[[i]]$z)

so now I have 100 akima.li which I then transform into a dataframe of the
akima.li values

y-as.list(1:100)
x-as.list(1:100)
z-as.list(1:100)

for (i in 1:endofrun){
y[[i]]= rep(akima.li[[i]]$x, each = length(akima.li[[i]]$y))
x[[i]] = rep(akima.li[[i]]$y, length(akima.li[[i]]$x))
z[[i]] = as.numeric(akima.li[[i]]$z)
}

abc-as.list(1:100)

for (i in 1:endofrun){
abc[[i]]- data.frame(x[[i]], y[[i]], z[[i]])
abc[[i]][is.na(abc[[i]])] - 0}



so now I have 100 dataframes with x and y columns and corresponding z values
and any NAs are now 0.

This is where my problem starts I wish to use sp to state which columns are
coordinates of the form

for (i in 1:100) coordinates(abc[[i]])= ~x+y

and that all of the dataframes are a grid, such that.

for (i in 1:100)  gridded(abc[[i]]) = TRUE

however I get error messeges such as:
Error in function (classes, fdef, mtable)  :  unable to find an inherited
method for function coordinates-, for signature integer

and I do not know what this means.

I will then want to then go on to overlay such:

datapoint = data.frame(x = 10, y = 20)
coordinates(datapoint) = ~x+y
gridded(datapoint)=TRUE

value-as.list(1:100)

for (i in 1:100)   value [[i]]= abc[[...@data[overlay(abc[[i]], datapoint),]

then I will have a list of 100 value for each original dataframe

I would be appreciative if someone could tell me how I can allocate
coordinate and grided systems to an dataframes which are as.list.

I hope that is comprehendable and someone can help. I am very stuck

many thanks Sylvestre

[[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] heatmap.2 color range

2010-01-26 Thread Dieter Menne


evgeny55 wrote:
 
 I'm trying to create a heatmap with color ranges for different values in
 my matrix. For example:
 If  x  5 , use orange gradient
 if  x  1.5, use red gradient
 .
 
 Right now I have the following:
 orgPal-brewer.pal(3,Oranges)
 bluPal-brewer.pal(3,Blues)
 redPal-brewer.pal(3,Reds)
 
 

I often use larger palettes (brewer.pal(7,...)) and remove the middle range.

Dieter


-- 
View this message in context: 
http://n4.nabble.com/heatmap-2-color-range-tp1293498p1305413.html
Sent from the R help mailing list archive at Nabble.com.

__
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] PNG resolution

2010-01-26 Thread Dieter Menne


Matthew Walker wrote:
 
 I expect that if I change only the resolution of an image, although the 
 image would have more pixels, if viewed in the same physical size, the 
 elements in the image would have the same physical size but with more 
 detail. 
 
 

The sample you provided create figures with the same relative size of text
and title on Windows and R 2.10.1. I remember, however, that I had similar
problem before, so possibly it has been fixed and you are using an older
version or a different operating system.

Also have a look at the Cairo devices; I have used them with good success in
similar cases.

Dieter


-- 
View this message in context: 
http://n4.nabble.com/PNG-resolution-tp1294757p1307877.html
Sent from the R help mailing list archive at Nabble.com.

__
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] tapply and more than one function, with different arguments

2010-01-26 Thread Dennis Murphy
Hi:

Using the plyr package, we can get the result as follows:

 library(plyr)
 my.fun - function(x, mult) mult*sum(x)
 dat - data.frame(x = 1:4, grp = c(a,a,b,b))
 ddply(dat, .(grp), summarize, max = max(x), myfun = my.fun(x, 10))
  grp max myfun
1   a   230
2   b   470

HTH,
Dennis

On Tue, Jan 26, 2010 at 8:26 AM, RINNER Heinrich 
heinrich.rin...@tirol.gv.at wrote:

 Dear R-users,

 I am working with R version 2.10.1.

 Say I have is a simple function like this:

  my.fun - function(x, mult) mult*sum(x)

 Now, I want to apply this function along with some other (say 'max') to a
 simple data.frame, like:

  dat - data.frame(x = 1:4, grp = c(a,a,b,b))

 Ideally, the result would look something like this (if mult = 10):
  max my.fun
 a   2 30
 b   4 70

 I have tried it that way:

 apply.more.functions - function(dat, FUN = c(max, my.fun), ...) {
  res - NULL
  for(f in FUN) res[[f]] - tapply(dat$x, dat$grp, FUN = f, ...)
  data.frame(res)
 }

 # let's test it:
  apply.more.functions(dat, FUN = c(max, min))
  max min
 a   2   1
 b   4   3
 # perfect!

 # now, with an additional argument:
  apply.more.functions(dat, FUN = c(max, my.fun), mult = 10)
  max my.fun
 a  10 30
 b  10 70
 # uhuh!
 Apparently, 'mult' has been used in the calculation of 'max' as well.
 How can I modify apply.more.functions in order to avoid this?

 Your advice would be appreciated;
 Kind regards
 Heinrich.

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


[[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] heatmap.2 color range

2010-01-26 Thread evgeny55

as a followup, I tried using the rainbow function to create the gradients but
is there a way to do a reverse rainbow, ie. normally if I do: 

pie(rep(1,6), col=rainbow(6,start=0, end=.07))

I'll get a gradient from dark red to orangish but what if I want it to go
the other way

thanks
-- 
View this message in context: 
http://n4.nabble.com/heatmap-2-color-range-tp1293498p1302571.html
Sent from the R help mailing list archive at Nabble.com.

__
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] Formatting cgroup and factor level labels in Hmisc latex function

2010-01-26 Thread Dieter Menne


stefan.petersson wrote:
 
 
 I'm trying to typeset at simple crosstable with the Hmisc latex function.
 And I have two problems.
 
 1. How do I make all columns the same width? The Latex function seems very
 unwilling to break the 'cgroup' labels and the factor level labels. Please
 have look at this screenshot that shows my problem:
 
   http://hem.passagen.se/stpe9096/table.png
 
 So, how can I make sure that the cgroup labels and the factor level labels
 are sufficiently line breaked and/or hyphenated to make the columns evenly
 spaced?
 
 
To force a fixed width, use a custom latex column format and pass it to the
latex function. If this does not solve the column break problem, manually
pass the column titles and insert a \n. I have used the first version, the
second one might not work.


stefan.petersson wrote:
 
 
 2. Is there something like a 'widetable' package that can break a wide
 table into several tables with repeated 'rgroup' labels? As You can see in
 the screenshot, the table runs way off the page. And I know that there is
 a 'longtable' package that can do exactly this, but for tables with long
 rgroup lists.
 
 

A workaround is to rotate the output with latex, or to use a smaller font.
Also, making the padding space columns in latex smaller can help.

Dieter

-- 
View this message in context: 
http://n4.nabble.com/Formatting-cgroup-and-factor-level-labels-in-Hmisc-latex-function-tp1290232p1310696.html
Sent from the R help mailing list archive at Nabble.com.

__
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] Large dataset importing, columns merging and splitting

2010-01-26 Thread Tom Short
If you need more aggregations on the stock (I assume that's what the
first column is), I'd use the data.table package. It allows fast
indexing and merge operations. That's handy if you have other features
of a stock (like company size or industry sector) that you'd like to
include in the aggregation. Like Gabor, I'd probably use chron for
keeping track of the dates.

Here's some code to get you started:

Lines - CVX 20070201 9 30 51 73.25 81400 0
CVX 20070201 9 30 51 73.25 100 0
CVX 20070201 9 30 51 73.25 100 0
CVX 20070201 9 30 51 73.25 300 0
CVX 20070201 9 30 51 73.25 81400 0
CVX 20070201 9 40 51 74.25 100 0
CVX 20070201 9 40 52 74.25 100 0
CVX 20070201 9 40 53 74.25 300 0
CVX 20070301 9 30 51 74.25 100 0
CVX 20070301 9 30 51 74.25 100 0
CVX 20070301 9 30 51 74.25 300 0
CVX 20070301 9 30 51 74.25 81400 0
CVX 20070301 9 40 51 74.25 100 0
CVX 20070301 9 40 52 74.25 100 0
CVX 20070301 9 40 53 74.25 300 0
DVX 20070201 9 30 51 73.25 81400 0
DVX 20070201 9 30 51 73.25 100 0
DVX 20070201 9 30 51 73.25 100 0
DVX 20070201 9 30 51 73.25 300 0
DVX 20070201 9 30 51 73.25 81400 0
DVX 20070201 9 40 51 74.25 100 0
DVX 20070201 9 40 52 74.25 100 0
DVX 20070201 9 40 53 74.25 300 0
DVX 20070301 9 30 51 74.25 100 0
DVX 20070301 9 30 51 74.25 100 0
DVX 20070301 9 30 51 74.25 300 0
DVX 20070301 9 30 51 74.25 81400 0
DVX 20070301 9 40 51 74.25 100 0
DVX 20070301 9 40 52 74.25 100 0
DVX 20070301 9 40 53 74.25 300 0


library(data.table)
library(chron)
dt - data.table(read.table(textConnection(Lines),
                           colClasses = c(character, numeric,
numeric, numeric, numeric, numeric,
                           numeric, numeric),
                           col.names = c(stock, date, h, m,
s, Price, Volume, xx)))
dt$date - as.chron(as.Date(as.character(dt$date), format = %Y%m%d))
+ dt$h/24 + dt$m/(60*24) + dt$s/(60*60*24)
dt$roundeddate - as.integer(floor(as.numeric(dt$date) * (24 * 12))) #
data.table likes integers

dt[,list(meanprice = mean(Price), volume = sum(Volume)), by = roundeddate]
dt[,list(meanprice = mean(Price), volume = sum(Volume)), by =
stock,roundeddate]

You'd still probably want to turn the roundeddate back into a real
chron object. If you use aggregation a lot, the development version of
data.table has faster aggregations:
http://r-forge.r-project.org/projects/datatable/

- Tom

On Tue, Jan 26, 2010 at 11:23 AM, Gabor Grothendieck
ggrothendi...@gmail.com wrote:
 Try this using the development version of read.zoo in zoo (which we
 source from the R-Forge on the fly).

 We use NULL in colClasses for those columns we don't need but in
 col.names we still have to include dummy names for
 them.  Of what is left the index is the first three columns (1:3)
 which we convert to chron class times in FUN and then truncate to 5
 seconds in FUN2.  Finally we use aggregate = mean to average over the
 5 second intervals.

 Lines - CVX 20070201 9 30 51 73.25 81400 0
 CVX 20070201 9 30 51 73.25 100 0
 CVX 20070201 9 30 51 73.25 100 0
 CVX 20070201 9 30 51 73.25 300 0
 CVX 20070201 9 30 51 73.25 81400 0
 CVX 20070201 9 40 51 73.25 100 0
 CVX 20070201 9 40 52 73.25 100 0
 CVX 20070201 9 40 53 73.25 300 0


 library(zoo)
 source(http://r-forge.r-project.org/plugins/scmsvn/viewcvs.php/*checkout*/pkg/zoo/R/read.zoo.R?rev=611root=zoo;)
 library(chron)

 z - read.zoo(textConnection(Lines),
        colClasses = c(NULL, NULL, numeric, numeric, numeric, 
 numeric,
                numeric, NULL),
        col.names = c(V1, V2, V3, V4, V5, Price, Volume, V8),
        index = 1:3,
        FUN = function(tt) times(paste(tt[,1], tt[,2], tt[,3], sep = :)),
        FUN2 = function(tt) trunc(tt, 00:00:05),
        aggregate = mean)

 The result of running the above is:

 z
         Price     Volume
 09:30:50 73.25 32660.
 09:40:50 73.25   166.6667

 On Tue, Jan 26, 2010 at 10:48 AM, Manta mantin...@libero.it wrote:

 Dear All,
 I have a large data set that looks like this:

 CVX 20070201 9 30 51 73.25 81400 0
 CVX 20070201 9 30 51 73.25 100 0
 CVX 20070201 9 30 51 73.25 100 0
 CVX 20070201 9 30 51 73.25 300 0

 First, I would like to import it by merging column 3 4 and 5, since that is
 the timestamp. Then, I would like to aggregate the data by splitting them in
 bins of 5 minutes size, therefore from 93000 up to 93459 etc, givin as
 output the average price and volume in the 5 minutes bin.

 Hope this helps,
 Best,

 Marco
 --
 View this message in context: 
 http://n4.nabble.com/Large-dataset-importing-columns-merging-and-splitting-tp1294668p1294668.html
 Sent from the R help mailing list archive at Nabble.com.

 __
 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 

Re: [R] Formatting cgroup and factor level labels in Hmisc latex function

2010-01-26 Thread Dieter Menne


stefan.petersson wrote:
 
 
 I'm trying to typeset at simple crosstable with the Hmisc latex function.
 And I have two problems.
 
 1. How do I make all columns the same width? The Latex function seems very
 unwilling to break the 'cgroup' labels and the factor level labels. Please
 have look at this screenshot that shows my problem:
 
 

Snippets for custom width
\newcolumntype{R}[1]{{\raggedright\hspace{0pt}\arraybackslash}p{#1}}

databasefields,results=tex=
col.just = c(l,l,R{9cm}) # You can use past to construct the width be
code
latex(... col.just=col.just,


Dieter



-- 
View this message in context: 
http://n4.nabble.com/Formatting-cgroup-and-factor-level-labels-in-Hmisc-latex-function-tp1290232p1310708.html
Sent from the R help mailing list archive at Nabble.com.

__
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] PNG resolution

2010-01-26 Thread Matthew Walker

   Dieter Menne wrote:

Matthew Walker wrote:
  

I expect that if I change only the resolution of an image, although the 
image would have more pixels, if viewed in the same physical size, the 
elements in the image would have the same physical size but with more 
detail. 



The sample you provided create figures with the same relative size of text
and title on Windows and R 2.10.1. I remember, however, that I had similar
problem before, so possibly it has been fixed and you are using an older
version or a different operating system.

Also have a look at the Cairo devices; I have used them with good success in
similar cases.

  

   Thank you Dieter for your reply.
   I too am using R version 2.10.1 (2009-12-14), but on Linux.  I compiled it
   against  cairo-1.8.8.   I  tried specifying the cairo device by adding
   'type=cairo' to the png() call, but it resulted in the same effect.
   I did notice, however, that the centre (0,0) circle is drawn at the same
   physical size for each of the examples.  The same can be said of the outer
   box, and the tick marks.  It is only the main text and the x and y labels
   that change in size.  Is it possible that the text size is somehow dependant
   on the number of pixels in the image?
   Thanks again,
   Matthew
__
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] reading a string vector

2010-01-26 Thread bia.estat

thanks, it was exactly what i needed.
-- 
View this message in context: 
http://n4.nabble.com/reading-a-string-vector-tp1290289p1310721.html
Sent from the R help mailing list archive at Nabble.com.

__
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] Fwd: Re: Graph color

2010-01-26 Thread narillosdesantos
No mate,

Sorry first of all about my indefinition (I´m Spanish, I´m improving  
everyday but a long road to the perfection). Sorry pleae.

Second, also it is diffcoult sometimes to express what we try (sorry and  
many thanks just for reading of course for helping).

Imagine you plot

X=[2 4 6 8] front a Y=[6 5 8 7]

When you plot it by default all is white what I want is to use  
par(br=gray) to make the graph gray but I want that the area (the  
imaginary square defined by the axis) not to be gray I want to deffine its  
colour by ie lightblue.

So the image will be a square image outside gray and on the axis area (not  
the dots, points or bar plots) the area in lightblue.

I don´t now if I have expressed well if not latter I will send an example,  
ok?

Many thanks

-- Mensaje reenviado --
De: Kyle. ambe...@gmail.com
Fecha:
Asunto: Re: [R] Graph color
Para: Jose Narillos de Santos narillosdesan...@gmail.com
CC: r-help@r-project.org


 If I understand what you want correctly, you'll probably want to use  
 the col argument in whatever base graphics function you're using,  
 rather than changing something in the graphical parameters. For example,  
 if I wanted to add red points to an existing plot, I would use something  
 like





 points(c(1:10), col=red)


 Or, if I wanted to generate a barplot using a shading color other than  
 gray,


 barplot(c(1:10), col=steelblue)






 Does that answer your question?




 Kyle H. Ambert
 Fellow, National Library of Medicine
 Department of Medical Informatics  Clinical Epidemiology




 Oregon Health  Science University





 On Tue, Jan 26, 2010 at 6:44 AM, Jose Narillos de Santos  
 narillosdesan...@gmail.com wrote:




 Hi all I want to apply different colors on a simple plot:





 If I type par(br=gray) before a plot it puts all the image in gray but


 (imagine I run a simple plot) want to let the centrall box (where the dots


 are plotted) in white or image in lightblue.





 Can anyone guide me to apply this second step (make the box where the  
 series


 are plotted in different colours).





 Thanks in advance.





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









[[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] Apply a function on an array with the parameter as an array

2010-01-26 Thread anna

Hello R buddies, I want to apply a function on an array but for each element
of the array I want to use a different parameter, So here is how I tried to
enter the function:
apply(as.matrix(X),2, function, parameter1 = arrayOfParameter)
I put X as a matrix because it was initially an element of a list. It
returns me an array with the same length as X but with values that I don't
even understand...Can someone please help me?
-- 
View this message in context: 
http://n4.nabble.com/Apply-a-function-on-an-array-with-the-parameter-as-an-array-tp1310834p1310834.html
Sent from the R help mailing list archive at Nabble.com.

__
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] Fwd: Re: Graph color

2010-01-26 Thread baptiste auguie
Hi,

Try this,

x - seq(0, 10, len = 100)
y - jitter(sin(x), 1000)

old.par - par()
par(bg=grey(0.5))

plot(x, y, new = TRUE, t = n)
lims - par(usr)

plot(x, y, col = 1,
  panel.first = {
rect(lims[1], lims[3], lims[2], lims[4],
  col = lightblue) })

HTH,

baptiste

2010/1/26  narillosdesan...@gmail.com:
 No mate,

 Sorry first of all about my indefinition (I´m Spanish, I´m improving
 everyday but a long road to the perfection). Sorry pleae.

 Second, also it is diffcoult sometimes to express what we try (sorry and
 many thanks just for reading of course for helping).

 Imagine you plot

 X=[2 4 6 8] front a Y=[6 5 8 7]

 When you plot it by default all is white what I want is to use
 par(br=gray) to make the graph gray but I want that the area (the
 imaginary square defined by the axis) not to be gray I want to deffine its
 colour by ie lightblue.

 So the image will be a square image outside gray and on the axis area (not
 the dots, points or bar plots) the area in lightblue.

 I don´t now if I have expressed well if not latter I will send an example,
 ok?

 Many thanks

 -- Mensaje reenviado --
 De: Kyle. ambe...@gmail.com
 Fecha:
 Asunto: Re: [R] Graph color
 Para: Jose Narillos de Santos narillosdesan...@gmail.com
 CC: r-help@r-project.org


 If I understand what you want correctly, you'll probably want to use
 the col argument in whatever base graphics function you're using,
 rather than changing something in the graphical parameters. For example,
 if I wanted to add red points to an existing plot, I would use something
 like





 points(c(1:10), col=red)


 Or, if I wanted to generate a barplot using a shading color other than
 gray,


 barplot(c(1:10), col=steelblue)






 Does that answer your question?




 Kyle H. Ambert
 Fellow, National Library of Medicine
 Department of Medical Informatics  Clinical Epidemiology




 Oregon Health  Science University





 On Tue, Jan 26, 2010 at 6:44 AM, Jose Narillos de Santos
 narillosdesan...@gmail.com wrote:




 Hi all I want to apply different colors on a simple plot:





 If I type par(br=gray) before a plot it puts all the image in gray but


 (imagine I run a simple plot) want to let the centrall box (where the dots


 are plotted) in white or image in lightblue.





 Can anyone guide me to apply this second step (make the box where the
 series


 are plotted in different colours).





 Thanks in advance.





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









        [[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-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] Apply a function on an array with the parameter as an array

2010-01-26 Thread Bert Gunter


-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On
Behalf Of anna
Sent: Tuesday, January 26, 2010 11:48 AM
To: r-help@r-project.org
Subject: [R] Apply a function on an array with the parameter as an array


Hello R buddies, I want to apply a function on an array but for each element
of the array I want to use a different parameter, So here is how I tried to
enter the function:
apply(as.matrix(X),2, function, parameter1 = arrayOfParameter)
I put X as a matrix because it was initially an element of a list. It
returns me an array with the same length as X but with values that I don't
even understand...Can someone please help me?


-- Probably not. You haven't read and followed the posting guide and
provided a small reproducible example so we know exactly what you tried to
do.

Bert Gunter
Genentech Nonclinical Statistics

__
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] Apply a function on an array with the parameter as an array

2010-01-26 Thread anna

No the posting guide is quite big and I wanted to take time to read it
properly, since I have been posting seriously since last wednesday and I
work a lot I didn't get time to do it but will do it now ;). So you say that
you know exactly what I tried to do can you explain what I tried to do if
it's not looking for help? 
-- 
View this message in context: 
http://n4.nabble.com/Apply-a-function-on-an-array-with-the-parameter-as-an-array-tp1310834p1310849.html
Sent from the R help mailing list archive at Nabble.com.

__
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] Apply a function on an array with the parameter as an array

2010-01-26 Thread Bert Gunter
I perhaps should have added that the etiquette of this list is to supply
your correct name in your signature. This does not necessarily mean that you
will be ignored if you fail to do so, but it does increase the likelihood
that you will be.


Bert Gunter
Genentech Nonclinical Biostatistics

__
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] Apply a function on an array with the parameter as an array

2010-01-26 Thread Bert Gunter
Speaking **only for myself**, if you don't have the time to read and follow
the posting guide, I don't have the time to try to help you.

Bert Gunter
Genentech Nonclinical Biostatistics

__
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] Apply a function on an array with the parameter as an array

2010-01-26 Thread anna

Sorry! I am reading it now! 
-- 
View this message in context: 
http://n4.nabble.com/Apply-a-function-on-an-array-with-the-parameter-as-an-array-tp1310834p1310856.html
Sent from the R help mailing list archive at Nabble.com.

__
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] newton method for single nonlinear equation

2010-01-26 Thread Berend Hasselman


Roslina Zakaria wrote:
 
 newton.inputsingle - function(pars,n)
 {  runi    - runif(974, min=0, max=1)
    lendt   - length(runi)
    ## Parameter to estimate
    z - vector(length=lendt, mode= numeric)
    z  - pars[1]
    
    ## Constant value  
    
    alp  - 2.0165 ; rho - 0.868; 
    c    - sqrt(pi)/(gamma(alp)*(1-rho)^alp)
    
    for (i in 1:n)
    {  t1   - exp(-pars[1]/(1-rho))   
   t2   - (pars[1]*(1-rho)/(2*sqrt(rho)))^(alp-0.5)   
   bes1 - besselI(pars[1]*sqrt(rho)/(1-rho),alp-0.5)  
   bes2 - besselI(pars[1]*sqrt(rho)/(1-rho),alp-1.5)
   bes3 - besselI(pars[1]*sqrt(rho)/(1-rho),alp+0.5)
  
    ## Equation
   f   - c*t1*t2*bes1 - runi
    
    ## derivative
   fprime   - c*t1*t2*( -bes1/(1-rho) + (alp-0.5)*bes1/pars[1] +
 sqrt(rho)*(bes2-bes3)/(2*(1-rho)))
   z[i+1] - z[i] - f/fprime 
   }
   z
 }
  
 pars - 0.5  
 newton.inputsingle(pars,5)
  
 The output :
  
 pars - 0.5  
 newton.inputsingle(pars,5)
 [1]  0.500 -0.4826946 -1.4653892 -2.4480838 -3.4307784 -4.4134730
 Warning messages:
 1: In z[i + 1] - z[i] - f/fprime :
   number of items to replace is not a multiple of replacement length
 

The warning message is the result of assigning a vector (f/fprime) to a
scalar.
You are also redefining an R built-in function: c

Furthermore it is unclear what you are trying to do.

I would advise: Keep It Simple and Stupid (KISS).
To help you along I have lifted the relevant function out of your
newton.inputsingle
(or at least what I think your function is)

zztest - function(x) {
   ## Constant value
alp  - 2.0165 ; rho - 0.868;
czz  - sqrt(pi)/(gamma(alp)*(1-rho)^alp)

t1   - exp(-x/(1-rho))
t2   - (x*(1-rho)/(2*sqrt(rho)))^(alp-0.5)
bes1 - besselI(x*sqrt(rho)/(1-rho),alp-0.5)
bes2 - besselI(x*sqrt(rho)/(1-rho),alp-1.5)
bes3 - besselI(x*sqrt(rho)/(1-rho),alp+0.5)

   ## Equation
f   - czz*t1*t2*bes1 - .1
}

pars - 0.5
zztest(pars)
plot(zztest,0,10)
abline(0,0,lty=2)
uniroot(zztest, c(0,2))
uniroot(zztest, c(4,8))

The plot indicates how your function behaves.
The two uniroot calls solve for the two roots that appear in the plot.
You should be able to proceed on your own from here.
BTW: I do hope that this not homework.

good luck

Berend

-- 
View this message in context: 
http://n4.nabble.com/newton-method-for-single-nonlinear-equation-tp1289991p1310861.html
Sent from the R help mailing list archive at Nabble.com.

__
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] splitting a factor column into binary columns for each factor

2010-01-26 Thread Chuck White
Yesterday I posted the following question (my apologies for not putting a 
subject line):

=question==
Hello -- I would like to know of a more efficient way of writing the following 
piece of code. Thanks. 

options(stringsAsFactors=FALSE) 
orig -  c(rep('',10),rep('',20),rep(''  
,30),rep('',40)) 
orig.unique - unique(orig) 
system.time(df - as.data.frame(sapply(orig.unique,  function(x) 
ifelse(orig==x, 1, 0


I received a response via e-mail which was **extremely** useful.

=answer==
Using sapply instead of lapply here is a waste.  sapply() calls lapply(), which 
returns a list that sapply() turns into a list by making each list element a 
column of the matrix.  data.frame(matrix) then makes a list from the columns of 
the matrix.

The one thing that sapply gives you and lapply doesn't is column names.  If you 
attach names to orig.unique then lapply's output will have them. 
 
Also ifelse(orig==x,1,0) slower than the equivalent as.numeric(orig==x).  I 
wrote functions g0 (containing your code), g1 (using lapply), and g2 
(ifelse-as.numeric).  I parameterized them by the number of '111' elements 
and they each return the data.frame created and the time it took to do it:

 g0
function(n = 1e+05) { 
  orig - c(rep(, n), rep(, 2*n), rep(, 3*n), 
rep(, 4*n)) 
  orig.unique - unique(orig) 
  time - system.time(df - as.data.frame(sapply(orig.unique, function(x) 
ifelse(orig == x, 1, 0 
  list(time = time, df = df) 
} 

 g1
function (n = 1e+05)  { 
  orig - c(rep(, n), rep(, 2*n), rep(, 3*n), 
rep(, 4*n)) 
  orig.unique - unique(orig)
  names(orig.unique) - orig.unique 
  time - system.time(df - data.frame(check.names=FALSE, lapply(orig.unique, 
function(x) ifelse(orig == x, 1, 0 
  list(time = time, df = df) 
}

 g2 
function (n = 1e+05) { 
  orig - c(rep(, n), rep(, 2*n), rep(, 3*n), 
rep(, 4*n)) 
  orig.unique - unique(orig) 
  names(orig.unique) - orig.unique 
  time - system.time(df - data.frame(check.names=FALSE, lapply(orig.unique, 
function(x) as.numeric(orig == x 
  list(time = time, df = df) 
} 
 
For n=10^5 the times were 
 g0(1e5)$time 
   user  system elapsed 
  20.650.41   20.64 
 g1(1e5)$time 
   user  system elapsed 
   2.350.052.36 
 g2(1e5)$time 
   user  system elapsed 
   0.730.100.77 
and the data.frames each produced were identical. 
 
Another approach is to use outer() to make a matrix that gets passed to 
data.frame().  It seems slightly slower than g2, but small changes might make 
it faster.
 
 g3 
function (n = 1e+05) { 
orig - c(rep(, n), rep(, 2 * n), rep(, 3 * 
n), rep(, 4 * n)) 
orig.unique - unique(orig) 
names(orig.unique) - orig.unique 
time - system.time(df - data.frame(check.names=FALSE, outer(orig, 
orig.unique, function(x, y) as.numeric(x==y 
list(time = time, df = df) 
}

 g3(1e5)$time 
   user  system elapsed 
   1.020.000.97 
 
When you want to optimize code it is often handy to write functions like this 
to do the timing for various problem sizes.  You can quickly experiment with 
small versions of the problem to make sure the results are correct and the time 
looks reasonable and later see if the times scale up as hoped to your desired 
problem size.

__
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] splitting a factor column into binary columns for each factor

2010-01-26 Thread Chuck White
Yesterday I posted the following question (my apologies for not putting a 
subject line):

=question==
Hello -- I would like to know of a more efficient way of writing the following 
piece of code. Thanks. 

options(stringsAsFactors=FALSE) 
orig -  c(rep('',10),rep('',20),rep(''  
,30),rep('',40)) 
orig.unique - unique(orig) 
system.time(df - as.data.frame(sapply(orig.unique,  function(x) 
ifelse(orig==x, 1, 0


I received a response via e-mail which was **extremely** useful.

=answer==
Using sapply instead of lapply here is a waste.  sapply() calls lapply(), which 
returns a list that sapply() turns into a list by making each list element a 
column of the matrix.  data.frame(matrix) then makes a list from the columns of 
the matrix.

The one thing that sapply gives you and lapply doesn't is column names.  If you 
attach names to orig.unique then lapply's output will have them. 
 
Also ifelse(orig==x,1,0) slower than the equivalent as.numeric(orig==x).  I 
wrote functions g0 (containing your code), g1 (using lapply), and g2 
(ifelse-as.numeric).  I parameterized them by the number of '111' elements 
and they each return the data.frame created and the time it took to do it:

 g0
function(n = 1e+05) { 
  orig - c(rep(, n), rep(, 2*n), rep(, 3*n), 
rep(, 4*n)) 
  orig.unique - unique(orig) 
  time - system.time(df - as.data.frame(sapply(orig.unique, function(x) 
ifelse(orig == x, 1, 0 
  list(time = time, df = df) 
} 

 g1
function (n = 1e+05)  { 
  orig - c(rep(, n), rep(, 2*n), rep(, 3*n), 
rep(, 4*n)) 
  orig.unique - unique(orig)
  names(orig.unique) - orig.unique 
  time - system.time(df - data.frame(check.names=FALSE, lapply(orig.unique, 
function(x) ifelse(orig == x, 1, 0 
  list(time = time, df = df) 
}

 g2 
function (n = 1e+05) { 
  orig - c(rep(, n), rep(, 2*n), rep(, 3*n), 
rep(, 4*n)) 
  orig.unique - unique(orig) 
  names(orig.unique) - orig.unique 
  time - system.time(df - data.frame(check.names=FALSE, lapply(orig.unique, 
function(x) as.numeric(orig == x 
  list(time = time, df = df) 
} 
 
For n=10^5 the times were 
 g0(1e5)$time 
   user  system elapsed 
  20.650.41   20.64 
 g1(1e5)$time 
   user  system elapsed 
   2.350.052.36 
 g2(1e5)$time 
   user  system elapsed 
   0.730.100.77 
and the data.frames each produced were identical. 
 
Another approach is to use outer() to make a matrix that gets passed to 
data.frame().  It seems slightly slower than g2, but small changes might make 
it faster.
 
 g3 
function (n = 1e+05) { 
orig - c(rep(, n), rep(, 2 * n), rep(, 3 * 
n), rep(, 4 * n)) 
orig.unique - unique(orig) 
names(orig.unique) - orig.unique 
time - system.time(df - data.frame(check.names=FALSE, outer(orig, 
orig.unique, function(x, y) as.numeric(x==y 
list(time = time, df = df) 
}

 g3(1e5)$time 
   user  system elapsed 
   1.020.000.97 
 
When you want to optimize code it is often handy to write functions like this 
to do the timing for various problem sizes.  You can quickly experiment with 
small versions of the problem to make sure the results are correct and the time 
looks reasonable and later see if the times scale up as hoped to your desired 
problem size.

__
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] splitting a factor column into binary columns for each level

2010-01-26 Thread Chuck White
Yesterday I posted the following question (my apologies for not putting a 
subject line):

=question==
Hello -- I would like to know of a more efficient way of writing the following 
piece of code. Thanks. 

options(stringsAsFactors=FALSE) 
orig -  c(rep('',10),rep('',20),rep(''  
,30),rep('',40)) 
orig.unique - unique(orig) 
system.time(df - as.data.frame(sapply(orig.unique,  function(x) 
ifelse(orig==x, 1, 0


I received a response via e-mail which was **extremely** useful.

=answer==
Using sapply instead of lapply here is a waste.  sapply() calls lapply(), which 
returns a list that sapply() turns into a list by making each list element a 
column of the matrix.  data.frame(matrix) then makes a list from the columns of 
the matrix.

The one thing that sapply gives you and lapply doesn't is column names.  If you 
attach names to orig.unique then lapply's output will have them. 
 
Also ifelse(orig==x,1,0) slower than the equivalent as.numeric(orig==x).  I 
wrote functions g0 (containing your code), g1 (using lapply), and g2 
(ifelse-as.numeric).  I parameterized them by the number of '111' elements 
and they each return the data.frame created and the time it took to do it:

 g0
function(n = 1e+05) { 
  orig - c(rep(, n), rep(, 2*n), rep(, 3*n), 
rep(, 4*n)) 
  orig.unique - unique(orig) 
  time - system.time(df - as.data.frame(sapply(orig.unique, function(x) 
ifelse(orig == x, 1, 0 
  list(time = time, df = df) 
} 

 g1
function (n = 1e+05)  { 
  orig - c(rep(, n), rep(, 2*n), rep(, 3*n), 
rep(, 4*n)) 
  orig.unique - unique(orig)
  names(orig.unique) - orig.unique 
  time - system.time(df - data.frame(check.names=FALSE, lapply(orig.unique, 
function(x) ifelse(orig == x, 1, 0 
  list(time = time, df = df) 
}

 g2 
function (n = 1e+05) { 
  orig - c(rep(, n), rep(, 2*n), rep(, 3*n), 
rep(, 4*n)) 
  orig.unique - unique(orig) 
  names(orig.unique) - orig.unique 
  time - system.time(df - data.frame(check.names=FALSE, lapply(orig.unique, 
function(x) as.numeric(orig == x 
  list(time = time, df = df) 
} 
 
For n=10^5 the times were 
 g0(1e5)$time 
   user  system elapsed 
  20.650.41   20.64 
 g1(1e5)$time 
   user  system elapsed 
   2.350.052.36 
 g2(1e5)$time 
   user  system elapsed 
   0.730.100.77 
and the data.frames each produced were identical. 
 
Another approach is to use outer() to make a matrix that gets passed to 
data.frame().  It seems slightly slower than g2, but small changes might make 
it faster.
 
 g3 
function (n = 1e+05) { 
orig - c(rep(, n), rep(, 2 * n), rep(, 3 * 
n), rep(, 4 * n)) 
orig.unique - unique(orig) 
names(orig.unique) - orig.unique 
time - system.time(df - data.frame(check.names=FALSE, outer(orig, 
orig.unique, function(x, y) as.numeric(x==y 
list(time = time, df = df) 
}

 g3(1e5)$time 
   user  system elapsed 
   1.020.000.97 
 
When you want to optimize code it is often handy to write functions like this 
to do the timing for various problem sizes.  You can quickly experiment with 
small versions of the problem to make sure the results are correct and the time 
looks reasonable and later see if the times scale up as hoped to your desired 
problem size.

__
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] tapply and more than one function, with different arguments

2010-01-26 Thread RINNER Heinrich
Hi Dennis,
now that's a very nice function, and this seems to be just what I need!
Thanks a lot!
-Heinrich.

Von: Dennis Murphy [djmu...@gmail.com]
Gesendet: Dienstag, 26. Januar 2010 19:44
An: RINNER Heinrich
Cc: r-help
Betreff: Re: [R] tapply and more than one function, with different arguments

Hi:

Using the plyr package, we can get the result as follows:

 library(plyr)
 my.fun - function(x, mult) mult*sum(x)
 dat - data.frame(x = 1:4, grp = c(a,a,b,b))
 ddply(dat, .(grp), summarize, max = max(x), myfun = my.fun(x, 10))
  grp max myfun
1   a   230
2   b   470

HTH,
Dennis

On Tue, Jan 26, 2010 at 8:26 AM, RINNER Heinrich 
heinrich.rin...@tirol.gv.atmailto:heinrich.rin...@tirol.gv.at wrote:
Dear R-users,

I am working with R version 2.10.1.

Say I have is a simple function like this:

 my.fun - function(x, mult) mult*sum(x)

Now, I want to apply this function along with some other (say 'max') to a 
simple data.frame, like:

 dat - data.frame(x = 1:4, grp = c(a,a,b,b))

Ideally, the result would look something like this (if mult = 10):
 max my.fun
a   2 30
b   4 70

I have tried it that way:

apply.more.functions - function(dat, FUN = c(max, my.fun), ...) {
 res - NULL
 for(f in FUN) res[[f]] - tapply(dat$x, dat$grp, FUN = f, ...)
 data.frame(res)
}

# let's test it:
 apply.more.functions(dat, FUN = c(max, min))
 max min
a   2   1
b   4   3
# perfect!

# now, with an additional argument:
 apply.more.functions(dat, FUN = c(max, my.fun), mult = 10)
 max my.fun
a  10 30
b  10 70
# uhuh!
Apparently, 'mult' has been used in the calculation of 'max' as well.
How can I modify apply.more.functions in order to avoid this?

Your advice would be appreciated;
Kind regards
Heinrich.

__
R-help@r-project.orgmailto: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] Trouble Highlighting outliers on Time Series Plot

2010-01-26 Thread Idgarad
I am having trouble plotting outliers on time series.

Give then following code:

# find STL Outliers by weight and append sh2, use Robust
# this should allow the initial outliers to be filtered
# this section may be commented out.

tsSourceDiag - stl(tsSource,s.window=per, robust=TRUE)
#
tsSourceIO - which(tsSourceDiag $ weights   1e-8)
#
# This is how to append run-time regessors
for(z in tsSourceIO) {
tmpname -paste(PreIO,z,sep=)
#COPY EOM REGRESSOR AS A TEMPLATE
sh2[[tmpname]] - sh2[[EOM]]
#SET IT ALL TO 0
sh2[[tmpname]][]-FALSE
#SET The Proper Indice to TRUE
sh2[[tmpname]][z]- TRUE
}
Ok so I have a time series tsSource. I yank out the index of each
tsSourceDiag and appending it to an existing list of regressors with all
false save one that is true for the index of the suspected outlier.

I decided that a plot of the time series as points was in order and thought,
Hey I should really fill the circle that is considered an outlier red so I
can eye ball check the graph to see if that is indeed an outlier needing
agent Fox and Scully to investigate (yes my later list of outliers is in
fact called XFILES).

So I am like, BOOM! plot(tsSource) and points(tsSource[tsSourceIO]). Nada.

A plot of tsSource[tsSourceIO] reveals a hint of what is wrong. tsSource is
as time series with date info while tsSource[tsSourceIO] is just a series
with no proper alignment with the cosmic universe... errr... I mean time
series.

Anyone have some sweet voodoo on how to get a proper time series plot while
properly overplotting various indicies? (e.g. tsSeries[c=(1,22,11,61)])

[[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] Strange tick in ggplot geom_area; and ordering, again

2010-01-26 Thread hadley wickham
 can you also reproduce the “triangles” problem? Is it just a trivial 
 corollary of the order-bug?

The triangles are there because you have a layer of points (from the
qplot default) and layer of areas.  Setting geom = area in qplot
fixes that.

Hadley

-- 
http://had.co.nz/

__
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] Strange tick in ggplot geom_area; and ordering, again

2010-01-26 Thread hadley wickham

 In case you have a temporary workaround, it would be nice to have it. It’s a 
 show stopper for my report. Bars are not an option, because the curve looks 
 too jaggy.


I just remember that to work around the problem, you can just manually
order the data frame:

cf1 - cf1[with(cf1, order(dur, score, decreasing = T)), ]
qplot(dur,p,data=cf1, fill=score, order = rev(score), geom = area)

Hadley


-- 
http://had.co.nz/

__
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] Apply a function on an array with the parameter as an array

2010-01-26 Thread anna

Ok, I read the entire posting guide and updated my signature. So I come back
on my question, should I use an apply in an apply to make this?

-
Anna Lippel
-- 
View this message in context: 
http://n4.nabble.com/Apply-a-function-on-an-array-with-the-parameter-as-an-array-tp1310834p1310922.html
Sent from the R help mailing list archive at Nabble.com.

__
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] problems saving an mpfr object into a file

2010-01-26 Thread kayj

Hi All,

I have a problem cbind two vectors one is a numeric and the other is an 
mpfr object and then saving the result into a .csv file. I am unable to save
the mpfr vector into .csv file . here is the error that I get

Error in as.data.frame.default(x[[i]], optional = TRUE) : 
  cannot coerce class mpfr1 into a data.frame


any ideas?

Thanks for the help

-- 
View this message in context: 
http://n4.nabble.com/problems-saving-an-mpfr-object-into-a-file-tp1310857p1310857.html
Sent from the R help mailing list archive at Nabble.com.

__
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] large integers in R

2010-01-26 Thread Blanford, Glenn
Has there been any update on R's handling large integers greater than 10^9 
(between 10^9 and 4x10^9) ?

as.integer() in R 2.9.2 lists this as a restriction but doesnt list the actual 
limit or cause, nor if anyone was looking at fixing it.

Glenn D Blanford, PhD
mailto:glenn.blanf...@us.army.mil
Scientific Research Corporation
gblanf...@scires.commailto:gblanf...@scires.com


[[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] large integers in R

2010-01-26 Thread Duncan Murdoch

On 26/01/2010 3:25 PM, Blanford, Glenn wrote:

Has there been any update on R's handling large integers greater than 10^9 
(between 10^9 and 4x10^9) ?

as.integer() in R 2.9.2 lists this as a restriction but doesnt list the actual 
limit or cause, nor if anyone was looking at fixing it.


Integers in R are 4 byte signed integers, so the upper limit is 2^31-1. 
 That's not likely to change soon.


The double type in R can hold exact integer values up to around 2^52. 
So for example calculations like this work fine:


 x - 2^50
 y - x + 1
 y-x
[1] 1

Just don't ask R to put those values into a 4 byte integer, they won't fit:

 as.integer(c(x,y))
[1] NA NA
Warning message:
NAs introduced by coercion

Duncan Murdoch



Glenn D Blanford, PhD
mailto:glenn.blanf...@us.army.mil
Scientific Research Corporation
gblanf...@scires.commailto:gblanf...@scires.com


[[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-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] Install R 2.10.1 on Windows XP Errors

2010-01-26 Thread Steve_Friedman

I have just upgraded from 2.9.2 to 2.10.1 on my XP machine.

I rec'd the following error message:

Error in strsplit(x[ok], [.-]) :
  5 arguments passed to .Internal(strsplit) which requires 6

I also tried update.packages(checkBuilt=TRUE, ask = FALSE)

 update.packages(checkBuilt=TRUE, ask=FALSE)
Error: could not find function update.packages

Has anyone else experienced this - what is the fix ?

Thanks in advance.

Steve Friedman Ph. D.
Spatial Statistical Analyst
Everglades and Dry Tortugas National Park
950 N Krome Ave (3rd Floor)
Homestead, Florida 33034

steve_fried...@nps.gov
Office (305) 224 - 4282
Fax (305) 224 - 4147

__
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] Apply a function on an array with the parameter as an array

2010-01-26 Thread jim holtman
You can do something like this:

lapply(1:nrow(X), function(.indx, param){
X[.indx,] * param[.indx]  # apply param[i] to row i of X
}, param=arrayOf Params)


On Tue, Jan 26, 2010 at 3:52 PM, anna lippelann...@hotmail.com wrote:

 Ok, I read the entire posting guide and updated my signature. So I come back
 on my question, should I use an apply in an apply to make this?

 -
 Anna Lippel
 --
 View this message in context: 
 http://n4.nabble.com/Apply-a-function-on-an-array-with-the-parameter-as-an-array-tp1310834p1310922.html
 Sent from the R help mailing list archive at Nabble.com.

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




-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem that you are trying to solve?

__
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] Install R 2.10.1 on Windows XP Errors

2010-01-26 Thread Uwe Ligges



On 26.01.2010 22:09, steve_fried...@nps.gov wrote:


I have just upgraded from 2.9.2 to 2.10.1 on my XP machine.

I rec'd the following error message:

Error in strsplit(x[ok], [.-]) :
   5 arguments passed to .Internal(strsplit) which requires 6

I also tried update.packages(checkBuilt=TRUE, ask = FALSE)


update.packages(checkBuilt=TRUE, ask=FALSE)

Error: could not find function update.packages

Has anyone else experienced this - what is the fix ?




The fix is not to mix up base packages for old versions of R that you 
have in some library in your search path with a new version of R.


Best wishes,
Uwe Ligges





Thanks in advance.

Steve Friedman Ph. D.
Spatial Statistical Analyst
Everglades and Dry Tortugas National Park
950 N Krome Ave (3rd Floor)
Homestead, Florida 33034

steve_fried...@nps.gov
Office (305) 224 - 4282
Fax (305) 224 - 4147

__
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] ANCOVA with measurement error in x and y

2010-01-26 Thread Dylan Beaudette
Hi,

I am looking for some tips on how to incorporate known measurement error into 
the comparison of slopes in an analysis of covariance. Specifically, if I 
know that each measurement comes with a 5% error, is it possible to 'expand' 
the confidence intervals around the estimates for the slope of the line 
passing through the data defined by the grouping variable? With standard 
linear regression the confidence intervals are probably too narrow for the 
slope and intercept estimates.

# example data:
# these are measured with error, by an analytical machine

x.1 - rnorm(100, mean=1, sd=1)
x.2 - rnorm(100, mean=1, sd=1)
y.1 - (x.1 / 9) + rnorm(100, mean=0, sd=0.05)
y.2 - (x.2 / 11) + rnorm(100, mean=0, sd=0.05)

# combine and add group labels
d - rbind(data.frame(x=x.1, y=y.1), data.frame(x=x.2, y=y.2))
d$id - gl(n=2, k=100, labels=c('run 1', 'run 2'))

# plot:
library(lattice)
xyplot(y ~ x, data=d, groups=id, type=c('p','r'))

# ANCOVA
summary(l - lm(y ~ x * id, data=d))

# plot confidence intervals
dotplot(confint(l), col=1, xlab='95% Conf. Int.')

Is there any way to tell if these two populations have different slopes, given 
the measurement errors?

Thanks in advance,
Dylan

-- 
Dylan Beaudette
Soil Resource Laboratory
http://casoilresource.lawr.ucdavis.edu/
University of California at Davis
530.754.7341

__
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] add points to 3D plot using p3d {onion}

2010-01-26 Thread Bradley Christoffersen
Hi,

Can anyone guide me as to how I can add points to a p3d() plot from
the onion package?  I want to plot points with different colors on the
same 3D plot.  Perhaps I can do this without adding points but somehow
directing the 'h' parameter to give different color to points based on
a factor I assign to them?

FYI, I can do this using using scatterplot3d() and points3d(), but
these plots lack perspective and hence it is hard to sense depth
without the use of color.

Thanks,
Brad

__
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] unidentifiable problem..

2010-01-26 Thread Jonathan
Hi All,
My R installation is acting strangely and I'm hoping somebody might have
an idea what's going on:

I can't seem to load the RMySQL function.  It seems to have installed
without a problem, but when I enter:

library(RMySQL)

R tells me:
Error in utils::readRegistry(SOFTWARE\\MySQL AB, hive = HLM, maxdepth =
2) :
  Registry key 'SOFTWARE\MySQL AB' not found
Error : .onLoad failed in 'loadNamespace' for 'RMySQL'
Error: package/namespace load failed for 'RMySQL'


Moreover,
If I try to get information about a function (fisher exact test, for
example) by typing:
?fisher.test

R tells me:
Error in shell.exec(url) :
  access to 'http://127.0.0.1:12625/library/stats/html/fisher.test.html'
denied
If I manually open, in a web browser, the html file whose address is given,
I can see and read the document.

I'm wondering whether there is some kind of problem with the registry (any
ideas at all welcome).

Thanks,
Jon

[[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] unidentifiable problem..

2010-01-26 Thread Duncan Murdoch

On 26/01/2010 4:54 PM, Jonathan wrote:

Hi All,
My R installation is acting strangely and I'm hoping somebody might have
an idea what's going on:


You need to give more details.  Which R version?  (If less than 2.10.1, 
install that and try again.)  Do you have MySQL installed on that 
machine?  (If not, install it.) Which Windows version are you using? 
Are you able to open other URLs from R, e.g. does


browseURL(http://www.r-project.org;)

work?

Duncan Murdoch



I can't seem to load the RMySQL function.  It seems to have installed
without a problem, but when I enter:

library(RMySQL)

R tells me:
Error in utils::readRegistry(SOFTWARE\\MySQL AB, hive = HLM, maxdepth =
2) :
  Registry key 'SOFTWARE\MySQL AB' not found
Error : .onLoad failed in 'loadNamespace' for 'RMySQL'
Error: package/namespace load failed for 'RMySQL'


Moreover,
If I try to get information about a function (fisher exact test, for
example) by typing:
?fisher.test

R tells me:
Error in shell.exec(url) :
  access to 'http://127.0.0.1:12625/library/stats/html/fisher.test.html'
denied
If I manually open, in a web browser, the html file whose address is given,
I can see and read the document.

I'm wondering whether there is some kind of problem with the registry (any
ideas at all welcome).

Thanks,
Jon

[[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-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] library.dynam

2010-01-26 Thread Murat Tasan
hi, i'm having some trouble getting a package to load a shared library
object in .onLoad(...)

i have a shared object file, say mylib.so.

if i start an R session, and via the CLI specify the actual library
via:
 dyn.load(mylib.so)
everything works quite well (i.e. i can then follow with some .Call
(...) methods)

now, i'd like to include this shared library in my package.
assume that the .c file has already been compiled and i have the .so
file at some PATH.
in my zzz.R file i include:

.onLoad - function(libname, pkgname) {
  library.dynam(mylib, lib.loc = PATH)
}

when i load the package, however, i get:

Error in .find.package(package, lib.loc, verbose = verbose) :
  there are no packages called 'RCurl', 'bitops', 'rjson', 'stats',
'graphics', 'grDevices', 'utils', 'datasets', 'methods', 'base'

so it appears i need to specify the package name, so if i change the
call to:

  library.dynam(mylib, pkgname, lib.loc = PATH), i get:

Error in .find.package(package, lib.loc, verbose = verbose) :
  there is no package called 'mypackage'
Error : .onLoad failed in 'loadNamespace' for 'mypackage'

which makes sense because the package namespace isn't attached yet.
so i'm not really sure what to specify for the package parameter of
library.dynam.

i've elected to try to use library.dynam() instead of useDynLib() in
the NAMESPACE file because this is a VERY customized package and the
library i'm using will change often enough and will probably be placed
in a non-standard location on the user's system.

ideas?

__
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] library.dynam

2010-01-26 Thread Murat Tasan
to clarify the example a bit, assume that for lib.loc i always want to
search the current working directory of the R session (thus forcing
the user to have mylib.so sitting in the directory returned by getwd()
when loading the package).

NOTE: this is not how i will finally implement this package, but is a
temporary requirement for my writing this package for some colleagues.


On Jan 26, 5:16 pm, Murat Tasan mmu...@gmail.com wrote:
 hi, i'm having some trouble getting a package to load a shared library
 object in .onLoad(...)

 i have a shared object file, say mylib.so.

 if i start an R session, and via the CLI specify the actual library
 via: dyn.load(mylib.so)

 everything works quite well (i.e. i can then follow with some .Call
 (...) methods)

 now, i'd like to include this shared library in my package.
 assume that the .c file has already been compiled and i have the .so
 file at some PATH.
 in my zzz.R file i include:

 .onLoad - function(libname, pkgname) {
   library.dynam(mylib, lib.loc = PATH)

 }

 when i load the package, however, i get:

 Error in .find.package(package, lib.loc, verbose = verbose) :
   there are no packages called 'RCurl', 'bitops', 'rjson', 'stats',
 'graphics', 'grDevices', 'utils', 'datasets', 'methods', 'base'

 so it appears i need to specify the package name, so if i change the
 call to:

   library.dynam(mylib, pkgname, lib.loc = PATH), i get:

 Error in .find.package(package, lib.loc, verbose = verbose) :
   there is no package called 'mypackage'
 Error : .onLoad failed in 'loadNamespace' for 'mypackage'

 which makes sense because the package namespace isn't attached yet.
 so i'm not really sure what to specify for the package parameter of
 library.dynam.

 i've elected to try to use library.dynam() instead of useDynLib() in
 the NAMESPACE file because this is a VERY customized package and the
 library i'm using will change often enough and will probably be placed
 in a non-standard location on the user's system.

 ideas?

 __
 r-h...@r-project.org mailing listhttps://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guidehttp://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.


Re: [R] heatmap.2 color range

2010-01-26 Thread evgeny55

thanks, 
I think I got the color ranges down, however, I just realized that the
colors don't match the data.  When I execute:
grad - ifelse(randMat  5,yelPal,ifelse(randMat1.5,redPal,bluPal))
the grad matrix contains the correct hex codes corresponding to the randMat
data matrix  but when I run:

heatmap(randMat, Rowv=NA, Colv=NA, col = grad, scale=none,
margins=c(5,10))

The colors displayed don't match up.  I'm not sure if it's re-ordering the
data somehow but I'm not getting any warning or errors and can't find any
similiar postings.
-- 
View this message in context: 
http://n4.nabble.com/heatmap-2-color-range-tp1293498p1311023.html
Sent from the R help mailing list archive at Nabble.com.

__
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] heatmap.2 color range

2010-01-26 Thread evgeny55

also, can you point me to some example of how to omit colors from a palette
-- 
View this message in context: 
http://n4.nabble.com/heatmap-2-color-range-tp1293498p1311031.html
Sent from the R help mailing list archive at Nabble.com.

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


  1   2   >