[R] Problem storing lm() model in a list

2010-12-04 Thread Harold Pimentel
Hi all,

I recently wrote some code to store a number of polynomial models in a list and 
return this list. The model is returned fine, but when I make a subsequent call 
to predict(), I have an error. The code for polyModel selection is listed at 
the end of the email. Here is an example of the error:

 poly.fit - polyModelSelection(x,y,10,F)
 for (d in 1:4) {
+ lm.model - poly.fit$models[[d]]
+ curve(predict(lm.model,data.frame(x)),add=T,lty=d+1)
+ }
Error: variable 'poly(x, d, raw = T)' was fitted with type nmatrix.1 but type 
nmatrix.10 was supplied

Does anyone have any ideas? 



Thanks,

Harold




polyModelSelection - function(x,y,maxd,add.dim=F) {
dim.mult - 0
if (add.dim) {
dim.mult = 1
}
bestD - 1
bestError - 1
loss - 1
lm.models - vector(list,maxd)
for (d in 1:maxd) {
lm.mod - lm(y ~ 0 + poly(x,d,raw=T))
lm.models[[d]] - lm.mod
loss[d] - modelError(lm.mod,data.frame(x),y)+d*dim.mult
if (d == 1){
bestError - loss[d]
}
if (loss[d]  bestError) {
bestError - loss[d]
bestD - d
}
# print(loss[d])
}
list(loss=loss,models=lm.models,best=c(bestD))
}

modelError - function(model,x,y) {
sum((y-predict(model,x))^2)
}
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Non-visible functions: merge.data.table

2010-12-04 Thread Ryan Garner

Thanks Jim! I posted the specifics of what I'm trying to accomplish here:
http://r.789695.n4.nabble.com/Slow-Data-Table-Merge-td3072027.html
-- 
View this message in context: 
http://r.789695.n4.nabble.com/Non-visible-functions-merge-data-table-tp3072051p3072075.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] Nash Equilibrium

2010-12-04 Thread Christophe Dutang
Hello all,

Months ago, when I wanted to compute Nash equilibria (both standard and 
generalized), I only found one package that implements the discrete, i.e. when 
the player payoff is represented by a matrix. So I decided to implement the 
computation when the payoff is a continuous payoff, generally on a compact set.

The project NE computation is available on R-forge 
(https://r-forge.r-project.org/R/?group_id=860), there is one package called 
GNE computing generalized Nash Equilibria.

Two days ago, I commit a first stable and documented version. Please download 
the binary from the R packages tab. The package depends on the alabama 
package, which depends also on numDeriv. So you need to download these two 
packages as well. 

Once loaded, ?GNE is an overview of the package. I put 3 examples of GNE in the 
man page taken from von Heusinger  Kanzow (2009). 

Christophe  

PS: send me an email if you have problems with the functions.

Le 4 déc. 2010 à 00:25, Ravi Varadhan a écrit :

 I think Christophe Dutang is writing a package for generalized Nash
 Equilibria models called GNE.
 
 I am cc'ing him here.  
 
 I don't know if there are other packages out there.  Christophe would know.
 
 Ravi.
 
 ---
 Ravi Varadhan, Ph.D.
 Assistant Professor,
 Division of Geriatric Medicine and Gerontology School of Medicine Johns
 Hopkins University
 
 Ph. (410) 502-2619
 email: rvarad...@jhmi.edu
 
 
 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On
 Behalf Of ivo welch
 Sent: Friday, December 03, 2010 5:40 PM
 To: r-help
 Subject: [R] Nash Equilibrium
 
 Dear R experts:
 
 I searched cran (and r-help) for nash equilibrium and game but
 nothing stuck out.  has someone written a numerical nash optimizer for
 two players?
 
 player a has choices x1,x2,x3,... and cares about (maximizes)
 pa(x1,x2,x3,...,y1,y2,y3)
 player b has choices y1,y2,y3,..., and cares about (maximizes)
 pb(x1,x2,x3,...,y1,y2,y3)
 
 I can tune it to my problem, but if someone has already invented this,
 please point me to it, so that I do not have to reinvent the wheel.
 
 regards,
 
 /iaw
 
 
 Ivo Welch (ivo.we...@brown.edu, ivo.we...@gmail.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.
 

--
Christophe Dutang
Ph.D. student at ISFA, Lyon, France
website: http://dutangc.free.fr

__
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] Question about #1 zoo-faq

2010-12-04 Thread Alexander Salim
Hi all,

I have a zoo object issue. When I create a zoo object I have following error
message: some methods for 'zoo' objects do not work if the index entries in
'order.by' are not unique.

I checked if I have some duplicates in the 'Time' column, R says yes, but
when I check the data set I can't explain why. Here is the code.

 

 sum(duplicated(dataSet1$Time))

[1] 5

 x - which(duplicated(dataSet1$Time))

 dataSet1[x,]

Time fkl010z0 tre200s0 gre000z0 prestas0 rre150z0
tde200s0 ure200s0

4046 2009-03-29 02:10:00  0.5  3.00942.10
1.9 92.7

4047 2009-03-29 02:20:00  0.3  2.70942.10
1.7 93.4

4048 2009-03-29 02:30:00  0.6  2.80942.20
1.8 92.9

4049 2009-03-29 02:40:00  0.4  2.80942.30
1.6 92.0

4050 2009-03-29 02:50:00  0.8  2.80942.20
1.6 92.1

 

 

Enclosed is a dput file with the data set.

 

Thank you for your help.

 

Regards,

Alex

__
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 about #1 zoo-faq

2010-12-04 Thread Gabor Grothendieck
On Sat, Dec 4, 2010 at 5:40 AM, Alexander Salim sa...@gmx.ch wrote:
 Hi all,

 I have a zoo object issue. When I create a zoo object I have following error
 message: some methods for 'zoo' objects do not work if the index entries in
 'order.by' are not unique.

 I checked if I have some duplicates in the 'Time' column, R says yes, but
 when I check the data set I can't explain why. Here is the code.



 sum(duplicated(dataSet1$Time))

 [1] 5

 x - which(duplicated(dataSet1$Time))

 dataSet1[x,]

                    Time fkl010z0 tre200s0 gre000z0 prestas0 rre150z0
 tde200s0 ure200s0

 4046 2009-03-29 02:10:00      0.5      3.0        0    942.1        0
 1.9     92.7

 4047 2009-03-29 02:20:00      0.3      2.7        0    942.1        0
 1.7     93.4

 4048 2009-03-29 02:30:00      0.6      2.8        0    942.2        0
 1.8     92.9

 4049 2009-03-29 02:40:00      0.4      2.8        0    942.3        0
 1.6     92.0

 4050 2009-03-29 02:50:00      0.8      2.8        0    942.2        0
 1.6     92.1





 Enclosed is a dput file with the data set.


There is nothing attached.  Try again putting the dput output in the
body of your email or else make sure the attached file is a text file
with the extension .txt .


-- 
Statistics  Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.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] Question about #1 zoo-faq

2010-12-04 Thread Duncan Murdoch

On 04/12/2010 5:40 AM, Alexander Salim wrote:

Hi all,

I have a zoo object issue. When I create a zoo object I have following error
message: some methods for 'zoo' objects do not work if the index entries in
'order.by' are not unique.

I checked if I have some duplicates in the 'Time' column, R says yes, but
when I check the data set I can't explain why. Here is the code.


Remember that duplicated() doesn't return TRUE for all copies, only the 
second (and later ones).  For example,


duplicated(c(1,1,2,2,1))

returns

[1] FALSE  TRUE FALSE  TRUE  TRUE

I believe the %in% operator works on zoo objects, so you can see all 
copies using


x - with(dataSet1, Time %in% Time[duplicated(Time)])
dataSet1[x,]

Duncan Murdoch






sum(duplicated(dataSet1$Time))


[1] 5


x- which(duplicated(dataSet1$Time))



dataSet1[x,]


 Time fkl010z0 tre200s0 gre000z0 prestas0 rre150z0
tde200s0 ure200s0

4046 2009-03-29 02:10:00  0.5  3.00942.10
1.9 92.7

4047 2009-03-29 02:20:00  0.3  2.70942.10
1.7 93.4

4048 2009-03-29 02:30:00  0.6  2.80942.20
1.8 92.9

4049 2009-03-29 02:40:00  0.4  2.80942.30
1.6 92.0

4050 2009-03-29 02:50:00  0.8  2.80942.20
1.6 92.1







Enclosed is a dput file with the data set.



Thank you for your help.



Regards,

Alex




__
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] scale caption on levelplot

2010-12-04 Thread Andrew Collier
hi,

i am trying to figure out how to put a caption on the colour scale of a
levelplot. there does not seem to be an option for this in levelplot().
i tried using mtext() but as soon as you put the text far out enough on
the right of the plot, it goes beyond the plot boundary. so i tried to
extend the margin on the right of the plot using par(mar) but this did
not have any effect on the plot area.

i would really appreciate some help with this because having a caption
on a colour scale is rather fundamental and certainly something that a
journal referee is going to pick up on!

best regards,
andrew.


-- 
Andrew B. Collier

Physicist
Waves and Space Plasmas Group
Hermanus Magnetic Observatory

Honorary Senior Lecturer tel: +27 31 2601157
Space Physics Research Institute fax: +27 31 2607795
University of KwaZulu-Natal, Durban, South Africagsm: +27 83 3813655

__
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] Nash Equilibrium

2010-12-04 Thread Ravi Varadhan

Hi Christophe,

Aren't you also using fixed-point acceleration schemes (from the SQUAREM 
package) for solving the Nash equilibria?  

How does fixed-point acceleration approach compare to the optimization approach 
in terms of speed and robustness (i.e. convergence from bad starting values)?

Ravi.


Ravi Varadhan, Ph.D.
Assistant Professor,
Division of Geriatric Medicine and Gerontology
School of Medicine
Johns Hopkins University

Ph. (410) 502-2619
email: rvarad...@jhmi.edu


- Original Message -
From: Christophe Dutang duta...@gmail.com
Date: Saturday, December 4, 2010 5:09 am
Subject: Re: [R] Nash Equilibrium
To: Ravi Varadhan rvarad...@jhmi.edu, ivo welch ivo...@gmail.com
Cc: r-help r-h...@stat.math.ethz.ch


 Hello all,
 
 Months ago, when I wanted to compute Nash equilibria (both standard 
 and generalized), I only found one package that implements the 
 discrete, i.e. when the player payoff is represented by a matrix. So I 
 decided to implement the computation when the payoff is a continuous 
 payoff, generally on a compact set.
 
 The project NE computation is available on R-forge (, there is one 
 package called GNE computing generalized Nash Equilibria.
 
 Two days ago, I commit a first stable and documented version. Please 
 download the binary from the R packages tab. The package depends on 
 the alabama package, which depends also on numDeriv. So you need to 
 download these two packages as well. 
 
 Once loaded, ?GNE is an overview of the package. I put 3 examples of 
 GNE in the man page taken from von Heusinger  Kanzow (2009). 
 
 Christophe  
 
 PS: send me an email if you have problems with the functions.
 
 Le 4 déc. 2010 à 00:25, Ravi Varadhan a écrit :
 
  I think Christophe Dutang is writing a package for generalized Nash
  Equilibria models called GNE.
  
  I am cc'ing him here.  
  
  I don't know if there are other packages out there.  Christophe 
 would know.
  
  Ravi.
  
  ---
  Ravi Varadhan, Ph.D.
  Assistant Professor,
  Division of Geriatric Medicine and Gerontology School of Medicine Johns
  Hopkins University
  
  Ph. (410) 502-2619
  email: rvarad...@jhmi.edu
  
  
  -Original Message-
  From: r-help-boun...@r-project.org [ On
  Behalf Of ivo welch
  Sent: Friday, December 03, 2010 5:40 PM
  To: r-help
  Subject: [R] Nash Equilibrium
  
  Dear R experts:
  
  I searched cran (and r-help) for nash equilibrium and game but
  nothing stuck out.  has someone written a numerical nash optimizer for
  two players?
  
  player a has choices x1,x2,x3,... and cares about (maximizes)
  pa(x1,x2,x3,...,y1,y2,y3)
  player b has choices y1,y2,y3,..., and cares about (maximizes)
  pb(x1,x2,x3,...,y1,y2,y3)
  
  I can tune it to my problem, but if someone has already invented this,
  please point me to it, so that I do not have to reinvent the wheel.
  
  regards,
  
  /iaw
  
  
  Ivo Welch (ivo.we...@brown.edu, ivo.we...@gmail.com)
  
  __
  R-help@r-project.org mailing list
  
  PLEASE do read the posting guide 
  and provide commented, minimal, self-contained, reproducible code.
  
 
 --
 Christophe Dutang
 Ph.D. student at ISFA, Lyon, France
 website: 
 
 
 
 
 


__
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] Nash Equilibrium

2010-12-04 Thread Christophe Dutang
Finally, I decided not to depends on SQUAREM, which I used for testing. 
Nevertherless extrapolation methods for fixed point iteration are at least 
twice faster than the crude fixed-point iteration or other relaxation methods. 
Later I would like to do a real benchmark of all methods, not just fixed-point 
iterations.

Christophe

Le 4 déc. 2010 à 15:49, Ravi Varadhan a écrit :

 
 Hi Christophe,
 
 Aren't you also using fixed-point acceleration schemes (from the SQUAREM 
 package) for solving the Nash equilibria?  
 
 How does fixed-point acceleration approach compare to the optimization 
 approach in terms of speed and robustness (i.e. convergence from bad starting 
 values)?
 
 Ravi.
 
 
 Ravi Varadhan, Ph.D.
 Assistant Professor,
 Division of Geriatric Medicine and Gerontology
 School of Medicine
 Johns Hopkins University
 
 Ph. (410) 502-2619
 email: rvarad...@jhmi.edu
 
 
 - Original Message -
 From: Christophe Dutang duta...@gmail.com
 Date: Saturday, December 4, 2010 5:09 am
 Subject: Re: [R] Nash Equilibrium
 To: Ravi Varadhan rvarad...@jhmi.edu, ivo welch ivo...@gmail.com
 Cc: r-help r-h...@stat.math.ethz.ch
 
 
 Hello all,
 
 Months ago, when I wanted to compute Nash equilibria (both standard 
 and generalized), I only found one package that implements the 
 discrete, i.e. when the player payoff is represented by a matrix. So I 
 decided to implement the computation when the payoff is a continuous 
 payoff, generally on a compact set.
 
 The project NE computation is available on R-forge (, there is one 
 package called GNE computing generalized Nash Equilibria.
 
 Two days ago, I commit a first stable and documented version. Please 
 download the binary from the R packages tab. The package depends on 
 the alabama package, which depends also on numDeriv. So you need to 
 download these two packages as well. 
 
 Once loaded, ?GNE is an overview of the package. I put 3 examples of 
 GNE in the man page taken from von Heusinger  Kanzow (2009). 
 
 Christophe  
 
 PS: send me an email if you have problems with the functions.
 
 Le 4 déc. 2010 à 00:25, Ravi Varadhan a écrit :
 
 I think Christophe Dutang is writing a package for generalized Nash
 Equilibria models called GNE.
 
 I am cc'ing him here.  
 
 I don't know if there are other packages out there.  Christophe 
 would know.
 
 Ravi.
 
 ---
 Ravi Varadhan, Ph.D.
 Assistant Professor,
 Division of Geriatric Medicine and Gerontology School of Medicine Johns
 Hopkins University
 
 Ph. (410) 502-2619
 email: rvarad...@jhmi.edu
 
 
 -Original Message-
 From: r-help-boun...@r-project.org [ On
 Behalf Of ivo welch
 Sent: Friday, December 03, 2010 5:40 PM
 To: r-help
 Subject: [R] Nash Equilibrium
 
 Dear R experts:
 
 I searched cran (and r-help) for nash equilibrium and game but
 nothing stuck out.  has someone written a numerical nash optimizer for
 two players?
 
 player a has choices x1,x2,x3,... and cares about (maximizes)
 pa(x1,x2,x3,...,y1,y2,y3)
 player b has choices y1,y2,y3,..., and cares about (maximizes)
 pb(x1,x2,x3,...,y1,y2,y3)
 
 I can tune it to my problem, but if someone has already invented this,
 please point me to it, so that I do not have to reinvent the wheel.
 
 regards,
 
 /iaw
 
 
 Ivo Welch (ivo.we...@brown.edu, ivo.we...@gmail.com)
 
 __
 R-help@r-project.org mailing list
 
 PLEASE do read the posting guide 
 and provide commented, minimal, self-contained, reproducible code.
 
 
 --
 Christophe Dutang
 Ph.D. student at ISFA, Lyon, France
 website: 
 
 
 
 
 
 

--
Christophe Dutang
Ph.D. student at ISFA, Lyon, France
website: http://dutangc.free.fr

__
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] Nash Equilibrium

2010-12-04 Thread Paul Smith
On Sat, Dec 4, 2010 at 10:09 AM, Christophe Dutang duta...@gmail.com wrote:
 Months ago, when I wanted to compute Nash equilibria (both standard and 
 generalized), I only found one package that implements the discrete, i.e. 
 when the player payoff is represented by a matrix.

Could you please tell us which R package solves matrix games?

Paul

__
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] Add columns of dataset

2010-12-04 Thread Lisa

Your R script works very well. Thank you very much.

Lisa
-- 
View this message in context: 
http://r.789695.n4.nabble.com/Add-columns-of-dataset-tp3071722p3072513.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] scale caption on levelplot

2010-12-04 Thread David Winsemius


On Dec 4, 2010, at 8:25 AM, Andrew Collier wrote:


hi,

i am trying to figure out how to put a caption on the colour scale  
of a
levelplot. there does not seem to be an option for this in  
levelplot().


Agreed. I could not find one in the levelplot help page or in the  
chapter of Lattice on legends and keys. Sarkar basically says you need  
to use grid calls if you want to go beyond the basics.


i tried using mtext() but as soon as you put the text far out enough  
on

the right of the plot, it goes beyond the plot boundary. so i tried to
extend the margin on the right of the plot using par(mar) but this did
not have any effect on the plot area.

i would really appreciate some help with this because having a caption
on a colour scale is rather fundamental and certainly something that a
journal referee is going to pick up on!


Your question has no reproducible example but suggests that you do not  
understand that levelplot is a lattice function and that lattice uses  
grid graphics. The par arguments that lattice understands (or is  
willing to deal with gracefully) are passed through trellis.par.set().  
The current settings are accessible with:


trellis.par.get()

 Since lattice is implemented with grid graphics, you may get useful  
information from:


require(grid)   # lattice apparently loads gpar and its help page but  
doesn't

# actually load grid. (I don't understand this. )
?gpar()   # Which has examples that may allow you to get a better  
understanding
  # of how to layer new material on top of existing grid  
graphics.


--

David Winsemius, MD
West Hartford, CT

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


Re: [R] Downloading quote data from yahoo finance

2010-12-04 Thread Joshua Ulrich
On Wed, Dec 1, 2010 at 11:15 PM, Deb Midya debmi...@yahoo.com wrote:
 Hi R users,

 Thanks in advance.

 I am using R 2.12.0 on Windows XP.

 May I request you to assist me in the following please.

 1. I am getting error while downloading quote data from yahoo finance.

 The example code is below (taken from tseries help):

 library(tseries)

 con - url(http://quote.yahoo.com;)
 if(!inherits(try(open(con), silent = TRUE), try-error)) {
   close(con)
   x - get.hist.quote(instrument = ^gspc, start = 1998-01-01,
   quote = Close)
   plot(x)
   x - get.hist.quote(instrument = ibm, quote = c(Cl, Vol))
   plot(x, main = International Business Machines Corp)
   spc - get.hist.quote(instrument = ^gspc, start = 1998-01-01,
  quote = Close)
   ibm - get.hist.quote(instrument = ibm,  start = 1998-01-01,
  quote = AdjClose)
   x - merge(spc, ibm)
   plot(x, main = IBM vs SP 500)
   x - get.hist.quote(instrument = EUR/USD, provider = oanda,
   start = Sys.Date() - 500)
   plot(x, main = EUR/USD)
 }

 Error message:

 Warning message:
 In open.connection(con) :
   unable to connect to 'quote.yahoo.com' on port 80.

The example works for me.  Are you behind a firewall or proxy?

 2. How can I download Key Statistics Data from Yahoo Finance

 A. http://finance.yahoo.com/

 B. ASH.AX (Using GET QUOTES)

 C. Key Statistics

 How can I download Key Statistics dynamically (Using R code)

library(quantmod)
getFinancials(IBM)
viewFinancials(IBM.f)


 Thank you very much for the time you have given.

 Regards,

 Deb




Hope that helps,
--
Joshua Ulrich  |  FOSS Trading: www.fosstrading.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 in calcCurveGrob(x, x$debug) : End points must not be identical

2010-12-04 Thread Bryan Hanson
Hi All... I haven¹t found mention of this error anywhere.  I'm trying to
draw spline curves using grid graphics.  Most of the time, I have no
problems, but I have some data sets that give the error in the subject line.
I'm not sure which end points are identical, but the end points passed to
the function are definitely not identical.

Any assistance appreciated!  Bryan

tst -
structure(list(x.st = c(-1, -2, -3, -1, -1.5, -3, -1.5, -1.5,
-8, -1, -1.5, -1, -1.5, -2, -1.5, -2, -1, -1.5, -2), y.st =
c(1.73205080756888,
3.46410161513776, 5.19615242270663, 1.73205080756888, 2.59807621135332,
5.19615242270663, 2.59807621135332, 2.59807621135332, 13.8564064605510,
1.73205080756888, 2.59807621135332, 1.73205080756888, 2.59807621135332,
3.46410161513776, 2.59807621135332, 3.46410161513776, 1.73205080756888,
2.59807621135332, 3.46410161513776), x.end = c(-6.5, -6.5, -6.5,
-4, -4, -4, -1.5, -1, -1, -1.5, -1.5, -2, -2, -2, -3, -3, -8,
-8, -8), y.end = c(-11.2583302491977, -11.2583302491977, -11.2583302491977,
-6.92820323027551, -6.92820323027551, -6.92820323027551, -2.59807621135332,
1.73205080756888, 1.73205080756888, 2.59807621135332, 2.59807621135332,
3.46410161513776, 3.46410161513776, 3.46410161513776, 5.19615242270663,
5.19615242270663, 13.8564064605510, 13.8564064605510, 13.8564064605510
), grp = c(3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
3, 3), lwd = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 3, 1, 1, 1,
2, 5, 2)), .Names = c(x.st, y.st, x.end, y.end, grp,
lwd), row.names = 34:52, class = data.frame)

grid.newpage()
vp - viewport(width = 0.9, height = 0.9, x = 0.5, y = 0.5)
pushViewport(vp)
grid.rect(gp = gpar(lty = dashed, col = gray))
grid.points(0.5, 0.5, pch = 20, gp = gpar(cex = 0.5))
grid.curve(tst$x.st, tst$y.st, tst$x.end, tst$y.end,
default.units = native)

###
 sessionInfo()
R version 2.12.0 (2010-10-15)
Platform: x86_64-apple-darwin9.8.0/x86_64 (64-bit)

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

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

other attached packages:
 [1] gridExtra_0.7  GGally_0.2.2   xtable_1.5-6
 [4] mvbutils_2.5.1 ggplot2_0.8.8  proto_0.3-8
 [7] reshape_0.8.3  ChemoSpec_1.46 seriation_1.0-2
[10] colorspace_1.0-1   TSP_1.0-1  R.utils_1.5.3
[13] R.oo_1.7.4 R.methodsS3_1.2.1  rgl_0.92.794
[16] lattice_0.19-13mvoutlier_1.4  plyr_1.2.1
[19] RColorBrewer_1.0-2 chemometrics_1.0   som_0.3-5
[22] robustbase_0.5-0-1 rpart_3.1-46   pls_2.1-0
[25] pcaPP_1.8-3mvtnorm_0.9-92 nnet_7.3-1
[28] mclust_3.4.6   MASS_7.3-8 lars_0.9-7
[31] gclus_1.3  cluster_1.13.1 e1071_1.5-24
[34] class_7.3-2   
 

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


[R] Quadratic programming with semi-definite matrix

2010-12-04 Thread Andreas Jensen
Hello.

I'm trying to solve a quadratic programming problem of the form min
||Hx - y||^2 s.t. x = 0 and x = t using solve.QP in the quadprog
package but I'm having problems with Dmat not being positive definite,
which is kinda okay since I expect it to be numerically semi-definite
in most cases. As far as I'm aware the problem arises because the
Goldfarb and Idnani method first solves the unconstrained problem
requiring a positive definite matrix. Are there any (fast) packages
that allows me to do QP with (large) semidefinite matrices?

Example:
t - 100
y - signalConvNoisy[1,]
D - crossprod(H,H)
d - crossprod(H,y)
A - cbind(rep(-1, nrow(H)), diag(ncol(H)))
b0 - c(t, rep(0, ncol(H)))
sol - solve.QP(Dmat=D, dvec = d, Amat = A, bvec = b0)$solution
Error in solve.QP(Dmat = D, dvec = d, Amat = A, bvec = b0) :
  matrix D in quadratic function is not positive definite!

Thanks in advance,
Andreas Jensen

__
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] what is this averaging function called ?, has R a built in function for it ?

2010-12-04 Thread madr

I know little of statistics and have created this function out of intuition.
But since this algorithm is so basic I wonder what is the proper name of
this function and is it build in R.

here is some code in PHP to illustrate what the function is doing, it uses
some function I created but the meaning is obvious:

#get csv file and interchange rows with columns to get two arrays
$csv = aic(getcsv(file_get_contents(out.csv)));
#now those arrays contained in one bigger array are sorted
array_multisort($csv[0],SORT_NUMERIC,$csv[1],SORT_NUMERIC);

#second array is created and values that will be put on x or 0 axis are made
unique with every y or 1
# value is going into array under x/0 it will be used after to make mean
arithmetic, geometric or harmonic
foreach ($csv[0] as $k=$x) {
$sum[$x][] = $csv[1][$k];
}

#the x values are put on other array for later use
$x = array_keys($sum);
$rang = $sum = array_values($sum);

#and here is the key feature, to smooth the line the function looks for (in
this case) 500 values above and beond given value
# if they exist of course, the search stops when search goes outside the
array
# the search also stop when number of gathered values goes beyond 500 or
next value that would be added will be making
# this value more than 500, you can imagine that there could be a large
spike in data and this would be affecting points near
# if this precaution haven't been conceived
foreach ($rang as $k=$v) {
if (!($k % 100)) echo $k.' ';
$up = $down = array();
$walk = 0;
while (true) {
++$walk;
if (isset($sum[$k-$walk]) and
count($v)+count($up)+count($sum[$k-$walk])500)
$up = array_merge($up,$sum[$k-$walk]);
else break;
}
$walk = 0;
while (true) {
++$walk;
if (isset($sum[$k+$walk]) and
count($v)+count($down)+count($sum[$k+$walk])500)
$down = array_merge($down,$sum[$k+$walk]);
else break;
}

$rang[$k] = array_merge($up,$rang[$k],$down);
# after gathering data for given point it makes a mean, in this case
arithmetic
$rang[$k] = array_sum($rang[$k])/count($rang[$k]);
}
# now the array with x values can be added and fipped array is ready to go
to a file
$csv = aic(array($x,$rang));

# in php this is awfully slow but I like it because it is sensitive for the
densiti of the data and to not goes away in strange
# directions when data density becomes very low
-- 
View this message in context: 
http://r.789695.n4.nabble.com/what-is-this-averaging-function-called-has-R-a-built-in-function-for-it-tp3072826p3072826.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] Downloading quote data from yahoo finance

2010-12-04 Thread Mike Marchywka







 From: josh.m.ulr...@gmail.com
 Date: Sat, 4 Dec 2010 14:47:45 -0600
 To: debmi...@yahoo.com
 CC: r-help@r-project.org
 Subject: Re: [R] Downloading quote data from yahoo finance

 On Wed, Dec 1, 2010 at 11:15 PM, Deb Midya  wrote:
  Hi R users,
 
  Thanks in advance.
 

 
  May I request you to assist me in the following please.
 
  1. I am getting error while downloading quote data from yahoo finance.
 
  The example code is below (taken from tseries help):
 
  library(tseries)
 
  con - url(http://quote.yahoo.com;)
  if(!inherits(try(open(con), silent = TRUE), try-error)) {
close(con)
x - get.hist.quote(instrument = ^gspc, start = 1998-01-01,
quote = Close)
plot(x)
x - get.hist.quote(instrument = ibm, quote = c(Cl, Vol))
plot(x, main = International Business Machines Corp)
spc - get.hist.quote(instrument = ^gspc, start = 1998-01-01,
   quote = Close)
ibm - get.hist.quote(instrument = ibm,  start = 1998-01-01,
   quote = AdjClose)
x - merge(spc, ibm)
plot(x, main = IBM vs SP 500)
x - get.hist.quote(instrument = EUR/USD, provider = oanda,
start = Sys.Date() - 500)
plot(x, main = EUR/USD)
  }
 
  Error message:
 
  Warning message:
  In open.connection(con) :
unable to connect to 'quote.yahoo.com' on port 80.
 
 The example works for me. Are you behind a firewall or proxy?

  2. How can I download Key Statistics Data from Yahoo Finance
 
  A. http://finance.yahoo.com/
 
  B. ASH.AX (Using GET QUOTES)
 
  C. Key Statistics
 
  How can I download Key Statistics dynamically (Using R code)
 
 library(quantmod)
 getFinancials(IBM)
 viewFinancials(IBM.f)


Does this R code talk to yhoo for real time or historical
data? I'm surprised there is a package dedicated to 
specific specialized data sources although if the package itself
is as the name implies then code for even scraping html
from some sources may be a nice feature. The reason I ask
is that the SEC is going to more stuctured submissions,

http://xbrl.sec.gov/

and I was curious if anyone has related code
for collating fundamental information such
as this. In one of my rants, I suggested that real
estate transactions be revealed in a similar machine
readable format, a large R constituency would
help make that case more persuasive :)

Commercial downloads are not usually stable enough
for reference from automated packages
although I have lots of my own private
scripts for stuff like that, even scraping data
from adversarial commercial and public sites. 



Thanks.







 
  Thank you very much for the time you have given.
 
  Regards,
 
  Deb
 
 
 

 Hope that helps,
 --
 Joshua Ulrich | FOSS Trading: www.fosstrading.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.


Re: [R] scale caption on levelplot

2010-12-04 Thread Peter Ehlers

Andrew,
see below

On 2010-12-04 08:25, David Winsemius wrote:


On Dec 4, 2010, at 8:25 AM, Andrew Collier wrote:


hi,

i am trying to figure out how to put a caption on the colour scale
of a
levelplot. there does not seem to be an option for this in
levelplot().


Agreed. I could not find one in the levelplot help page or in the
chapter of Lattice on legends and keys. Sarkar basically says you need
to use grid calls if you want to go beyond the basics.


i tried using mtext() but as soon as you put the text far out enough
on
the right of the plot, it goes beyond the plot boundary. so i tried to
extend the margin on the right of the plot using par(mar) but this did
not have any effect on the plot area.

i would really appreciate some help with this because having a caption
on a colour scale is rather fundamental and certainly something that a
journal referee is going to pick up on!


Your question has no reproducible example but suggests that you do not
understand that levelplot is a lattice function and that lattice uses
grid graphics. The par arguments that lattice understands (or is
willing to deal with gracefully) are passed through trellis.par.set().
The current settings are accessible with:

trellis.par.get()

   Since lattice is implemented with grid graphics, you may get useful
information from:

require(grid)   # lattice apparently loads gpar and its help page but
doesn't
  # actually load grid. (I don't understand this. )
?gpar()   # Which has examples that may allow you to get a better
understanding
# of how to layer new material on top of existing grid
graphics.


As David says, you need to use trellis parameters, in this case
presumably trellis.par.get('layout.widths') and
trellis.par.get('layout.heights') will be useful. You can add
appropriate settings to your levelplot() call with the
par.settings argument. After you adjust the amount of space
you want, you can then use grid::grid.text() to add your text.
Here's an example:

  library(grid)
  x - sort(rnorm(100,50,10))
  y - sort(runif(100,0,20))
  d - expand.grid(x=x, y=y)
  d$z - x + y
  graphics.off()
  p - levelplot(z ~ x*y, d,
par.settings=list(
  layout.widths=list(right.padding=4),
  layout.heights=list(top.padding=6)),
colorkey = TRUE)
  print(p)

  ## now add the text
  grid.text('here and there', x=.98, y=.5, rot=-90,
gp = gpar(col=4,
fontfamily=HersheyGothicEnglish, cex=2))
  grid.text('here\nand\nthere', x=.88, y=.92,
gp = gpar(lineheight=.75, col=3))

Peter Ehlers

__
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 with diff(sqrt()) function in terms of time series

2010-12-04 Thread Addi Wei

year1 is the time series data set below
11.64
11.50
11.49
11.16
11.15
11.37
11.37
11.57
11.83
11.87
11.85
11.92
11.77
11.71
11.57
11.24
11.27
11.33
11.17
.

With a total of 1304 rows of data.

When I try to run the code:
diff(sqrt(year10))
I get the response: data frame with 0 columns and 1304 rows and then I
subsequently try to convert my data into a time series with the following
function:
 yearstate = ts(diff(sqrt(year10)))
 yearstate
Time Series:
Start = 1 
End = 1304 
Frequency = 1 

   1
   2
   3
   4
   5
all the way to 1304.  So, it basically erased all of my previous
data, and the data are just row numbers all the way to 1304...  Any help
would be appreciated.  I tried my best to produce actual code.  
-- 
View this message in context: 
http://r.789695.n4.nabble.com/Help-with-diff-sqrt-function-in-terms-of-time-series-tp3072877p3072877.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] data.table query

2010-12-04 Thread Dennis Murphy
Hi:

dt[, mean(A), by = 'B']
 B   V1
[1,] 1 1.00
[2,] 2 1.67
[3,] 3 2.33
[4,] 4 3.00

...and I can see you've found the data.table mailing list...

HTH,
Dennis

On Fri, Dec 3, 2010 at 3:38 PM, Santosh Srinivas santosh.srini...@gmail.com
 wrote:

 Hello Group,

 I need a modification in the data.table example to get my intended
 result shown below ... is there a more simple way!

 dt - data.table(A = rep(1:3, each=4), B = rep(1:4, each=3), C = rep(1:2,
 6))
 dt[, transform(.SD,D=mean(A)), by=B]


 The result I want is below ... which is probably long winded!

 data.table(unique(as.data.frame(dt[, transform(.SD,D=mean(A)),
 by=B][,list(B,D)])))
 BD
 [1,] 1 1.00
 [2,] 2 1.67
 [3,] 3 2.33
 [4,] 4 3.00

 Thank you.

 __
 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] latex tables for 3+ dimensional tables/arrays

2010-12-04 Thread Michael Friendly

Hi Rich,
I was looking for something that I could make general, as a latex.ftable
method for ftable objects.  I realize you showed how to do this for a
particular case, but I'm having a bit of trouble translating this into
a general solution for 1 or more row variables and 1 or more col variables.

This is most likely because latex() offers a bewildering collection
of arguments I don't fully understand how to apply in this case.

Here is my current sketch, with test cases below, one of which fails...

latex.ftable - function(object, numeric.dollar=FALSE,  ...) {
  cv - attr(object,col.vars)
  rv - attr(object,row.vars)
  ncv - length(cv)
  nrv - length(rv)
  colheads - cv[[1]]
  cgroup - if (ncv1) cv[[1]] else NULL
  rowname - rv[[2]]
  rgroup - if (nrv1) rv[[1]] else NULL
  latex.default(object, colheads=colheads, rowname=rowname,
cgroup=cgroup, rgroup=rgroup, numeric.dollar=numeric.dollar, ...)
}

 ft - ftable(UCBAdmissions)
 ft
Dept   A   B   C   D   E   F
AdmitGender
Admitted Male512 353 120 138  53  22
 Female   89  17 202 131  94  24
Rejected Male313 207 205 279 138 351
 Female   19   8 391 244 299 317
 str(ft)
 ftable [1:4, 1:6] 512 89 313 19 353 17 207 8 120 202 ...
 - attr(*, row.vars)=List of 2
  ..$ Admit : chr [1:2] Admitted Rejected
  ..$ Gender: chr [1:2] Male Female
 - attr(*, col.vars)=List of 1
  ..$ Dept: chr [1:6] A B C D ...


 latex(ft, file=)
% latex.default(object, colheads = colheads, rowname = rowname, 
cgroup = cgroup, rgroup = rgroup, numeric.dollar = numeric.dollar, 
...)

%
\begin{table}[!tbp]
 \begin{center}
 \begin{tabular}{lrr}\hline\hline
\multicolumn{1}{l}{object}\multicolumn{1}{c}{A}\multicolumn{1}{c}{B}\multicolumn{1}{c}{C}\multicolumn{1}{c}{D}\multicolumn{1}{c}{E}\multicolumn{1}{c}{F}\tabularnewline
\hline
{\bfseries Admitted}\tabularnewline
~~Male512353120138 53 22\tabularnewline
~~Female 89 17202131 94 24\tabularnewline
\hline
{\bfseries Rejected}\tabularnewline
~~Male313207205279138351\tabularnewline
~~Female 19  8391244299317\tabularnewline
\hline
\end{tabular}

\end{center}

 ft1 - ftable(UCBAdmissions, col.vars=2:3)
 ft1
 Gender Male Female
 Dept  A   B   C   D   E   F  A   B   C   D   E   F
Admit
Admitted 512 353 120 138  53  22 89  17 202 131  94  24
Rejected 313 207 205 279 138 351 19   8 391 244 299 317

 latex(ft1, file=)
Error in rv[[2]] : subscript out of bounds


On 12/2/2010 5:24 PM, RICHARD M. HEIBERGER wrote:

Michael,

I think this is what you are looking for.
Rich



library(Hmisc)
tmp- array(rnorm(60), c(3,4,5),
list(letters[1:3],LETTERS[4:7],letters[8:12]))
## latex(tmp)
ftable(tmp)
dviname- latex(ftable(tmp))
ft- ftable(tmp)
dviname- latex(ft,
  colheads=attr(ft,col.vars)[[1]],
  rowname=attr(ft,row.vars)[[2]],
  rgroup=attr(ft,row.vars)[[1]],
  n.rgroup=c(4,4,4))

[[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] how to debug (mtrace) a function defined inside a function?

2010-12-04 Thread MarkBravington

Hi Andre

Just saw your email; I'm the author of the 'debug' package but I don't
subscribe to R-help, so it's best to email me directly with questions about
'debug' or 'mvbutils'.

The quick answer is that you can either: 

 -  mtrace( mymodel), then after it has executed the 'build -
function()...' line, type 
mtrace( build) at the prompt

 - or you can insert the line below into your code of mymodel, so that you
won't need to step thru mymodel when it exectues. You could put an 'if'
statement based on a global variable if you want to be able to control
debugging behaviour globally.

HTH
Mark Bravington (mark dot bravington at csiro dot au)

mymodel-function(){
 data-numeric(0)
 build-function(){
   data-1
 }
 
  ## Add this:
  mtrace( build)

 m-list()
 m$build-build
 m
} 
-- 
View this message in context: 
http://r.789695.n4.nabble.com/how-to-debug-mtrace-a-function-defined-inside-a-function-tp3019781p3072957.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] bandplot

2010-12-04 Thread Nasrin Pak
Hi;

 I'm trying to use bandplot function. I've installed the gplots package but
still the function is not found in R. what's the problem?

-- 
Sincerely

Nasrin  Pak

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

2010-12-04 Thread David Winsemius


On Dec 4, 2010, at 8:56 PM, Nasrin Pak wrote:


Hi;

I'm trying to use bandplot function. I've installed the gplots  
package but

still the function is not found in R. what's the problem?


That usually means you have not yet loaded it. Try one of:

library(gplots)
require(gplots)

--

David Winsemius, MD
West Hartford, CT

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


[R] grep for strings

2010-12-04 Thread Santosh Srinivas
I am trying to find the function where I can search for a pattern in a
text string (I thought I could use grep for this but no :().

 x
[1] abcdefghijkl

I want to find the positions (i.e. equivalent of nchar) for cd and
in case there are multiple hits .. then the results as a array

Thank you.

__
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] grep for strings

2010-12-04 Thread Charles C. Berry

On Sun, 5 Dec 2010, Santosh Srinivas wrote:


I am trying to find the function where I can search for a pattern in a
text string (I thought I could use grep for this but no :().


Correct, but reading

?grep

and running

example( grep )

should show you how to do that search.




x

[1] abcdefghijkl

I want to find the positions (i.e. equivalent of nchar) for cd and
in case there are multiple hits .. then the results as a array


You will need to deal with the possibility that there are more 'cd's in 
some elements of 'text' than in others.


So, it is not obvious that an _array_ will work without some special 
tooling.


HTH,

Chuck





Thank you.

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



Charles C. BerryDept of Family/Preventive Medicine
cbe...@tajo.ucsd.eduUC San Diego
http://famprevmed.ucsd.edu/faculty/cberry/  La Jolla, San Diego 92093-0901

__
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] grep for strings

2010-12-04 Thread jim holtman
 x - abcdefghijkl
 ?regexpr
starting httpd help server ... done
 regexpr('cd', x)
[1] 3
attr(,match.length)
[1] 2



On Sat, Dec 4, 2010 at 9:34 PM, Santosh Srinivas
santosh.srini...@gmail.com wrote:
 I am trying to find the function where I can search for a pattern in a
 text string (I thought I could use grep for this but no :().

 x
 [1] abcdefghijkl

 I want to find the positions (i.e. equivalent of nchar) for cd and
 in case there are multiple hits .. then the results as a array

 Thank you.

 __
 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
Data Munger Guru

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] scale caption on levelplot

2010-12-04 Thread Andrew Collier
hi peter and david,

thanks for the excellent suggestions. here is something like what i am
finally using (those fancy fonts were really tempting, but i chose
something a little more mundane!):

library(lattice)

x - sort(rnorm(100,50,10))
y - sort(runif(100,0,20))
d - expand.grid(x=x, y=y)
d$z - x + y
plot.new()
p = levelplot(z ~ x*y, d,
   par.settings=list(
 layout.widths=list(right.padding=4)),
   colorkey = TRUE)
print(p)

mtext(CAPTION, 4, 1)

your help really appreciated!

best regards,
andrew.

-- 
Andrew B. Collier

Physicist
Waves and Space Plasmas Group
Hermanus Magnetic Observatory

Honorary Senior Lecturer tel: +27 31 2601157
Space Physics Research Institute fax: +27 31 2607795
University of KwaZulu-Natal, Durban, South Africagsm: +27 83 3813655

__
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] scale caption on levelplot

2010-12-04 Thread Peter Ehlers

On 2010-12-04 21:29, Andrew Collier wrote:

hi peter and david,

thanks for the excellent suggestions. here is something like what i am
finally using (those fancy fonts were really tempting, but i chose
something a little more mundane!):

library(lattice)

x- sort(rnorm(100,50,10))
y- sort(runif(100,0,20))
d- expand.grid(x=x, y=y)
d$z- x + y
plot.new()
p = levelplot(z ~ x*y, d,
par.settings=list(
  layout.widths=list(right.padding=4)),
colorkey = TRUE)
print(p)

mtext(CAPTION, 4, 1)


Even if that worked (it doesn't for me), you're still mixing
base (or tradtional) graphics with lattice graphics. Not a
good idea. I would replace the plot.new call with

 trellis.device()

and then, after the levelplot, replace the mtext with
grid.text(...) as I suggested originally. You'll have
to fiddle a bit with the x location but that should
be easy to get the way you want.

One more thing, since you imply that this is for
publication, it's a good idea to create the plot close
to the size that will ultimately be printed; resizing
is always better avoided.

Peter Ehlers



your help really appreciated!

best regards,
andrew.



__
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] grep for strings

2010-12-04 Thread Petr Savicky
On Sun, Dec 05, 2010 at 08:04:08AM +0530, Santosh Srinivas wrote:
 I am trying to find the function where I can search for a pattern in a
 text string (I thought I could use grep for this but no :().
 
  x
 [1] abcdefghijkl
 
 I want to find the positions (i.e. equivalent of nchar) for cd and
 in case there are multiple hits .. then the results as a array

For a single string, for example

  p - gregexpr(cd, abcdecdecdcd)[[1]]

  p
  [1]  3  6  9 11
  attr(,match.length)
  [1] 2 2 2 2

  as.numeric(p) # [1]  3  6  9 11

For a vector of strings, for example

  p -  gregexpr(cd, c(abcde, acdecde, abcdecdecdcd, cdcd))
  m - max(unlist(lapply(p, length)))
  out - matrix(nrow=length(p), ncol=m)
  for (i in seq(nrow(out))) {
  out[i, seq(length(p[[i]]))] - p[[i]]
  }

  out
   [,1] [,2] [,3] [,4]
  [1,]3   NA   NA   NA
  [2,]25   NA   NA
  [3,]369   11
  [4,]13   NA   NA

Petr Savicky.

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