[R] Elegant Code

2012-03-16 Thread Raphael Fraser
Hi,

Can anyone help to write a more elegant version of my code? I am sure
this can be put into a loop but I am having trouble creating the
objects b1,b2,b3,...,etc.

b1 - rigamma(50,1,1)
theta1 - rgamma(50,0.5,(1/b1))
sim1 - rpois(50,theta1)

b2 - rigamma(50,1,1)
theta2 - rgamma(50,0.5,(1/b2))
sim2 - rpois(50,theta2)

b3 - rigamma(50,1,1)
theta3 - rgamma(50,0.5,(1/b3))
sim3 - rpois(50,theta3)

b4 - rigamma(50,1,1)
theta4 - rgamma(50,0.5,(1/b4))
sim4 - rpois(50,theta4)

b5 - rigamma(50,1,1)
theta5 - rgamma(50,0.5,(1/b5))
sim5 - rpois(50,theta5)



par(mfrow=c(1,5))
boxplot(sim1)
boxplot(sim2)
boxplot(sim3)
boxplot(sim4)
boxplot(sim5);

Thanks,
Raphael

__
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] How to interpret glmnet lasso error

2012-03-16 Thread Ryan Zotti
I get an error when I try to use glmnet to fit a lasso model on some data.

My code:
 lasso - glmnet(predictorPartitionTrainingM, targetPartitionTraining,
alpha=1)

The error that is returned:
Error in elnet(x, is.sparse, ix, jx, y, weights, offset, type.gaussian,  :
 NA/NaN/Inf in foreign function call (arg 5)

Some potentially important details:
- 50 predictor variables
- 300 observations
- everthing is numeric
- predictorPartitionTrainingM is a matrix
- targetPartitionTraining is a vector

Thanks in advance,
Ryan Zotti

[[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] Generation of correlated variables

2012-03-16 Thread Petr Savicky
On Thu, Mar 15, 2012 at 11:23:28PM -, Ted Harding wrote:
 On 15-Mar-2012 Filoche wrote:
  Hi everyone.
  
  Based on a dependent variable (y), I'm trying to generate some
  independent variables with a specified correlation. For this
  there's no problems.
  However, I would like that have all my regressors to be
  orthogonal (i.e. no correlation among them).
  
  For example, 
  
  y = x1 + x2 + x3 where the correlation between y x1 = 0.7,
  x2 = 0.4 and x3 = 0.8.  However, x1, x2 and x3 should not be
  correlated to each other.
  
  Anyone can help me?
  
  Regards,
  Phil
 
 Your fundamental problem here (with the correlations you specify)
 is the following.
 
 Your desired correlation matrix can be constructed by
 
   C - cbind( c(1.0,0.7,0.4,0.8),c(0.7,1.0,0.0,0.0),
   c(0.4,0.0,1.0,0.0),c(0.8,0.0,0.0,1.0) )
   rownames(C) - c(y,x1,x2,x3)
   colnames(C) - c(y,x1,x2,x3)
 
   C
   #  y  x1  x2  x3
   # y  1.0 0.7 0.4 0.8
   # x1 0.7 1.0 0.0 0.0
   # x2 0.4 0.0 1.0 0.0
   # x3 0.8 0.0 0.0 1.0
 
 And now:
 
   det(C)
   # [1] -0.29
 
 and it is impossible for the determinant of a correlation
 matrix to have a negative determinant: a correlation matyrix
 must be positive-semidefinite, and therefore have a non-negative
 determinant.
 
 An alternative check is to look at the eigen-structure of C:
 
   eigen(C)
   # $values
   # [1]  2.1357817  1.000  1.000 -0.1357817
   # 
   # $vectors
   #   [,1]  [,2]   [,3]   [,4]
   # [1,] 0.7071068  0.00e+00  0.000  0.7071068
   # [2,] 0.4358010 -1.172802e-16  0.7874992 -0.4358010
   # [3,] 0.2490291 -8.944272e-01 -0.2756247 -0.2490291
   # [4,] 0.4980582  4.472136e-01 -0.5512495 -0.4980582
 
 so one of the eigenvalues (-0.1357817) is negative, again
 impossible for a correlation matrix.

Thank you for this analysis. For general correlations,
say, s1, s2, s3, the matrix is

   y  x1  x2  x3

 y 1  s1  s2  s3  
 x1   s1   1   0   0
 x2   s2   0   1   0
 x3   s3   0   0   1

and its determinant is 1 - s1^2 - s2^2 - s3^2. Since there
was also a requirement that y = x1 + x2 + x3, the correlation
matrix should be singular. Hence, the required correlation
structure implies s1^2 + s2^2 + s3^2 = 1.

If this condition is satisfied, then a multivariate
distribution obtained by multiplying a vector from 
three-dimensional N(0, I) by the matrix

  (s1   s2   s3)
  (s100)
  ( 0   s20)
  ( 00   s3)

has the required correlation structure.

However, this is still not a solution of the original question,
since the original requirement was to find x1, x2, x3, when y is
given. I do not know, whether a solution for an arbitrary y exists,
even if the above condition on the correlations is satisfied.

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.


Re: [R] Elegant Code

2012-03-16 Thread Berend Hasselman

On 16-03-2012, at 08:09, Raphael Fraser wrote:

 Hi,
 
 Can anyone help to write a more elegant version of my code? I am sure
 this can be put into a loop but I am having trouble creating the
 objects b1,b2,b3,...,etc.
 
 b1 - rigamma(50,1,1)
 theta1 - rgamma(50,0.5,(1/b1))
 sim1 - rpois(50,theta1)
 
 b2 - rigamma(50,1,1)
 theta2 - rgamma(50,0.5,(1/b2))
 sim2 - rpois(50,theta2)
 
 b3 - rigamma(50,1,1)
 theta3 - rgamma(50,0.5,(1/b3))
 sim3 - rpois(50,theta3)
 
 b4 - rigamma(50,1,1)
 theta4 - rgamma(50,0.5,(1/b4))
 sim4 - rpois(50,theta4)
 
 b5 - rigamma(50,1,1)
 theta5 - rgamma(50,0.5,(1/b5))
 sim5 - rpois(50,theta5)
 
 
 
 par(mfrow=c(1,5))
 boxplot(sim1)
 boxplot(sim2)
 boxplot(sim3)
 boxplot(sim4)
 boxplot(sim5);


Not reproducible since rigamma is not a standard function.
What package?

Why store results in separate variables?
Use matrices then it become much easier.

Like this

N - 5
Nsample - 50

# temporary
rigamma - function(n,a,b) runif(n)

b - matrix(0,N*Nsample,nrow=N)
theta - matrix(0,N*Nsample,nrow=N)
sim   - matrix(0,N*Nsample,nrow=N)

for( k in 1:N ) {
b[k, ]- rigamma(Nsample, 1, 1)
theta[k,] - rgamma(Nsample,0.5,(1/b[k,]))
sim[k,]   - rpois(Nsample,theta[k,])
}

par(mfrow=c(1,N))
for( k in 1:N) boxplot(sim[k,])

Berend

__
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] Re : Elegant Code

2012-03-16 Thread Pascal Oettli
Hi Raphael,

Something like that?

require(pscl)sim - numeric()
for(i in 1:5){
  eval(parse(text=paste('b',i,' - rigamma(50,1,1)',sep='')))
  eval(parse(text=paste('theta',i,' - rgamma(50,0.5,(1/b',i,'))',sep='')))
  eval(parse(text=paste('sim',i,' - rpois(50,theta',1,')',sep='')))
  eval(parse(text=paste('sim - cbind(sim, sim',i,')',sep='')))
}
x11()
par(mfrow=c(1,5))
boxplot(c(sim1,sim2,sim3,sim4,sim5))

x11()
boxplot(sim)


Regards,
Pascal


- Mail original -
De : Raphael Fraser raphael.fra...@gmail.com
À : r-help@r-project.org
Cc : 
Envoyé le : Vendredi 16 mars 2012 16h09
Objet : [R] Elegant Code

Hi,

Can anyone help to write a more elegant version of my code? I am sure
this can be put into a loop but I am having trouble creating the
objects b1,b2,b3,...,etc.

b1 - rigamma(50,1,1)
theta1 - rgamma(50,0.5,(1/b1))
sim1 - rpois(50,theta1)

b2 - rigamma(50,1,1)
theta2 - rgamma(50,0.5,(1/b2))
sim2 - rpois(50,theta2)

b3 - rigamma(50,1,1)
theta3 - rgamma(50,0.5,(1/b3))
sim3 - rpois(50,theta3)

b4 - rigamma(50,1,1)
theta4 - rgamma(50,0.5,(1/b4))
sim4 - rpois(50,theta4)

b5 - rigamma(50,1,1)
theta5 - rgamma(50,0.5,(1/b5))
sim5 - rpois(50,theta5)



par(mfrow=c(1,5))
boxplot(sim1)
boxplot(sim2)
boxplot(sim3)
boxplot(sim4)
boxplot(sim5);

Thanks,
Raphael

__
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] How to change the number of axis?

2012-03-16 Thread Jim Lemon

On 03/16/2012 01:28 AM, qiao xue wrote:

Hi,

I use R to plot a graph with 2 frames. Because the limit of pixel
or others, the screen fail to show the graph. So I have to draw a
point every 10 frames. So the total of x axis becomes 2000.
So when imaging the picture, I still hope that the total of x-axis is
2.  I need to find a way to modify the number of axis.
How could I do this?


Hi Qiao,
Let's assume that you want a scatterplot:

# first let's indulge our secret desire to make up data
x-rnorm(2)+5*sin(seq(0.001,20,by=0.001))
# now plot this data
plot(x)
# Wow! Pretty messy. Now take the mean of every ten
# values to get a vector of 2000 values
x10-mean(x[1:10])
for(i in 2:2000) x10-c(x10,mean(x[(i*10):(i*10+9)]))
# when plotting this, add the x values, which were
# previously just made up from the length of the vector
plot(seq(1,2,by=10),x10)

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] Bar graph with 2 Y axis

2012-03-16 Thread Jim Lemon

On 03/16/2012 09:24 AM, KAYIS Seyit Ali wrote:

Dear R users,

I need to draw a barplot with 2 Y axis. I have 3 days each of wich having 2 groups (and error bar 
for each of them). The height of the 3rd day is too tall compared to others. That's why I have to 
use a second Y axis for that. I am using  barplot2 function of gplots 
library (to be able to add error bars as well). Data and  codes currently I am using is below.
...
Any help regarding adding second Y axis is deeply apprecited.


Hi Seyit,
It is fairly easy to get the bars like this:

library(plotrix)
barpos-barp(means,ylim=range(means+SEM)+c(0,4),col=2:3)
dispersion(barpos$x,barpos$y,CIU,CIL,interval=FALSE)

or even more simply:

dispersion(barpos$x,barpos$y,SEM)

I am not sure that you need an extra y axis here.

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] ncd4 package

2012-03-16 Thread Amen
Hi
I am using windows. I cant install ncdf4 package but it didn't work . any
suggestions!!


--
View this message in context: 
http://r.789695.n4.nabble.com/ncd4-package-tp4477496p4477496.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] Ggplot barchart drops factor levels: how to show them with zero counts?

2012-03-16 Thread Bart6114
To visualize my problem a little; see this screenshot 
http://i40.tinypic.com/fodsm0.png http://i40.tinypic.com/fodsm0.png .

So I would like factor level 4 to show up but without a bar (zero counts).

Thanks

--
View this message in context: 
http://r.789695.n4.nabble.com/Ggplot-barchart-drops-factor-levels-how-to-show-them-with-zero-counts-tp4475417p4477563.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] line plot over a barplot

2012-03-16 Thread Petr PIKAL
Hi

 
 Dear all,
 
 I have data in the following format :
 X-axisY-axis
 010%
 0-20  20%
 20-4030%
 40-6040%
 . and so on.
  I want to plot a bar graph of the above. Also I would want to add a
 trendline passing either through the center of each bar or through the 
top.

x-letters[1:5]
y-1:5
bb-barplot(y, names.arg=x)
lines(bb, y)
lines(bb, y/2)

 Is it also possible to get the r-squared and p-values for this 
trendline?

summary(fit-lm(y~bb))

Regards
Petr

 How do I all of the above? I would be extremely indebted by your help.
 Thanks in advance
 
 
 Regards,
 
 Anupam
 
 
 -- 
 Graduate Student,
 Laboratory of Computational Biology,
 Center For DNA Fingerprinting And Diagnostics,
 4-1-714 to 725/2, Tuljaguda complex
 Mozamzahi Road, Nampally,
 Hyderabad-51
 
[[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] ncd4 package

2012-03-16 Thread Stefan Luedtke
This one is for windows. 

http://cran.r-project.org/web/packages/RNetCDF/index.html

but you need netcdf libraries and udunits libraries installed. 

http://cran.r-project.org/web/packages/RNetCDF/INSTALL


Cheers

See the 

On Fri, 2012-03-16 at 00:39 -0700, Amen wrote: 

 Hi
 I am using windows. I cant install ncdf4 package but it didn't work . any
 suggestions!!
 
 
 --
 View this message in context: 
 http://r.789695.n4.nabble.com/ncd4-package-tp4477496p4477496.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.

[[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] Re : Elegant Code

2012-03-16 Thread Daniel Nordlund

 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
 On Behalf Of Pascal Oettli
 Sent: Friday, March 16, 2012 12:36 AM
 To: Raphael Fraser
 Cc: r-help@r-project.org
 Subject: [R] Re : Elegant Code
 
 Hi Raphael,
 
 Something like that?
 
 require(pscl)sim - numeric()
 for(i in 1:5){
   eval(parse(text=paste('b',i,' - rigamma(50,1,1)',sep='')))
   eval(parse(text=paste('theta',i,' -
 rgamma(50,0.5,(1/b',i,'))',sep='')))
   eval(parse(text=paste('sim',i,' - rpois(50,theta',1,')',sep='')))
   eval(parse(text=paste('sim - cbind(sim, sim',i,')',sep='')))
 }
 x11()
 par(mfrow=c(1,5))
 boxplot(c(sim1,sim2,sim3,sim4,sim5))
 
 x11()
 boxplot(sim)
 
 
 Regards,
 Pascal
 
 
 - Mail original -
 De : Raphael Fraser raphael.fra...@gmail.com
 À : r-help@r-project.org
 Cc :
 Envoyé le : Vendredi 16 mars 2012 16h09
 Objet : [R] Elegant Code
 
 Hi,
 
 Can anyone help to write a more elegant version of my code? I am sure
 this can be put into a loop but I am having trouble creating the
 objects b1,b2,b3,...,etc.
 
 b1 - rigamma(50,1,1)
 theta1 - rgamma(50,0.5,(1/b1))
 sim1 - rpois(50,theta1)
 
 b2 - rigamma(50,1,1)
 theta2 - rgamma(50,0.5,(1/b2))
 sim2 - rpois(50,theta2)
 
 b3 - rigamma(50,1,1)
 theta3 - rgamma(50,0.5,(1/b3))
 sim3 - rpois(50,theta3)
 
 b4 - rigamma(50,1,1)
 theta4 - rgamma(50,0.5,(1/b4))
 sim4 - rpois(50,theta4)
 
 b5 - rigamma(50,1,1)
 theta5 - rgamma(50,0.5,(1/b5))
 sim5 - rpois(50,theta5)
 
 
 
 par(mfrow=c(1,5))
 boxplot(sim1)
 boxplot(sim2)
 boxplot(sim3)
 boxplot(sim4)
 boxplot(sim5);
 
 Thanks,
 Raphael
 

Or, just get rid of the for loops altogether, something like this

trials -5
N - 50
b- rigamma(N*trials, 1, 1)
theta - rgamma(N*trials,0.5,1/b)
sim   - rpois(N*trials,theta)

dim(sim) - c(N,trials)

boxplot(sim)


Hope this is helpful,

Dan

Daniel Nordlund
Bothell, WA USA

__
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] Ggplot barchart drops factor levels: how to show them with zero counts?

2012-03-16 Thread R. Michael Weylandt
I can reproduce the OP's problem with ggplot 0.9.0 but I don't know
how to solve it: perhaps you should take this to the ggplot2 mailing
list: https://groups.google.com/group/ggplot2?pli=1

Michael

On Fri, Mar 16, 2012 at 4:17 AM, Bart6114 bartsmeet...@gmail.com wrote:
 To visualize my problem a little; see this screenshot
 http://i40.tinypic.com/fodsm0.png http://i40.tinypic.com/fodsm0.png .

 So I would like factor level 4 to show up but without a bar (zero counts).

 Thanks

 --
 View this message in context: 
 http://r.789695.n4.nabble.com/Ggplot-barchart-drops-factor-levels-how-to-show-them-with-zero-counts-tp4475417p4477563.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-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] Change in behavior of update.views()?

2012-03-16 Thread Michael Kubovy
I haven't seen this cryptic warning before:
 update.views('Robust')
Warning message:
In update.views(Robust) :
  The following packages are not available: covRobust, distr, FRB, MASS, mblm, 
multinomRob, mvoutlier, quantreg, RandVar, rgam, RobAStBase, robfilter, RobLox, 
RobRex, robust, RobustAFT, robustbase, ROptEst, ROptRegTS, rrcov, sandwich, wle
 library(covRobust)
 

It is puzzling because — as the second command shows — the package covRobust is 
installed.

Here is my
 sessionInfo()
R version 2.14.2 (2012-02-29)
Platform: x86_64-apple-darwin9.8.0/x86_64 (64-bit)

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

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

other attached packages:
[1] covRobust_1.0   ade4_1.4-17 BiocInstaller_1.2.1 ctv_0.7-4   
sos_1.3-1   brew_1.0-6  Hmisc_3.9-2 
survival_2.36-12   
[9] MASS_7.3-17

loaded via a namespace (and not attached):
[1] cluster_1.14.2 grid_2.14.2lattice_0.20-0 tools_2.14.2  


__
Professor Michael Kubovy
University of Virginia
Department of Psychology
for mail add:   for FedEx or UPS add: 
P.O.Box 400400  Gilmer Hall, Room 102
Charlottesville, VA 22904-4400  485 McCormick Road
USA Charlottesville, VA 
22903
roomphone
Office:B011 +1-434-982-4729
Lab:B019+1-434-982-4751
WWW:http://www.people.virginia.edu/~mk9y/


[[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] substituting own test statistics in a built-in function

2012-03-16 Thread Sarah Goslee
So then you need to find the code for those functions inside the source
package you downloaded, and use it to make your own functions. The authors
can't prevent you from seeing the code.

Sarah
On Mar 15, 2012 10:43 PM, Aparna Sampath aparna.sampat...@gmail.com
wrote:

 Hi Sarah Goslee

 Thanking you for replying to my doubt.

 I downloaded the multtest package from CRAN and also went through the
 package specific PDF file, they have given a list of functions which
 includes the mt.transformV, mt.checkothers etc, that I am trying to access
 which they call as the internal functions and say that these set of
 functions cannot be called by the user. and these functions perform the
 permutation part, so I need to somehow access them.

 Regards
 Ap





 On Thu, Mar 15, 2012 at 6:40 PM, Sarah Goslee sarah.gos...@gmail.comwrote:

 Hi,
 On Mar 15, 2012 4:28 AM, Aparna Sampath aparna.sampat...@gmail.com
 wrote:
 
  Hi All
 
  I would like to compute the raw p-value from permutation tests and I
 found
  mt.sample.rawp() from the package multtest almost similar to what I
 want to
  do. But in the function definition:
 
 
 mt.sample.rawp(V,classlabel,test=t,side=abs,fixed.seed.sampling=y,B=1,na=.mt.naNUM,nonpara=n)
 
  I would like to choose my own t-test which is designed using my model
  parameters, so it is like a modification of t-test. I would like to use
 this
  t-test instead of the ones in the list.  I am not sure if this can be
 done.
  Can anyone tell me how to do it, if it is possible.
 
  the other way I tried is to copy the function and and modify it.

 Indeed, that's the way to customize functions.

  But it uses
  internal functions from the package like mt.checkothers() which I do not
  know perform what kind of function. I tried to access its function
  definition, but I was not able to do so. is there some other way I
 could see
  what these internal functions do, so that I could possibly try to use
 the
  same logic and write the code.

 If you download the package source from CRAN, you'll have all of it,
 including any comments that have been stripped out.

  Appreciate all help. Thanks a lot :)
 
  Regards
  Ap
 

 Sarah




 --
 Aparna Sampath
 Master of Science (Bioinformatics)
 Nanyang Technological University
 Mob no : +65 91601854


[[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] Urgente: retiro de la lista

2012-03-16 Thread Martin Maechler
 JB == Jaime Bernal-Hadad jaib...@yahoo.com
 on Thu, 15 Mar 2012 19:11:19 -0700 writes:

JB Urgente
 

JB Dedido al gran n�mero de correos recibidos que afectan seriamente
mi trabajo, es urgente que me reitren de esta lista.  JB Alguien me
puede decir que debo hacer

JB �
JB Gracias

Por favor, hace lo Ustedes mismo:

 -- https://stat.ethz.ch/mailman/listinfo/r-help

__
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] Timer on a function

2012-03-16 Thread Prof Brian Ripley

On Thu, 15 Mar 2012, Bert Gunter wrote:


Bill et. al:

1. This is new to me. Thanks.

2. As I read the man page, this is not guaranteed to work if the model
fitting function does not contain sufficient interrupts. Is that
correct?


Yes.  If someone wrote a model fitting package in Fortran with no 
callbacks then it is not interruptible, including not by timers.  In 
that case all you can do is to kill the R session.


The author of setTimeLimit()



-- Bert

On Thu, Mar 15, 2012 at 4:14 PM, William Dunlap wdun...@tibco.com wrote:

There is a setTimeLimit function in base.  It could be encapsulated into
the following to limit the time spent on an expression:

timeOut - function (expr, ...)  {
   on.exit(setTimeLimit())
   setTimeLimit(...)
   expr
}


Using setTimeLimit(transient = TRUE) is slightly simpler here.


E.g., with the following slow way to compute Euler's phi
  f - function(n) sum(sapply(seq_len(n), function(i)1/i)) - log(n)
I get
  timeOut(f(1e5), elapsed=1)
 [1] 0.5772207
  timeOut(f(1e6), elapsed=1)
 Error in FUN(1:100[[711624L]], ...) : reached elapsed time limit
Use try() or tryCatch() to check for the error.  E.g.,
  sapply(1:7, function(n)tryCatch(timeOut(f(10^n), elapsed=1), 
error=function(e)-1))
 [1]  0.6263832  0.5822073  0.5777156  0.5772657  0.5772207 -1.000 
-1.000
You could look at 'e' in the error handler to see if it is a time out problem.

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com


-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
Behalf
Of Bert Gunter
Sent: Thursday, March 15, 2012 3:05 PM
To: Ramiro Barrantes
Cc: r-help@r-project.org
Subject: Re: [R] Timer on a function

On Thu, Mar 15, 2012 at 2:24 PM, Ramiro Barrantes
ram...@precisionbioassay.com wrote:

   Hello,

I have a program that consists of a loop fitting a function over many

models.  Sometimes the fitting on a particular model takes minutes to converge. 
 Is there
a way that I can limit the amount of time that R spends on a given model:

AFAIK, no -- this is an OS level issue.

Of course, most iterative fitting procedures have controls for the
number of iterations, convergence criteria, etc. , but there is no
awareness of timing except when the OS is interrogated, e.g. by
?proc.time or ?system.time . Such calls would have to be built into
the fitting function or OS level services would have to be invoked to
run the R process with timing limitations built in. See e.g. ?Rscript
for one possible approach.

Corrections or clever tricks to get around these perceived limitations
welcomed, of course.

-- Bert

Cheers,
Bert


say if my line is:

fittingFunction( func, model.1)

can I have some function:

stopIfUnderTime(  fittingFunction( func, model.1) , 5 )

where stopIfUnderTime will return the result if it finishes under 5 seconds, or 
NA

otherwise.


Is there anything like this?  (just looked through the web but did not find 
anything)

Thanks,
Ramiro



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




--

Bert Gunter
Genentech Nonclinical Biostatistics

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

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




--

Bert Gunter
Genentech Nonclinical Biostatistics

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

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



--
Brian D. Ripley,  rip...@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel:  +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UKFax:  +44 1865 272595__
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] multivariate regression and lm()

2012-03-16 Thread Ernest Lo
Hello,

I would like to perform a multivariate regression analysis to model the
relationship between m responses Y1, ... Ym and a single set of predictor
variables X1, ..., Xr.  Each response is assumed to follow its own
regression model, and the error terms in each model can be correlated.

Based on my readings of the R help archives and R documentation, the
function lm() should be able to perform this analysis.  However my tests of
lm() show that it really just fits m separate regression models (without
accounting for any possible correlation between the response variables).

I have attached an example below that demonstrates that the multivariate
analysis result produced by lm() is identical to running separate
regression analyses on each of the Y1, ... Ym response variables, which is
not the desired objective.

Can anyone confirm if lm() is indeed capable of performing multivariate
regression analysis, and if so how?

Thanks very much,

Ernest

PS – my post is based on an earlier 2005 post where the same question was
asked ... the conclusion at that time was that the function lm() is capable
of handling the multivariate analysis.  However my tests (shown below)
indicate that lm() actually seems to perform separate regressions for each
of the response variables without accounting for their possible correlation.


### multivariate analysis using lm() ###


 ex7.8 - data.frame(z1 = c(0, 1, 2, 3, 4), y1 = c(1, 4, 3, 8, 9), y2 =
c(-1, -1, 2, 3, 2))

 f.mlm - lm(cbind(y1, y2) ~ z1, data = ex7.8)
 summary(f.mlm)
Response y1 :

Call:
lm(formula = y1 ~ z1, data = ex7.8)

Residuals:
 1  2  3  4  5
 0  1 -2  1  0

Coefficients:
Estimate Std. Error t value Pr(|t|)
(Intercept)   1. 1.0954   0.913   0.4286
z12. 0.4472   4.472   0.0208 *
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 1.414 on 3 degrees of freedom
Multiple R-squared: 0.8696, Adjusted R-squared: 0.8261
F-statistic:20 on 1 and 3 DF,  p-value: 0.02084


Response y2 :

Call:
lm(formula = y2 ~ z1, data = ex7.8)

Residuals:
 1  2  3  4  5
-1.110e-16 -1.000e+00  1.000e+00  1.000e+00 -1.000e+00

Coefficients:
Estimate Std. Error t value Pr(|t|)
(Intercept)  -1. 0.8944  -1.118   0.3450
z11. 0.3651   2.739   0.0714 .
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 1.155 on 3 degrees of freedom
Multiple R-squared: 0.7143, Adjusted R-squared: 0.619
F-statistic:   7.5 on 1 and 3 DF,  p-value: 0.07142


### separate linear regressions on y1 and y2 ###


 f.mlm1 = lm(y1 ~ z1, data=ex7.8); summary(f.mlm1)

Call:
lm(formula = y1 ~ z1, data = ex7.8)

Residuals:
 1  2  3  4  5
 0  1 -2  1  0

Coefficients:
Estimate Std. Error t value Pr(|t|)
(Intercept)   1. 1.0954   0.913   0.4286
z12. 0.4472   4.472   0.0208 *
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 1.414 on 3 degrees of freedom
Multiple R-squared: 0.8696, Adjusted R-squared: 0.8261
F-statistic:20 on 1 and 3 DF,  p-value: 0.02084

 f.mlm2 = lm(y2 ~ z1, data=ex7.8); summary(f.mlm2)

Call:
lm(formula = y2 ~ z1, data = ex7.8)

Residuals:
 1  2  3  4  5
-1.110e-16 -1.000e+00  1.000e+00  1.000e+00 -1.000e+00

Coefficients:
Estimate Std. Error t value Pr(|t|)
(Intercept)  -1. 0.8944  -1.118   0.3450
z11. 0.3651   2.739   0.0714 .
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 1.155 on 3 degrees of freedom
Multiple R-squared: 0.7143, Adjusted R-squared: 0.619
F-statistic:   7.5 on 1 and 3 DF,  p-value: 0.07142

[[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] ncd4 package (really ncdf4)

2012-03-16 Thread Prof Brian Ripley

On Fri, 16 Mar 2012, Stefan Luedtke wrote:


This one is for windows.

http://cran.r-project.org/web/packages/RNetCDF/index.html

but you need netcdf libraries and udunits libraries installed.

http://cran.r-project.org/web/packages/RNetCDF/INSTALL


Which are the non-Windows instructions.  On Windows the libraries are 
statically linked into the binary package (and BTW, it is udunits2, 
not udunits, these days).


ncdf4 is available for Windows from the author: see 
http://cirrus.ucsd.edu/~pierce/ncdf/ . However, the author does not 
make clear that is a non-standard 32-bit-only build.  The main reason 
that there is no Windows binary on CRAN is the lack of 64-bit support.


And ncdf is also available for Windows.




Cheers

See the

On Fri, 2012-03-16 at 00:39 -0700, Amen wrote:


Hi
I am using windows. I cant install ncdf4 package but it didn't work . any
suggestions!!



--
Brian D. Ripley,  rip...@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel:  +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UKFax:  +44 1865 272595

__
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] multivariate regression and lm()

2012-03-16 Thread John Fox
Dear Ernest,

The ML estimator for the mulitvariate linear model assuming multinormal errors 
is the same as equation-by-equation LS, but multivariate tests performed for 
all of the responses on the resulting multivariate linear model object (e.g., 
by anova() or Anova() in the car package) will take the correlations of the 
responses into account.

I hope that this helps,
 John


John Fox
Sen. William McMaster Prof. of Social Statistics
Department of Sociology
McMaster University
Hamilton, Ontario, Canada
http://socserv.mcmaster.ca/jfox/

On Fri, 16 Mar 2012 07:32:02 -0400
 Ernest Lo treem...@gmail.com wrote:
 Hello,
 
 I would like to perform a multivariate regression analysis to model the
 relationship between m responses Y1, ... Ym and a single set of predictor
 variables X1, ..., Xr.  Each response is assumed to follow its own
 regression model, and the error terms in each model can be correlated.
 
 Based on my readings of the R help archives and R documentation, the
 function lm() should be able to perform this analysis.  However my tests of
 lm() show that it really just fits m separate regression models (without
 accounting for any possible correlation between the response variables).
 
 I have attached an example below that demonstrates that the multivariate
 analysis result produced by lm() is identical to running separate
 regression analyses on each of the Y1, ... Ym response variables, which is
 not the desired objective.
 
 Can anyone confirm if lm() is indeed capable of performing multivariate
 regression analysis, and if so how?
 
 Thanks very much,
 
 Ernest
 
 PS – my post is based on an earlier 2005 post where the same question was
 asked ... the conclusion at that time was that the function lm() is capable
 of handling the multivariate analysis.  However my tests (shown below)
 indicate that lm() actually seems to perform separate regressions for each
 of the response variables without accounting for their possible correlation.
 
 
 ### multivariate analysis using lm() ###
 
 
  ex7.8 - data.frame(z1 = c(0, 1, 2, 3, 4), y1 = c(1, 4, 3, 8, 9), y2 =
 c(-1, -1, 2, 3, 2))
 
  f.mlm - lm(cbind(y1, y2) ~ z1, data = ex7.8)
  summary(f.mlm)
 Response y1 :
 
 Call:
 lm(formula = y1 ~ z1, data = ex7.8)
 
 Residuals:
  1  2  3  4  5
  0  1 -2  1  0
 
 Coefficients:
 Estimate Std. Error t value Pr(|t|)
 (Intercept)   1. 1.0954   0.913   0.4286
 z12. 0.4472   4.472   0.0208 *
 ---
 Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
 
 Residual standard error: 1.414 on 3 degrees of freedom
 Multiple R-squared: 0.8696, Adjusted R-squared: 0.8261
 F-statistic:20 on 1 and 3 DF,  p-value: 0.02084
 
 
 Response y2 :
 
 Call:
 lm(formula = y2 ~ z1, data = ex7.8)
 
 Residuals:
  1  2  3  4  5
 -1.110e-16 -1.000e+00  1.000e+00  1.000e+00 -1.000e+00
 
 Coefficients:
 Estimate Std. Error t value Pr(|t|)
 (Intercept)  -1. 0.8944  -1.118   0.3450
 z11. 0.3651   2.739   0.0714 .
 ---
 Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
 
 Residual standard error: 1.155 on 3 degrees of freedom
 Multiple R-squared: 0.7143, Adjusted R-squared: 0.619
 F-statistic:   7.5 on 1 and 3 DF,  p-value: 0.07142
 
 
 ### separate linear regressions on y1 and y2 ###
 
 
  f.mlm1 = lm(y1 ~ z1, data=ex7.8); summary(f.mlm1)
 
 Call:
 lm(formula = y1 ~ z1, data = ex7.8)
 
 Residuals:
  1  2  3  4  5
  0  1 -2  1  0
 
 Coefficients:
 Estimate Std. Error t value Pr(|t|)
 (Intercept)   1. 1.0954   0.913   0.4286
 z12. 0.4472   4.472   0.0208 *
 ---
 Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
 
 Residual standard error: 1.414 on 3 degrees of freedom
 Multiple R-squared: 0.8696, Adjusted R-squared: 0.8261
 F-statistic:20 on 1 and 3 DF,  p-value: 0.02084
 
  f.mlm2 = lm(y2 ~ z1, data=ex7.8); summary(f.mlm2)
 
 Call:
 lm(formula = y2 ~ z1, data = ex7.8)
 
 Residuals:
  1  2  3  4  5
 -1.110e-16 -1.000e+00  1.000e+00  1.000e+00 -1.000e+00
 
 Coefficients:
 Estimate Std. Error t value Pr(|t|)
 (Intercept)  -1. 0.8944  -1.118   0.3450
 z11. 0.3651   2.739   0.0714 .
 ---
 Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
 
 Residual standard error: 1.155 on 3 degrees of freedom
 Multiple R-squared: 0.7143, Adjusted R-squared: 0.619
 F-statistic:   7.5 on 1 and 3 DF,  p-value: 0.07142
 
   [[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 

Re: [R] Ggplot barchart drops factor levels: how to show them with zero counts?

2012-03-16 Thread Helios de Rosario
You can tell that levels must not be dropped with scale_x_discrete():

library(ggplot2)
mtcars$cyl-factor(mtcars$cyl)
plot1 - ggplot(mtcars[!mtcars$cyl==4,], aes(cyl))+geom_bar()
plot1 + scale_x_discrete(drop=FALSE)

Or explicitly set the values you want in the x axis with the argument
limits:

plot1 + scale_x_discrete(limits=levels(mtcars$cyl))


Regards,
Helios


 El día 15/03/2012 a las 16:47, Bart6114 bartsmeet...@gmail.com
escribió:
 Hello,
 
 When plotting a barchart with ggplot it drops the levels of the
factor for
 which no counts are available.
 
 For example:
 
 library(ggplot)
 mtcars$cyl-factor(mtcars$cyl)
 ggplot(mtcars[!mtcars$cyl==4,], aes(cyl))+geom_bar()
 levels(mtcars[!mtcars$cyl==4,])
 
 This shows my problem. Because no counts are available for
factorlevel '4',
 the label 4 dissapears from the plot. However, I would still like it
to show
 up, but without a bar (zero observations).
 
 I would like to use this for the presentation of data with a
Likert-like
 scale.
 
 Thanks in advance!
 Bart
 
 --
 View this message in context: 

http://r.789695.n4.nabble.com/Ggplot-barchart-drops-factor-levels-how-to-show-the

 m-with-zero-counts-tp4475417p4475417.html
 Sent from the R help mailing list archive at Nabble.com.

INSTITUTO DE BIOMECÁNICA DE VALENCIA
Universidad Politécnica de Valencia • Edificio 9C
Camino de Vera s/n • 46022 VALENCIA (ESPAÑA)
Tel. +34 96 387 91 60 • Fax +34 96 387 91 69
www.ibv.org

  Antes de imprimir este e-mail piense bien si es necesario hacerlo.
En cumplimiento de la Ley Orgánica 15/1999 reguladora de la Protección
de Datos de Carácter Personal, le informamos de que el presente mensaje
contiene información confidencial, siendo para uso exclusivo del
destinatario arriba indicado. En caso de no ser usted el destinatario
del mismo le informamos que su recepción no le autoriza a su divulgación
o reproducción por cualquier medio, debiendo destruirlo de inmediato,
rogándole lo notifique al remitente.

__
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] ncd4 package (really ncdf4)

2012-03-16 Thread Stefan Luedtke
sorry, I did not know that, thanks!

On Fri, 2012-03-16 at 11:35 +, Prof Brian Ripley wrote: 

 On Fri, 16 Mar 2012, Stefan Luedtke wrote:
 
  This one is for windows.
 
  http://cran.r-project.org/web/packages/RNetCDF/index.html
 
  but you need netcdf libraries and udunits libraries installed.
 
  http://cran.r-project.org/web/packages/RNetCDF/INSTALL
 
 Which are the non-Windows instructions.  On Windows the libraries are 
 statically linked into the binary package (and BTW, it is udunits2, 
 not udunits, these days).
 
 ncdf4 is available for Windows from the author: see 
 http://cirrus.ucsd.edu/~pierce/ncdf/ . However, the author does not 
 make clear that is a non-standard 32-bit-only build.  The main reason 
 that there is no Windows binary on CRAN is the lack of 64-bit support.
 
 And ncdf is also available for Windows.
 
 
 
  Cheers
 
  See the
 
  On Fri, 2012-03-16 at 00:39 -0700, Amen wrote:
 
  Hi
  I am using windows. I cant install ncdf4 package but it didn't work . any
  suggestions!!
 
 

[[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] Singleton pattern

2012-03-16 Thread David Cassany
Hi all,

I know it may not have much sense thinking about a Singleton Pattern in an
R application which doesn't use any OOP facilities, however I'm curious to
know if anybody faced the same issue. I've been googling but using
singleton pattern as a key word leads to typical OOP languages like Java
or C++ among others.

So my problem is that I'd like to ensure some very big objects aren't
copied again and again in some other variables. In the worst case I'll
check all code by myself to ensure it but in this case the application
won't force programmers to take it in consideration which is what I am
really looking for.

Any advice will be highly appreciated :P

Thanks!
-- 
*David Cassany Viladomat
Software Developer
Transmural Biote**ch S.L*

[[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] Change in behavior of update.views()?

2012-03-16 Thread Achim Zeileis

On Fri, 16 Mar 2012, Michael Kubovy wrote:


I haven't seen this cryptic warning before:

update.views('Robust')

Warning message:
In update.views(Robust) :
 The following packages are not available: covRobust, distr, FRB, MASS, 
mblm, multinomRob, mvoutlier, quantreg, RandVar, rgam, RobAStBase, 
robfilter, RobLox, RobRex, robust, RobustAFT, robustbase, ROptEst, 
ROptRegTS, rrcov, sandwich, wle

library(covRobust)



It is puzzling because ? as the second command shows ? the package 
covRobust is installed.


Even though it is installed, update.views() tries to find out whether the 
installed version is the most current version.


Essentially, it does the following:
(1) Query names of packages in the task view.
(2) Query names/versions of all available.packages() in the repository.
(3) Query names/versions of all installed.packages() on the local machine.
(4) install.packages() that are either not yet installed or not current.

The error message above occurs in step (2). The available.packages() found 
with your setup include _none_ of the packages in the task view. Possibly 
this is due to the repos used or the getOption(pkgType) requested.


On my machine:

R getOption(repos)
[1] http://CRAN.R-project.org/;
R getOption(pkgType)
[1] source

And then the following works:

Step (1)

R pkgs - ctv:::.get_pkgs_from_ctv_or_repos(Robust)
R pkgs
$`http://CRAN.R-project.org/`
 [1] covRobust   distr   FRB MASSmblm
 [6] multinomRob mvoutlier   quantregRandVar rgam
[11] RobAStBase  robfilter   RobLox  RobRex  robust
[16] RobustAFT   robustbase  ROptEst ROptRegTS   rrcov
[21] sandwichwle

Step (2)

R apkgs - available.packages(contriburl = contrib.url(names(pkgs)))
R dim(apkgs)
[1] 3661   13

And for the error message ctv looks essentially at

R pkgs[[1]][ !(pkgs[[1]] %in% apkgs[,1]) ]
character(0)

I suspect that with your settings the apkgs object does not include all 
CRAN packages yet. Setting a different repos and/or a different pkgType 
should solve the problem.


hth,
Z


Here is my

sessionInfo()

R version 2.14.2 (2012-02-29)
Platform: x86_64-apple-darwin9.8.0/x86_64 (64-bit)

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

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

other attached packages:
[1] covRobust_1.0   ade4_1.4-17 BiocInstaller_1.2.1 ctv_0.7-4   
sos_1.3-1   brew_1.0-6  Hmisc_3.9-2 survival_2.36-12
[9] MASS_7.3-17

loaded via a namespace (and not attached):
[1] cluster_1.14.2 grid_2.14.2lattice_0.20-0 tools_2.14.2


__
Professor Michael Kubovy
University of Virginia
Department of Psychology
for mail add:   for FedEx or UPS add:
P.O.Box 400400  Gilmer Hall, Room 102
Charlottesville, VA 22904-4400  485 McCormick Road
USA Charlottesville, VA 
22903
roomphone
Office:B011 +1-434-982-4729
Lab:B019+1-434-982-4751
WWW:http://www.people.virginia.edu/~mk9y/


[[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 to split a ID column in a data.frame and create a new ID column

2012-03-16 Thread gianni lavaredo
Dear Researchers,

I have a data.frame with 2 columns like this:

mydf -
data.frame(value=c(1,2,3,4,5),ID=c(Area_1,Area_2,Area_3,Area_4,Area_5))

 mydf
  value ID
1 1 Area_1
2 2 Area_2
3 3 Area_3
4 4 Area_4
5 5 Area_5


I need to convert the *ID *in the following version
 mydf
  value ID  newID
1 1 Area_1   AreaSample1
2 2 Area_2   AreaSample2
3 3 Area_3   AreaSample3
4 4 Area_4   AreaSample4
5 5 Area_5   AreaSample5

some people know the right function to split ID and create a new column

Thanks in advance
Gianni

[[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] Generation of correlated variables

2012-03-16 Thread Petr Savicky
On Thu, Mar 15, 2012 at 10:48:48AM -0700, Filoche wrote:
 Hi everyone.
 
 Based on a dependent variable (y), I'm trying to generate some independent
 variables with a specified correlation. For this there's no problems.
 However, I would like that have all my regressors to be orthogonal (i.e.
 no correlation among them.
 
 For example, 
 
 y = x1 + x2 + x3 where the correlation between y x1 = 0.7, x2 = 0.4 and x3 =
 0.8.  However, x1, x2 and x3 should not be correlated to each other.

Hi.

The previous discussion shows that the required correlations
should have sum of squares 1. It is not clear, whether your
expected application allows to normalize the correlations to
satisfy this condition. If this normalization is possible, then
try the following approach. 

It creates a matrix trans, which satisfies the following.
If Z is a matrix whose columns have zero mean and the identity covariance
matrix, then Z %*% trans has the required correlation structure.
This may be checked by looking at cov2cor(t(trans) %*% trans).

Moreover, trans should have the first column c(1, 0, 0) so that
the first column of Z is not changed by the transformation.

  # normalize the correlations (see the discussion above)
  rho - c(0.7, 0.4, 0.8)
  rho - rho/sqrt(sum(rho^2))

  (required - cbind(c(1, rho), rbind(c(rho), diag(3

  trans - cbind(
  y=rho,
  x1=c(rho[1], 0, 0),
  x2=c(0, rho[2], 0),
  x3=c(0, 0, rho[3]))

  # check that trans generates the required correlations
  max(abs(cov2cor(t(trans) %*% trans) - required)) # [1] 1.110223e-16

  # get orthonormal columns
  gram.schmidt - function(a)
  {
  n - ncol(a)
  for (i in seq.int(length=n)) {
  for (j in seq.int(length=i-1)) {
  a[, i] - a[, i] - sum(a[, j]*a[, i])*a[, j]
  }
  a[, i] - a[, i]/sqrt(sum(a[, i]^2))
  }
  a
  }

  # multiply trans by a unitary matrix, so that the first column becomes (1, 0, 
0)
  U - gram.schmidt(trans[, 1:3])
  trans - t(U) %*% trans

  # check that trans still generates the required correlations
  max(abs(cov2cor(t(trans) %*% trans) - required)) # [1] 1.110223e-16

  # choose an example of the real vector y and normalize
  y - rnorm(100)
  ynorm - y - mean(y)
  ynorm - ynorm/sqrt(sum(ynorm^2))

  # find two more normalized vectors orthogonal to ynorm
  u - gram.schmidt(cbind(1, ynorm, rnorm(length(y)), rnorm(length(y[, 3:4]
  Z - cbind(ynorm, u) 

  # get the solution as suggested at the beginning
  S - Z %*% trans
 
  # check that S is a solution for the normalized y (ynorm)
  max(abs(cor(S) - required)) # [1] 1.110223e-16
  max(abs(S[, 1] - ynorm)) # [1] 8.326673e-17
  max(abs(S[, 2] + S[, 3] + S[, 4] - ynorm)) # [1] 1.110223e-16

This solution contains ynorm. In order to get y as required, a
linear transformation, which is inverse to the normalization, should
be done. Since it is linear, it does not change the correlations.

Hope this helps.

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.


[R] var

2012-03-16 Thread Amen
ex.nc
[1] file cruncep_tair_2010.nc has 4 dimensions:
[1] longitude   Size: 720
[1] latitude   Size: 360
[1] time   Size: 1460
[1] points_terre   Size: 62482
[1] 
[1] file cruncep_tair_2010.nc has 4 variables:
[1] int mask[longitude,latitude]  Longname:mask Missval:NA
[1] short indice_ligne[points_terre]  Longname:indice_ligne Missval:NA
[1] short indice_col[points_terre]  Longname:indice_col Missval:NA
[1] float Temperature[longitude,latitude,time]  Longname:Temperature
Missval:1e+30
these are the information of my file. How can I display the temperature
variable and manipulation it;I wanna  convert from hourly to daily.any
help!!!

--
View this message in context: 
http://r.789695.n4.nabble.com/var-tp4477613p4477613.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] Spatstat - coordinates in observation window

2012-03-16 Thread Lucie V










Dear R users,
 
I wish to run spatial point pattern analysis (e.g. pair correlation function, 
mark correlation function) for which I need to create an observation window 
(window=owin) from which the spatial analysis is generated. The command I used 
to create this observation window as follows:
 
X1- ppp(x, y, window=owin(c(80.58,144.96),c(101.06,165.13)), 
unitname=c(metres,metres), marks=dbh)
 
I managed to create the observation window with this command. However, my data 
(x,y coordinates of objects in a square plot) didn't fit into this observation 
window's frame. It seems like I need to 'move or twist' my data by a certain 
angle so that they fit within the border of the observation window's frame. I'm 
not sure how to do that. Is there a command of function for that? I would be 
very grateful for any help or suggestions.
 
I hope I described my problem so that it is understandable.  Thank you, L.  


  
[[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] How to Group Categorical data in R?

2012-03-16 Thread Manish Gupta
Hi, 

I am newbie to R and working on result presentation? My Input table is in
following format 

A   B   CD
X   TCK
Z   U   ZM
E   VZR
Z   U   ZM
E   VPR

I need to present my result in the following way.

Colum3 C
ABD
XT K

Column3 Z
Z   U  M
E   VR
Z   U  M

Column3 P
E   VR

How can i implement it? 

Thanks

--
View this message in context: 
http://r.789695.n4.nabble.com/How-to-Group-Categorical-data-in-R-tp4477622p4477622.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] Extending a group of S4 classes by setClassUnion ?

2012-03-16 Thread Alexander

Martin Morgan wrote
 
 On 03/15/2012 09:51 AM, Alexander wrote:
 Hi Martin,
 thanks for your quick answer. I didn't know that '.' could be
 missleading.
 Is there any standard way to name function for S4 objects? get,set
 etc..?
 
 Hi Alexander -- it's usually better to include the original email in the 
 reply, to provide context especially for those joining the thread later.
 
 I think 'get' and 'set' are implicit in the action of the 'getter' 
 fun(x) and 'setter' fun(x) - value function. I would have written (I 
 wouldn't have used par, which is an existing function unrelated to what 
 you're trying to do).
 
In fact, I have several getter and setter. For example gettermean and
gettervariance are less clear then getter.mean and getter.variance. The
names mean.getter, variance.getter have the disadvantage to have getter
and setter not in first place... (Ok, these are very minor problems...)

Martin Morgan wrote
 
setGeneric(parent,
function(object, ...) standardGeneric(parent'))
setMethod(parent, Father, function(object, ...) object@name)
 
setGeneric(parent-,
function(object, ..., value) standardGeneric(parent-))
setReplaceMethod(parent, c(Father, Son1),
function(object, ..., value)  {
object@name - value
object
})
 
 and used as
 
parent(obj)
parent(obj) - son
 
 I realize I'm confused about Father / Son and 'parent' here, maybe you 
 meant something else by 'par'.
 
Yes indeed, par means parameter. But you're right, it is to close to
parent and very misleading in this example

Martin Morgan wrote
 
 
 I saw your example, and I was wondering, why get.par(ext) put out Son1,
 and not the same as get.par(new(Son1, name=Son1, par=3))
 
 the setIs established a relationship between Extension and Father; you 
 could have established a relationship between Extension and Son1
 
setIs(Extension, Son1, ...)
 
 and then you would get your expected result. I have to say that I have 
 rarely used setIs, so the complexity of inheritance may hold some 
 surprises, e.g., when there are setIs defined, from Extension to Father, 
 Son1, and Son2.
 
 Martin
 
 If I define a function just like setMethod(get.par, Father,
 function(object) object@name) , for example

 setMethod(get.par, Father, function(object) object@par)

 then it would work, for all objects, which are either Son1 or Son2, but
 not
 all object, which are Father, contains also the variable par

   get.par(new(Father))

 Alexander



 --
 View this message in context:
 http://r.789695.n4.nabble.com/Extending-a-group-of-S4-classes-by-setClassUnion-tp4475251p4475650.html
 Sent from the R help mailing list archive at Nabble.com.

 __
 R-help@ mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide
 http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
 
 
 -- 
 Computational Biology
 Fred Hutchinson Cancer Research Center
 1100 Fairview Ave. N. PO Box 19024 Seattle, WA 98109
 
 Location: M1-B861
 Telephone: 206 667-2793
 
 __
 R-help@ mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide
 http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
 

I rewrote the example and I think if will have to write some setIs methods.
Do you know, how this is done? Here is a little example which shows, that
the order of initialization for setIs determins the results !!

setClass(Father,representation(name=character))
setClass(Son1,contains=Father,representation(parameter=numeric))
setClass(Son2,contains=Father,representation(parameter=logical))

Son1-new(Son1,name=Son1,parameter=3)
Son2-new(Son2,name=Son2,parameter=TRUE)

setGeneric(get.parameter,function(object){standardGeneric
(get.parameter)})
setMethod(get.parameter,Son1,function(object){return(object@parameter+3)})
setMethod(get.parameter,Son2,function(object){return(object@parameter==TRUE)})

get.parameter(Son1)
get.parameter(Son2)

setClass(Extension,representation(person=Father,text=character))

ext1 - new(Extension,person=Son1,text=new try)
ext2 - new(Extension,person=Son2,text=yesyes)

setIs(Extension, Son1,test=function(from){print(setIsSon1)
return(class(from@person)==Son1)
},
coerce=function(from) as(from@person,Son1,strict=FALSE),
replace=function(from, value) {from@person - value
from
}
)

setIs(Extension, Son2,test=function(from){print(setIsSon2)
return(class(from@person)==Son2)
},
coerce=function(from) as(from@person,Son2,strict=FALSE),
replace=function(from, value) {from@person - value
from
}
)

get.parameter(ext1) #setIsSon1, 6  correct result
get.parameter(ext2)# setIsSon1, Error in as(object, Son1, strict =
FALSE) : 

Re: [R] ncd4 package

2012-03-16 Thread Amen
Thanks a lot
I installed it but the interface did not show up
I got this message
 Local ({pkg - select.list (sort (. Packages (all.available = TRUE)),
 graphics = TRUE)
+ If (nchar (pkg)) library (pkg, character.only = TRUE)})
Notification message:
package 'RNetCDF has been compiled with version 2.14.2 R

--
View this message in context: 
http://r.789695.n4.nabble.com/ncd4-package-tp4477496p4477713.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] ncd4 package

2012-03-16 Thread Amen
I got theses but no interface
 library(udunits2) 
 library(ncdf)
 local({pkg - select.list(sort(.packages(all.available =
 TRUE)),graphics=TRUE)
+ if(nchar(pkg)) library(pkg, character.only=TRUE)})
 

--
View this message in context: 
http://r.789695.n4.nabble.com/ncd4-package-tp4477496p4477732.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] R merge two dataframes with different row?

2012-03-16 Thread zhu free
Hi everyone,
I have a question for R code to merge.
Say I have two dataframes:
File1 is:
V1V2V3V4
1100101name1
2200201name2
2300301name3
3400401name4
3500501name5
4600601name6
4700701name7

File2 is:
V1V2V3V4
15055p1
3402449p2
4550650p3
4651660p4
2150250p5
2250350p6
3450499p7
2100250p8

I hope to have the merged file3 meet the following three criteria:
(1) File1$V1==File2$V1, and
(2) File1V2=File2$V2, and
(3) File1V3=File2$V3.

In this case, we can see that there should be four records meet these three
criteria. So the final merge file should looks like:
File1$V1 File1$V2 File1$V3 File1$V4 File2$V1 File2$V2 File2$V3 File2$V4
2200 201 name2   2150
250p5
2200 201 name2   2 100
250p8
2300 301 name3   2 250
350p6
4600 601 name6   4 550
650   p3

Is there any one know how to make R code to achieve this? I thought out a
way to use for loop to read for each row in the file1 to compare the whole
data frame in file2 to find the mathcing rows but for loop takes so much
time. I would like to have a vectorized code to make it faster but I don't
know how to manage this.

Thanks,

[[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] Rolling regressions with sample extended one period at a time

2012-03-16 Thread pie'
hey, 


thanks for the hint. I too figured I'd have to write a for-loop. I have the
problem now of how to extract the single element of the fitted values
vector. For example, run 1 of the regression generates 80 fitted values, run
2 generates 81 fitted values, run 3 produces 82 fitted values and so on. I
need to extract the 80th, 81st, 82nd (all the last values generated at every
run) value into a separate vector. I know that lm (and glm) provides a
specific function for extracting  the predicted values but I don't know how
to use it inside a loop. Can you suggest anything?


P.

--
View this message in context: 
http://r.789695.n4.nabble.com/Rolling-regressions-with-sample-extended-one-period-at-a-time-tp4470316p4478016.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] Problem reading mixed CSV file

2012-03-16 Thread Ashish Agarwal
I am having trouble reading this CSV file in R. There are six attributes
that I need to read  - CVar1, CVar2, Location, Year, Nvar3, Nvar4. Can
somebody help in reading this file?
On line 10 it has city and state separated by comma. I had been a user of
SAS where I can use different format to read in for this line. Can I do
this in R too?
__
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] how to speed up the inefficient code

2012-03-16 Thread mrzung
hi,

i'm really in trouble to simulate some experiment.
that is, it takes too much time to process the following code.

 following is short example,

---

p-data.frame(a=rnorm(10),b=rnorm(10),c=rnorm(10),d=rnorm(10))
test-data.frame(a=rnorm(1),b=rnorm(1),c=rnorm(1),d=rnorm(1))

result-list()
for(i in 1:nrow(p)){
result[[i]]-sum((p[i,]-test)^2)
}

result_1-unlist(result)

p_1-cbind(p,result_1)

---

is there any efficient way to shorten the time and make same output?


--
View this message in context: 
http://r.789695.n4.nabble.com/how-to-speed-up-the-inefficient-code-tp4478046p4478046.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] Re : ncd4 package

2012-03-16 Thread Pascal Oettli
Hi,

Package ncdf4 is not available for Windows.

Regards,
Pascal



- Mail original -
De : Amen amen.alya...@bordeaux.inra.fr
À : r-help@r-project.org
Cc : 
Envoyé le : Vendredi 16 mars 2012 16h39
Objet : [R] ncd4 package

Hi
I am using windows. I cant install ncdf4 package but it didn't work . any
suggestions!!


--
View this message in context: 
http://r.789695.n4.nabble.com/ncd4-package-tp4477496p4477496.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.


Re: [R] replacing values in Array

2012-03-16 Thread uday
Hey Gerrit , 
Thanks your solution  works 

--
View this message in context: 
http://r.789695.n4.nabble.com/replacing-values-in-Array-tp4468739p4477758.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] Adding mean values to boxplots

2012-03-16 Thread Cleland
That works great by the way. Thanks very much for your help! 

--
View this message in context: 
http://r.789695.n4.nabble.com/Adding-mean-values-to-boxplots-tp4474700p4478031.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] How to Group Categorical data in R?

2012-03-16 Thread Jorge I Velez
Hi Manish,

Try

# data set
x - structure(list(V1 = structure(c(1L, 3L, 4L, 2L, 4L, 2L), .Label =
c(A,
E, X, Z), class = factor), V2 = structure(c(1L, 2L, 3L,
4L, 3L, 4L), .Label = c(B, T, U, V), class = factor),
V3 = structure(c(1L, 1L, 3L, 3L, 3L, 2L), .Label = c(C,
P, Z), class = factor), V4 = structure(c(1L, 2L, 3L,
4L, 3L, 4L), .Label = c(D, K, M, R), class = factor)), .Names
= c(V1,
V2, V3, V4), class = data.frame, row.names = c(NA, -6L
))

# result
lapply(split(x, x$V3), [, c(1, 2, 4))

See ?lapply, ?split and ?[ for more information.

HTH,
Jorge.-


On Fri, Mar 16, 2012 at 4:43 AM, Manish Gupta  wrote:

 Hi,

 I am newbie to R and working on result presentation? My Input table is in
 following format

 A   B   CD
 X   TCK
 Z   U   ZM
 E   VZR
 Z   U   ZM
 E   VPR

 I need to present my result in the following way.

 Colum3 C
 ABD
 XT K

 Column3 Z
 Z   U  M
 E   VR
 Z   U  M

 Column3 P
 E   VR

 How can i implement it?

 Thanks

 --
 View this message in context:
 http://r.789695.n4.nabble.com/How-to-Group-Categorical-data-in-R-tp4477622p4477622.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.


[[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 extend a slot of a class?

2012-03-16 Thread Igor Sosa Mayor
i think if you do:

coord$time-YOURTIMEVECTOR

should work and the new vector is put correctly in the data slot.

Maybe also

coord@data$time-YOURTIMEVECTOR

On Wed, Mar 14, 2012 at 01:39:20PM +0100, Marco Smolla wrote:
 Hej hej,

 is there a way to extend the SpatialPointsDataFrame data slot?This is the 
 structure of an object of it: str(coord)
 Formal class 'SpatialPointsDataFrame' [package sp] with 5 slots
   ..@ data   :'data.frame':   214 obs. of  2 variables:
   .. ..$ location.long: num [1:214] -79.8 -79.8 -79.8 -79.8 -79.8 ...
   .. ..$ location.lat : num [1:214] 9.16 9.16 9.16 9.16 9.16 ...
   ..@ coords.nrs : num(0) 
   ..@ coords : num [1:214, 1:2] -79.8 -79.8 -79.8 -79.8 -79.8 ...
   .. ..- attr(*, dimnames)=List of 2
   .. .. ..$ : NULL
   .. .. ..$ : chr [1:2] location.long location.lat
   ..@ bbox   : num [1:2, 1:2] -79.84 9.16 -79.84 9.17
   .. ..- attr(*, dimnames)=List of 2
   .. .. ..$ : chr [1:2] location.long location.lat
   .. .. ..$ : chr [1:2] min max
   ..@ proj4string:Formal class 'CRS' [package sp] with 1 slots
   .. .. ..@ projargs: chr NA

 data is a data.frame including the information of long and lat location. I 
 would like to have there a third information: time (but as POSIXct). Is there 
 an elegant way to do this?

 Best,
 marco
   [[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.

-- 
:: Igor Sosa Mayor   :: joseleopoldo1...@gmail.com ::
:: GnuPG: 0x1C1E2890 :: http://www.gnupg.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] how to speed up the inefficient code

2012-03-16 Thread Jorge I Velez
Hi mrzung46,

Try

cbind(p, result_1 = rowSums((p-c(test))^2))

HTH,
Jorge.-


On Fri, Mar 16, 2012 at 8:32 AM, mrzung  wrote:

 hi,

 i'm really in trouble to simulate some experiment.
 that is, it takes too much time to process the following code.

  following is short example,


 ---

 p-data.frame(a=rnorm(10),b=rnorm(10),c=rnorm(10),d=rnorm(10))
 test-data.frame(a=rnorm(1),b=rnorm(1),c=rnorm(1),d=rnorm(1))

 result-list()
 for(i in 1:nrow(p)){
 result[[i]]-sum((p[i,]-test)^2)
 }

 result_1-unlist(result)

 p_1-cbind(p,result_1)


 ---

 is there any efficient way to shorten the time and make same output?


 --
 View this message in context:
 http://r.789695.n4.nabble.com/how-to-speed-up-the-inefficient-code-tp4478046p4478046.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.


[[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 to split a ID column in a data.frame and create a new ID column

2012-03-16 Thread Jorge I Velez
Hi Gianni,

Thank you for the reproducible example!

Try

mydf$newID - with(mydf, gsub(_, Sample, ID))
mydf

HTH,
Jorge.-


On Fri, Mar 16, 2012 at 7:54 AM, gianni lavaredo  wrote:

 Dear Researchers,

 I have a data.frame with 2 columns like this:

 mydf -

 data.frame(value=c(1,2,3,4,5),ID=c(Area_1,Area_2,Area_3,Area_4,Area_5))

  mydf
  value ID
 1 1 Area_1
 2 2 Area_2
 3 3 Area_3
 4 4 Area_4
 5 5 Area_5


 I need to convert the *ID *in the following version
  mydf
  value ID  newID
 1 1 Area_1   AreaSample1
 2 2 Area_2   AreaSample2
 3 3 Area_3   AreaSample3
 4 4 Area_4   AreaSample4
 5 5 Area_5   AreaSample5

 some people know the right function to split ID and create a new column

 Thanks in advance
 Gianni

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


Re: [R] how to speed up the inefficient code

2012-03-16 Thread jim holtman
Try this -- use matrices instead of dataframes if you want speed:

 p-data.frame(a=rnorm(10),b=rnorm(10),c=rnorm(10),d=rnorm(10))
 test-data.frame(a=rnorm(1),b=rnorm(1),c=rnorm(1),d=rnorm(1))

 result-list()
 for(i in 1:nrow(p)){
+ result[[i]]-sum((p[i,]-test)^2)
+ }

 result_1-unlist(result)

 p_1-cbind(p,result_1)

 # don't use dataframes; use matrices
 pm - as.matrix(p)
 testm - unlist(test)

 result_2 - colSums((t(pm) - testm)^2)
 p_2 - cbind(pm, result_2)
 p_1
a   b  c  d  result_1
1   1.4580819  0.03351271 -0.6414914 -0.4448870  2.464525
2  -0.7603889 -0.41833604 -1.3576672 -0.1230215  6.270578
3   1.3343855 -1.35613207  2.0560362 -1.0356030  3.592794
4   0.5974293  0.88175552 -1.4756855  0.1634320  6.707364
5  -0.8008295  0.37385864 -0.7822124 -0.4896094  4.712335
6  -0.5550789  0.07063761  0.9432475  1.0785456  4.868218
7   1.0641638 -1.52241836  0.3912154  0.1071740  2.165140
8   1.5619793 -0.30982169  1.2756762 -0.8522361  1.266879
9  -0.1049558 -1.0559  0.5425563  0.3232156  3.279428
10 -0.1565198  0.59954267 -1.3878649  1.8615366 12.132722
 p_2
   a   b  c  d  result_2
 [1,]  1.4580819  0.03351271 -0.6414914 -0.4448870  2.464525
 [2,] -0.7603889 -0.41833604 -1.3576672 -0.1230215  6.270578
 [3,]  1.3343855 -1.35613207  2.0560362 -1.0356030  3.592794
 [4,]  0.5974293  0.88175552 -1.4756855  0.1634320  6.707364
 [5,] -0.8008295  0.37385864 -0.7822124 -0.4896094  4.712335
 [6,] -0.5550789  0.07063761  0.9432475  1.0785456  4.868218
 [7,]  1.0641638 -1.52241836  0.3912154  0.1071740  2.165140
 [8,]  1.5619793 -0.30982169  1.2756762 -0.8522361  1.266879
 [9,] -0.1049558 -1.0559  0.5425563  0.3232156  3.279428
[10,] -0.1565198  0.59954267 -1.3878649  1.8615366 12.132722



On Fri, Mar 16, 2012 at 8:32 AM, mrzung mrzun...@gmail.com wrote:
 hi,

 i'm really in trouble to simulate some experiment.
 that is, it takes too much time to process the following code.

  following is short example,

 ---

 p-data.frame(a=rnorm(10),b=rnorm(10),c=rnorm(10),d=rnorm(10))
 test-data.frame(a=rnorm(1),b=rnorm(1),c=rnorm(1),d=rnorm(1))

 result-list()
 for(i in 1:nrow(p)){
 result[[i]]-sum((p[i,]-test)^2)
 }

 result_1-unlist(result)

 p_1-cbind(p,result_1)

 ---

 is there any efficient way to shorten the time and make same output?


 --
 View this message in context: 
 http://r.789695.n4.nabble.com/how-to-speed-up-the-inefficient-code-tp4478046p4478046.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
Data Munger Guru

What is the problem that you are trying to solve?
Tell me what you want to do, not how you want to do it.

__
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] Ggplot barchart drops factor levels: how to show them with zero counts?

2012-03-16 Thread Ben Bolker
R. Michael Weylandt michael.weylandt at gmail.com writes:

 
 I can reproduce the OP's problem with ggplot 0.9.0 but I don't know
 how to solve it: perhaps you should take this to the ggplot2 mailing
 list: https://groups.google.com/group/ggplot2?pli=1
 
 Michael
 
 On Fri, Mar 16, 2012 at 4:17 AM, Bart6114 bartsmeets86 at gmail.com wrote:
  To visualize my problem a little; see this screenshot
  http://i40.tinypic.com/fodsm0.png http://i40.tinypic.com/fodsm0.png .
 
  So I would like factor level 4 to show up but without a bar (zero counts).
 
  Thanks
 

  Supposedly 

ggplot(subset(mtcars,cyl!=4),aes(cyl))+stat_bin(drop=FALSE)

*should* work (see ?stat_bin) -- maybe a bug?  I would second the
advice to put this on the ggplot mailing list ...

__
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] Partial matching when using $ ? Feature or bug?

2012-03-16 Thread Rainer M Krug
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Hi

I have the following code:

  x - data.frame(x1=1, x2=2, y1=3)
  x$y
[1] 3
  x$x
NULL


I was surprised (and definitely irritated?) when I realised that partial 
matching also works for
the $. Is this intended?

I assume the reason is that $ is internally a function?

Rainer

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

Centre of Excellence for Invasion Biology
Stellenbosch University
South Africa

Tel :   +33 - (0)9 53 10 27 44
Cell:   +33 - (0)6 85 62 59 98
Fax :   +33 - (0)9 58 10 27 44

Fax (D):+49 - (0)3 21 21 25 22 44

email:  rai...@krugs.de

Skype:  RMkrug
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk9jQ+YACgkQoYgNqgF2egpe7QCeL2us46r9NVtJsXteUhEaBcwe
disAn2eY5Ci5/QNgRLOwOs8HVTcF3KHn
=Qgnt
-END PGP SIGNATURE-

__
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] contingency tables

2012-03-16 Thread mari681
Ok, before I definetly give up, and throw the laptop out of the window, or
fill my data.frame manually, I'll ask for some help.
I have a data.frame named MyTable with 3 columns, that looks like this:

 V1  V2   V3
red-jappearanceblood-n 105.032
red-j   appearanceground-n  93.749
red-j  appearancesea-n 102.167
red-j  appearancesky-n   10.898
orange-jappearanceobject-n  109.354
orange-jas_adj_aspainting-n 93.248
orange-jcolorbanknote-n 159.167
orange-jcolorcar-n  117.985
yellow-jappearanceskin-n109.527
yellow-jareacircle-n87.064
yellow-jareainfarction-n120.759
yellow-jas_adj_ascorn-n 219.739
yellow-jas_adj_asflax-n 122.576
yellow-jas_adj_asgold-n 90.814
green-j appearancewater-n   91.477
green-j architecturebuilding-n  103.582
green-j architecturecourse-n103.325
green-j areaRio-n   106.614
green-j areaauditorium-n102.505
green-j areacity-n  150.005
blue-j  appearancecypress-n 145.133
blue-j  appearancefirmament-n   148.655
blue-j  appearanceman-n 85.731
blue-j  appearancerange-n   90.706
blue-j  appearancesurface-n 100.991
blue-j  areagraph-n 92.708
blue-j  arealibrary-n   77.135
purple-jappearanceleave-n   119.423
purple-jappearancelesion-n  134.287
purple-jcolorViking-n   145.516
purple-jcoloramethyst-n 175.619
purple-jcolorbanknote-n 158.045
purple-jcolorbottle-n   132.395
purple-jcolorchocolate-n141.833

The elements on the first column can be: red-j, orange-j, yellow-j, green-j,
blue-j or purple-j. Elements on column 2 are contexts in which the color
appears. And in column 3 there is a kind of frequency measurement between
color and context.

I am trying to build a new data.frame where the 6 colors in column 1 are
placed as column names, all the unique contexts in column 2 are placed as
row names and the values on column 3 are in the correspondent cells (or 0 if
an intersection color-context is empty).
Easy to prepare the empty data.frame, but I cant find out how to fill it up
with the frequencies.
Ideas? Anybody has a ready script for this?

Thank you!!!

Marianna

--
View this message in context: 
http://r.789695.n4.nabble.com/contingency-tables-tp4478204p4478204.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] Partial matching when using $ ? Feature or bug?

2012-03-16 Thread Sarah Goslee
Hi Rainer,

On Fri, Mar 16, 2012 at 9:45 AM, Rainer M Krug r.m.k...@gmail.com wrote:
 -BEGIN PGP SIGNED MESSAGE-
 Hash: SHA1

 Hi

 I have the following code:

  x - data.frame(x1=1, x2=2, y1=3)
  x$y
 [1] 3
  x$x
 NULL


 I was surprised (and definitely irritated?) when I realised that partial 
 matching also works for
 the $. Is this intended?

This is documented behavior, which by definition makes it a feature, right?

 Both ‘[[’ and ‘$’ select a single element of the list.  The main
 difference is that ‘$’ does not allow computed indices, whereas
 ‘[[’ does.  ‘x$name’ is equivalent to ‘x[[name, exact =
 FALSE]]’.  Also, the partial matching behavior of ‘[[’ can be
 controlled using the ‘exact’ argument.

It's also a really good reason to use [[ in functions or anywhere
there might be a chance of confusion.

Sarah

-- 
Sarah Goslee
http://www.functionaldiversity.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] Re : Elegant Code

2012-03-16 Thread Raphael Fraser
Thank you all. Your responses were very helpful.

Raphael

On Fri, Mar 16, 2012 at 5:04 AM, Daniel Nordlund
djnordl...@frontier.com wrote:

 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
 On Behalf Of Pascal Oettli
 Sent: Friday, March 16, 2012 12:36 AM
 To: Raphael Fraser
 Cc: r-help@r-project.org
 Subject: [R] Re : Elegant Code

 Hi Raphael,

 Something like that?

 require(pscl)sim - numeric()
 for(i in 1:5){
   eval(parse(text=paste('b',i,' - rigamma(50,1,1)',sep='')))
   eval(parse(text=paste('theta',i,' -
 rgamma(50,0.5,(1/b',i,'))',sep='')))
   eval(parse(text=paste('sim',i,' - rpois(50,theta',1,')',sep='')))
   eval(parse(text=paste('sim - cbind(sim, sim',i,')',sep='')))
 }
 x11()
 par(mfrow=c(1,5))
 boxplot(c(sim1,sim2,sim3,sim4,sim5))

 x11()
 boxplot(sim)


 Regards,
 Pascal


 - Mail original -
 De : Raphael Fraser raphael.fra...@gmail.com
 À : r-help@r-project.org
 Cc :
 Envoyé le : Vendredi 16 mars 2012 16h09
 Objet : [R] Elegant Code

 Hi,

 Can anyone help to write a more elegant version of my code? I am sure
 this can be put into a loop but I am having trouble creating the
 objects b1,b2,b3,...,etc.

 b1 - rigamma(50,1,1)
 theta1 - rgamma(50,0.5,(1/b1))
 sim1 - rpois(50,theta1)

 b2 - rigamma(50,1,1)
 theta2 - rgamma(50,0.5,(1/b2))
 sim2 - rpois(50,theta2)

 b3 - rigamma(50,1,1)
 theta3 - rgamma(50,0.5,(1/b3))
 sim3 - rpois(50,theta3)

 b4 - rigamma(50,1,1)
 theta4 - rgamma(50,0.5,(1/b4))
 sim4 - rpois(50,theta4)

 b5 - rigamma(50,1,1)
 theta5 - rgamma(50,0.5,(1/b5))
 sim5 - rpois(50,theta5)



 par(mfrow=c(1,5))
 boxplot(sim1)
 boxplot(sim2)
 boxplot(sim3)
 boxplot(sim4)
 boxplot(sim5);

 Thanks,
 Raphael


 Or, just get rid of the for loops altogether, something like this

 trials -5
 N - 50
 b    - rigamma(N*trials, 1, 1)
 theta - rgamma(N*trials,0.5,1/b)
 sim   - rpois(N*trials,theta)

 dim(sim) - c(N,trials)

 boxplot(sim)


 Hope this is helpful,

 Dan

 Daniel Nordlund
 Bothell, WA USA

 __
 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] Partial matching when using $ ? Feature or bug?

2012-03-16 Thread Rainer M Krug
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

On 16/03/12 14:54, Sarah Goslee wrote:
 Hi Rainer,
 
 On Fri, Mar 16, 2012 at 9:45 AM, Rainer M Krug r.m.k...@gmail.com wrote:
 -BEGIN PGP SIGNED MESSAGE- Hash: SHA1
 
 Hi
 
 I have the following code:
 
 x - data.frame(x1=1, x2=2, y1=3) x$y [1] 3 x$x NULL
 
 
 I was surprised (and definitely irritated?) when I realised that partial 
 matching also works
 for the $. Is this intended?
 
 This is documented behavior, which by definition makes it a feature, right?

Not necessary - one can also document bugs. But I agree - this has to be 
considered a feature.

 
 Both ‘[[’ and ‘$’ select a single element of the list.  The main difference 
 is that ‘$’ does
 not allow computed indices, whereas ‘[[’ does.  ‘x$name’ is equivalent to 
 ‘x[[name, exact = 
 FALSE]]’.  Also, the partial matching behavior of ‘[[’ can be controlled 
 using the ‘exact’
 argument.
 
 It's also a really good reason to use [[ in functions or anywhere there might 
 be a chance of
 confusion.

Absolutely - I think I have to change my habit. I always prefered using $ as it 
seemed to me more
logical.

Thanks,

Rainer


 
 Sarah
 


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

Centre of Excellence for Invasion Biology
Stellenbosch University
South Africa

Tel :   +33 - (0)9 53 10 27 44
Cell:   +33 - (0)6 85 62 59 98
Fax :   +33 - (0)9 58 10 27 44

Fax (D):+49 - (0)3 21 21 25 22 44

email:  rai...@krugs.de

Skype:  RMkrug
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk9jR6AACgkQoYgNqgF2egqfdwCdGOhe5jk/xgaxpISf9GGMA+Yk
68IAn1RA9N7vJnytAliFszXJxt3/3tJC
=hIXq
-END PGP SIGNATURE-

__
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] Partial matching when using $ ? Feature or bug?

2012-03-16 Thread Sarah Goslee
 It's also a really good reason to use [[ in functions or anywhere there 
 might be a chance of
 confusion.

 Absolutely - I think I have to change my habit. I always prefered using $ as 
 it seemed to me more
 logical.

I started out that way because it's shorter and nicer-looking code,
but it can cause partial-matching problems, and also LaTeX annoyances
in Sweave code. Someday I'll go back through my packages and get rid
of all the lingering $.

R: lots of ways to do the same thing, but some of them are booby-trapped.

Sarah

-- 
Sarah Goslee
http://www.functionaldiversity.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] R merge two dataframes with different row?

2012-03-16 Thread David Winsemius


On Mar 16, 2012, at 5:51 AM, zhu free wrote:


Hi everyone,
I have a question for R code to merge.
Say I have two dataframes:
File1 is:
V1V2V3V4
1100101name1
2200201name2
2300301name3
3400401name4
3500501name5
4600601name6
4700701name7

File2 is:
V1V2V3V4
15055p1
3402449p2
4550650p3
4651660p4
2150250p5
2250350p6
3450499p7
2100250p8

I hope to have the merged file3 meet the following three criteria:
(1) File1$V1==File2$V1, and
(2) File1V2=File2$V2, and
(3) File1V3=File2$V3.

In this case, we can see that there should be four records meet  
these three

criteria. So the final merge file should looks like:
File1$V1 File1$V2 File1$V3 File1$V4 File2$V1 File2$V2 File2$V3  
File2$V4

2200 201 name2   2150
250p5
2200 201 name2   2 100
250p8
2300 301 name3   2 250
350p6
4600 601 name6   4 550
650   p3

Is there any one know how to make R code to achieve this? I thought  
out a
way to use for loop to read for each row in the file1 to compare the  
whole
data frame in file2 to find the mathcing rows but for loop takes so  
much
time. I would like to have a vectorized code to make it faster but I  
don't

know how to manage this.


Why not merge on the exact criterion and then subset out the rows that  
qualify on the logical tests?


dfm - merge(File1, File2, 1)
subset(dfm, V2.x = V2.y  V3.x = V3.y)
   V1 V2.x V3.x  V4.x V2.y V3.y V4.y
2   2  200  201 name2  150  250   p5
4   2  200  201 name2  100  250   p8
6   2  300  301 name3  250  350   p6
12  4  600  601 name6  550  650   p3
--

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] contingency tables

2012-03-16 Thread Milan Bouchet-Valat
Le vendredi 16 mars 2012 à 06:46 -0700, mari681 a écrit :
 Ok, before I definetly give up, and throw the laptop out of the window, or
 fill my data.frame manually, I'll ask for some help.
 I have a data.frame named MyTable with 3 columns, that looks like this:
snip

 The elements on the first column can be: red-j, orange-j, yellow-j, green-j,
 blue-j or purple-j. Elements on column 2 are contexts in which the color
 appears. And in column 3 there is a kind of frequency measurement between
 color and context.
 
 I am trying to build a new data.frame where the 6 colors in column 1 are
 placed as column names, all the unique contexts in column 2 are placed as
 row names and the values on column 3 are in the correspondent cells (or 0 if
 an intersection color-context is empty).
 Easy to prepare the empty data.frame, but I cant find out how to fill it up
 with the frequencies.
 Ideas? Anybody has a ready script for this?
If I understand correctly, this is very simple using xtabs().

dat - structure(list(V1 = structure(c(5L, 5L, 5L, 5L, 3L, 3L, 3L, 3L, 
6L, 6L, 6L, 6L, 6L, 6L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 4L, 4L, 4L, 4L, 4L, 4L, 4L), .Label = c(blue-j, 
green-j, orange-j, purple-j, red-j, yellow-j), class =
factor), 
V2 = structure(c(1L, 4L, 10L, 12L, 8L, 27L, 29L, 31L, 11L, 
18L, 21L, 24L, 25L, 26L, 14L, 15L, 16L, 23L, 17L, 19L, 2L, 
3L, 7L, 9L, 13L, 20L, 22L, 5L, 6L, 33L, 28L, 29L, 30L, 32L
), .Label = c(appearanceblood-n, appearancecypress-n, 
appearancefirmament-n, appearanceground-n, appearanceleave-n, 
appearancelesion-n, appearanceman-n, appearanceobject-n, 
appearancerange-n, appearancesea-n, appearanceskin-n, 
appearancesky-n, appearancesurface-n, appearancewater-n, 
architecturebuilding-n, architecturecourse-n,
areaauditorium-n, 
areacircle-n, areacity-n, areagraph-n, areainfarction-n, 
arealibrary-n, areaRio-n, as_adj_ascorn-n, as_adj_asflax-n, 
as_adj_asgold-n, as_adj_aspainting-n, coloramethyst-n, 
colorbanknote-n, colorbottle-n, colorcar-n,
colorchocolate-n, 
colorViking-n), class = factor), V3 = c(105.032, 93.749, 
102.167, 10.898, 109.354, 93.248, 159.167, 117.985, 109.527, 
87.064, 120.759, 219.739, 122.576, 90.814, 91.477, 103.582, 
103.325, 106.614, 102.505, 150.005, 145.133, 148.655, 85.731, 
90.706, 100.991, 92.708, 77.135, 119.423, 134.287, 145.516, 
175.619, 158.045, 132.395, 141.833)), .Names = c(V1, V2, 
V3), class = data.frame)

xtabs(V3 ~ V2 + V1, data=dat)


BTW, creating the data frame took me the most time, so please provide a
working data set using dput() next time.

Regards

__
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] contingency tables

2012-03-16 Thread David Winsemius


On Mar 16, 2012, at 9:46 AM, mari681 wrote:

Ok, before I definetly give up, and throw the laptop out of the  
window, or

fill my data.frame manually, I'll ask for some help.
I have a data.frame named MyTable with 3 columns, that looks like  
this:


V1  V2   V3
red-jappearanceblood-n 105.032
red-j   appearanceground-n  93.749
red-j  appearancesea-n 102.167
red-j  appearancesky-n   10.898
orange-jappearanceobject-n  109.354
orange-jas_adj_aspainting-n 93.248
orange-jcolorbanknote-n 159.167
orange-jcolorcar-n  117.985
yellow-jappearanceskin-n109.527
yellow-jareacircle-n87.064
yellow-jareainfarction-n120.759
yellow-jas_adj_ascorn-n 219.739
yellow-jas_adj_asflax-n 122.576
yellow-jas_adj_asgold-n 90.814
green-j appearancewater-n   91.477
green-j architecturebuilding-n  103.582
green-j architecturecourse-n103.325
green-j areaRio-n   106.614
green-j areaauditorium-n102.505
green-j areacity-n  150.005
blue-j  appearancecypress-n 145.133
blue-j  appearancefirmament-n   148.655
blue-j  appearanceman-n 85.731
blue-j  appearancerange-n   90.706
blue-j  appearancesurface-n 100.991
blue-j  areagraph-n 92.708
blue-j  arealibrary-n   77.135
purple-jappearanceleave-n   119.423
purple-jappearancelesion-n  134.287
purple-jcolorViking-n   145.516
purple-jcoloramethyst-n 175.619
purple-jcolorbanknote-n 158.045
purple-jcolorbottle-n   132.395
purple-jcolorchocolate-n141.833

The elements on the first column can be: red-j, orange-j, yellow-j,  
green-j,
blue-j or purple-j. Elements on column 2 are contexts in which the  
color
appears. And in column 3 there is a kind of frequency measurement  
between

color and context.

I am trying to build a new data.frame where the 6 colors in column 1  
are
placed as column names, all the unique contexts in column 2 are  
placed as
row names and the values on column 3 are in the correspondent cells  
(or 0 if

an intersection color-context is empty).
Easy to prepare the empty data.frame, but I cant find out how to  
fill it up

with the frequencies.
Ideas? Anybody has a ready script for this?


?xtabs
aRealTable - xtabs(V3 ~ V1+V2, data=MyTable)





--

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] ROC Analysis

2012-03-16 Thread Camille Leclerc
Hi everybody,

Pascal, your script works again but I want to calculate the LR otherwise.
I know the likelihood ratio is linked at the roc curve and so there are
different ways to calculate the LR.
The slope of an ROC curve can be defined in three ways:
(1) as the tangent at a particular point on the ROC curve corresponding to a
test value x
(2) as the slope between the origin 0 and the point on the ROC curve
corresponding to a test value x 
(3) as the slope between two points on the ROC curve corresponding to the
test values x and y

http://r.789695.n4.nabble.com/file/n4478233/LR.png 

But in my case, I want calculated the LR with the third way. 
So, LR (x,y) =(sensitivity (x)-sensitivity (y))/(specificity (y)-specificity
(x))
= (TPR(x)-TPR (y))/(FPR (x)-FPR (y))

It is possible ?!

All the best,
Camille


-
--
Camille Leclerc, Master student
Lab ESE, UMR CNRS 8079
Univ Paris-Sud
Bat 362
F-91405  Orsay Cedex FRANCE
--
View this message in context: 
http://r.789695.n4.nabble.com/ROC-Analysis-tp4469203p4478233.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] multiple density plot

2012-03-16 Thread statquant2
Hello I am looking for a special plot.

Let's suppose I have *100 days and 
  *each day I have a (1D)
distribution of the same variable.

I would like to plot 
*dates on x axis and 
*one distribution per date on the y axe. Do you know a way of doing it ?
Cheers



--
View this message in context: 
http://r.789695.n4.nabble.com/multiple-density-plot-tp4478196p4478196.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] How to start R in maximized size???

2012-03-16 Thread Christofer Bogaso
Dear all, when I start R, I want that the console window should be in
the Maximized size automatically. Can somebody help me how to achieve
that?

Thanks and regards,

__
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 start R in maximized size???

2012-03-16 Thread Duncan Murdoch

On 16/03/2012 10:23 AM, Christofer Bogaso wrote:

Dear all, when I start R, I want that the console window should be in
the Maximized size automatically. Can somebody help me how to achieve
that?


If you are working in Windows and starting R by clicking on the 
shortcut, just change the Run: property of the shortcut.  (Right click 
it, choose properties...)


Duncan Murdoch

__
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] plot columns

2012-03-16 Thread aoife doherty
Hey guys, can anyone help?

i have a sample table:

table - structure(c(4, 7, 0.2, 3, .1, 7, 222, 3, 10, 5, 11,
  8, 8, 10, 7), .Dim = c(5L, 3L), .Dimnames = list(c(gene1,
  gene2, gene3, gene4, gene5), c(codon1, codon2,
  codon3)))

table

  codon1 codon2 codon3
gene14.0  7 11
gene27.0222  8
gene30.2  3  8
gene43.0 10 10
gene50.1  5  7


i want to plot column 1 versus column 3.

Does anyone know how to read in particular columns and plot?

i was looking at this:

https://stat.ethz.ch/pipermail/r-help/2007-July/137638.html

but i can't seem to alter it to my needs

Thank you
Aoife

[[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] where I can find more color names or color definition?

2012-03-16 Thread David Reiner
I found this useful:
http://research.stowers-institute.org/efg/R/Color/Chart/ColorChart.pdf

HTH,
-- David


-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
Behalf Of FJ M
Sent: Wednesday, March 14, 2012 3:39 PM
To: totang...@gmail.com; R
Subject: Re: [R] where I can find more color names or color definition?


Load package fBasics

library(fBasics)

colors()

should give you what you want. Also helpful are

colorTable()
colorLocator()

Which I found by searching for colors from the R console help menu.


 Date: Wed, 14 Mar 2012 22:55:39 +0800
 From: totang...@gmail.com
 To: r-help@r-project.org
 Subject: [R] where I can find more color names or color definition?

 hi everyone .
 Now I want to draw several lines in one frame.And it seems needs more
 colors except for blue red,black .Where can i found these color name
 or define some new color ?thank you .

 --
 TANG Jie
 Email: totang...@gmail.com
 Tel: 0086-2154896104
 Shanghai Typhoon Institute,China

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


This e-mail and any materials attached hereto, including, without limitation, 
all content hereof and thereof (collectively, XR Content) are confidential 
and proprietary to XR Trading, LLC (XR) and/or its affiliates, and are 
protected by intellectual property laws.  Without the prior written consent of 
XR, the XR Content may not (i) be disclosed to any third party or (ii) be 
reproduced or otherwise used by anyone other than current employees of XR or 
its affiliates, on behalf of XR or its affiliates.

THE XR CONTENT IS PROVIDED AS IS, WITHOUT REPRESENTATIONS OR WARRANTIES OF ANY 
KIND.  TO THE MAXIMUM EXTENT PERMISSIBLE UNDER APPLICABLE LAW, XR HEREBY 
DISCLAIMS ANY AND ALL WARRANTIES, EXPRESS AND IMPLIED, RELATING TO THE XR 
CONTENT, AND NEITHER XR NOR ANY OF ITS AFFILIATES SHALL IN ANY EVENT BE LIABLE 
FOR ANY DAMAGES OF ANY NATURE WHATSOEVER, INCLUDING, BUT NOT LIMITED TO, 
DIRECT, INDIRECT, CONSEQUENTIAL, SPECIAL AND PUNITIVE DAMAGES, LOSS OF PROFITS 
AND TRADING LOSSES, RESULTING FROM ANY PERSON'S USE OR RELIANCE UPON, OR 
INABILITY TO USE, ANY XR CONTENT, EVEN IF XR IS ADVISED OF THE POSSIBILITY OF 
SUCH DAMAGES OR IF SUCH DAMAGES WERE FORESEEABLE.

__
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 start R in maximized size???

2012-03-16 Thread Christofer Bogaso
No no, I meant to say the console window, where we type the syntax etc.

BTW, what is the official name of this window?

Thanks,

On Fri, Mar 16, 2012 at 8:15 PM, Duncan Murdoch
murdoch.dun...@gmail.com wrote:
 On 16/03/2012 10:23 AM, Christofer Bogaso wrote:

 Dear all, when I start R, I want that the console window should be in
 the Maximized size automatically. Can somebody help me how to achieve
 that?


 If you are working in Windows and starting R by clicking on the shortcut,
 just change the Run: property of the shortcut.  (Right click it, choose
 properties...)

 Duncan Murdoch

__
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] Partial matching when using $ ? Feature or bug?

2012-03-16 Thread Ben Bolker
Sarah Goslee sarah.goslee at gmail.com writes:

 
 R: lots of ways to do the same thing, but some of them are booby-trapped.

  Fortune candidate!

__
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] Partial matching when using $ ? Feature or bug?

2012-03-16 Thread Rainer M Krug
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

On 16/03/12 15:05, Sarah Goslee wrote:
 It's also a really good reason to use [[ in functions or anywhere there 
 might be a chance
 of confusion.
 
 Absolutely - I think I have to change my habit. I always prefered using $ as 
 it seemed to me
 more logical.
 
 I started out that way because it's shorter and nicer-looking code,

absolutely.

 but it can cause partial-matching problems,

It did just for me...

 and also LaTeX annoyances in Sweave code.

Good to know - I'll keep that in mind.

 Someday I'll go back through my packages and get rid of all the lingering $.
 
 R: lots of ways to do the same thing, but some of them are booby-trapped.

Absolutely - but isn't that the fun part of R?

Rainer

 
 Sarah
 


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

Centre of Excellence for Invasion Biology
Stellenbosch University
South Africa

Tel :   +33 - (0)9 53 10 27 44
Cell:   +33 - (0)6 85 62 59 98
Fax :   +33 - (0)9 58 10 27 44

Fax (D):+49 - (0)3 21 21 25 22 44

email:  rai...@krugs.de

Skype:  RMkrug
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk9jTCoACgkQoYgNqgF2egp7yQCeJOSxxKSeFjYtCxucxYSj8MtU
bbAAni6vsxE7Rm14luVg41tUT34/LcZ+
=Tw5l
-END PGP SIGNATURE-

__
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 start R in maximized size???

2012-03-16 Thread Kevin Wright
Duncan's suggestion worked for me.  What about it didn't work for you?

Kevin


On Fri, Mar 16, 2012 at 9:35 AM, Christofer Bogaso 
bogaso.christo...@gmail.com wrote:

 No no, I meant to say the console window, where we type the syntax etc.

 BTW, what is the official name of this window?

 Thanks,

 On Fri, Mar 16, 2012 at 8:15 PM, Duncan Murdoch
 murdoch.dun...@gmail.com wrote:
  On 16/03/2012 10:23 AM, Christofer Bogaso wrote:
 
  Dear all, when I start R, I want that the console window should be in
  the Maximized size automatically. Can somebody help me how to achieve
  that?
 
 
  If you are working in Windows and starting R by clicking on the shortcut,
  just change the Run: property of the shortcut.  (Right click it, choose
  properties...)
 
  Duncan Murdoch

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




-- 
Kevin Wright

[[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 start R in maximized size???

2012-03-16 Thread Duncan Murdoch

On 16/03/2012 10:35 AM, Christofer Bogaso wrote:

No no, I meant to say the console window, where we type the syntax etc.

BTW, what is the official name of this window?


I think console window is good enough.

Duncan Murdoch

Thanks,

On Fri, Mar 16, 2012 at 8:15 PM, Duncan Murdoch
murdoch.dun...@gmail.com  wrote:
  On 16/03/2012 10:23 AM, Christofer Bogaso wrote:

  Dear all, when I start R, I want that the console window should be in
  the Maximized size automatically. Can somebody help me how to achieve
  that?


  If you are working in Windows and starting R by clicking on the shortcut,
  just change the Run: property of the shortcut.  (Right click it, choose
  properties...)

  Duncan Murdoch


__
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 start R in maximized size???

2012-03-16 Thread Christofer Bogaso
But unfortunately it did not work for me. I am using R-2.14.2 with
windows 7 home basic

Thanks,

On Fri, Mar 16, 2012 at 8:26 PM, Duncan Murdoch
murdoch.dun...@gmail.com wrote:
 On 16/03/2012 10:35 AM, Christofer Bogaso wrote:

 No no, I meant to say the console window, where we type the syntax etc.

 BTW, what is the official name of this window?


 I think console window is good enough.

 Duncan Murdoch

 Thanks,

 On Fri, Mar 16, 2012 at 8:15 PM, Duncan Murdoch
 murdoch.dun...@gmail.com  wrote:
   On 16/03/2012 10:23 AM, Christofer Bogaso wrote:
 
   Dear all, when I start R, I want that the console window should be in
   the Maximized size automatically. Can somebody help me how to achieve
   that?
 
 
   If you are working in Windows and starting R by clicking on the
  shortcut,
   just change the Run: property of the shortcut.  (Right click it,
  choose
   properties...)
 
   Duncan Murdoch



__
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] plot columns

2012-03-16 Thread R. Michael Weylandt michael.weyla...@gmail.com
plot(codon3 ~ codon1, data = table) should work but I'm not in a position to 
verify. If for some reason it doesn't does

plot(codon3 ~ codon1, data = as.data.frame(table))

get it?

Michael

On Mar 16, 2012, at 10:32 AM, aoife doherty aoife.m.dohe...@gmail.com wrote:

 Hey guys, can anyone help?
 
 i have a sample table:
 
 table - structure(c(4, 7, 0.2, 3, .1, 7, 222, 3, 10, 5, 11,
  8, 8, 10, 7), .Dim = c(5L, 3L), .Dimnames = list(c(gene1,
  gene2, gene3, gene4, gene5), c(codon1, codon2,
  codon3)))
 
 table
 
  codon1 codon2 codon3
 gene14.0  7 11
 gene27.0222  8
 gene30.2  3  8
 gene43.0 10 10
 gene50.1  5  7
 
 
 i want to plot column 1 versus column 3.
 
 Does anyone know how to read in particular columns and plot?
 
 i was looking at this:
 
 https://stat.ethz.ch/pipermail/r-help/2007-July/137638.html
 
 but i can't seem to alter it to my needs
 
 Thank you
 Aoife
 
[[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] Timer on a function

2012-03-16 Thread William Dunlap
 From: Prof Brian Ripley [mailto:rip...@stats.ox.ac.uk]
 Using setTimeLimit(transient = TRUE) is slightly simpler here.

Brian,

I thought I should have been able to use transient=TRUE instead of the
on.exit(setTimeLimit()) but that gave me an unwanted error report after
the top-level expression finished (if there was no timeout).   E.g.,

 to - function(expr, ...) {
+   setTimeLimit(..., transient=TRUE)
+   expr
+ }
 f - function(n) sum(sapply(seq_len(n), function(i)1/i)) - log(n)
 to(f(1e7), elapsed=1)
Error in FUN(1:1000[[371022L]], ...) : reached elapsed time limit
 to(f(1e2), elapsed=1)
[1] 0.5822073
Error: reached elapsed time limit
 
 
 sessionInfo()
R version 2.14.2 (2012-02-29)
Platform: x86_64-pc-mingw32/x64 (64-bit)

locale:
[1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252  
 
[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C 
 
[5] LC_TIME=English_United States.1252

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

(On a new 64-bit Windows 7 PC)
 
Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com


 -Original Message-
 From: Prof Brian Ripley [mailto:rip...@stats.ox.ac.uk]
 Sent: Friday, March 16, 2012 4:28 AM
 To: Bert Gunter
 Cc: William Dunlap; r-help@r-project.org; Ramiro Barrantes
 Subject: Re: [R] Timer on a function
 
 On Thu, 15 Mar 2012, Bert Gunter wrote:
 
  Bill et. al:
 
  1. This is new to me. Thanks.
 
  2. As I read the man page, this is not guaranteed to work if the model
  fitting function does not contain sufficient interrupts. Is that
  correct?
 
 Yes.  If someone wrote a model fitting package in Fortran with no
 callbacks then it is not interruptible, including not by timers.  In
 that case all you can do is to kill the R session.
 
 The author of setTimeLimit()
 
 
  -- Bert
 
  On Thu, Mar 15, 2012 at 4:14 PM, William Dunlap wdun...@tibco.com wrote:
  There is a setTimeLimit function in base.  It could be encapsulated into
  the following to limit the time spent on an expression:
 
  timeOut - function (expr, ...)  {
     on.exit(setTimeLimit())
     setTimeLimit(...)
     expr
  }
 
 Using setTimeLimit(transient = TRUE) is slightly simpler here.
 
  E.g., with the following slow way to compute Euler's phi
    f - function(n) sum(sapply(seq_len(n), function(i)1/i)) - log(n)
  I get
    timeOut(f(1e5), elapsed=1)
   [1] 0.5772207
    timeOut(f(1e6), elapsed=1)
   Error in FUN(1:100[[711624L]], ...) : reached elapsed time limit
  Use try() or tryCatch() to check for the error.  E.g.,
    sapply(1:7, function(n)tryCatch(timeOut(f(10^n), elapsed=1), 
  error=function(e)-1))
   [1]  0.6263832  0.5822073  0.5777156  0.5772657  0.5772207 -1.000 
  -1.000
  You could look at 'e' in the error handler to see if it is a time out 
  problem.
 
  Bill Dunlap
  Spotfire, TIBCO Software
  wdunlap tibco.com
 
  -Original Message-
  From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] 
  On
 Behalf
  Of Bert Gunter
  Sent: Thursday, March 15, 2012 3:05 PM
  To: Ramiro Barrantes
  Cc: r-help@r-project.org
  Subject: Re: [R] Timer on a function
 
  On Thu, Mar 15, 2012 at 2:24 PM, Ramiro Barrantes
  ram...@precisionbioassay.com wrote:
     Hello,
 
  I have a program that consists of a loop fitting a function over many
  models.  Sometimes the fitting on a particular model takes minutes to 
  converge.  Is
 there
  a way that I can limit the amount of time that R spends on a given model:
 
  AFAIK, no -- this is an OS level issue.
 
  Of course, most iterative fitting procedures have controls for the
  number of iterations, convergence criteria, etc. , but there is no
  awareness of timing except when the OS is interrogated, e.g. by
  ?proc.time or ?system.time . Such calls would have to be built into
  the fitting function or OS level services would have to be invoked to
  run the R process with timing limitations built in. See e.g. ?Rscript
  for one possible approach.
 
  Corrections or clever tricks to get around these perceived limitations
  welcomed, of course.
 
  -- Bert
 
  Cheers,
  Bert
 
  say if my line is:
 
  fittingFunction( func, model.1)
 
  can I have some function:
 
  stopIfUnderTime(  fittingFunction( func, model.1) , 5 )
 
  where stopIfUnderTime will return the result if it finishes under 5 
  seconds, or NA
  otherwise.
 
  Is there anything like this?  (just looked through the web but did not 
  find anything)
 
  Thanks,
  Ramiro
 
 
 
         [[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.
 
 
 
  --
 
  Bert Gunter
  Genentech Nonclinical Biostatistics
 
  Internal Contact Info:
  Phone: 467-7374
  Website:
  

Re: [R] Re : Elegant Code

2012-03-16 Thread Ranjan Maitra
Wonder if this is part of some assignment with points on elegance
of code. Sort of when I teach a class..


On Fri, 16 Mar 2012 10:02:48 -0400 Raphael Fraser
raphael.fra...@gmail.com wrote:

 Thank you all. Your responses were very helpful.
 
 Raphael
 
 On Fri, Mar 16, 2012 at 5:04 AM, Daniel Nordlund
 djnordl...@frontier.com wrote:
 
  -Original Message-
  From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
  On Behalf Of Pascal Oettli
  Sent: Friday, March 16, 2012 12:36 AM
  To: Raphael Fraser
  Cc: r-help@r-project.org
  Subject: [R] Re : Elegant Code
 
  Hi Raphael,
 
  Something like that?
 
  require(pscl)sim - numeric()
  for(i in 1:5){
    eval(parse(text=paste('b',i,' - rigamma(50,1,1)',sep='')))
    eval(parse(text=paste('theta',i,' -
  rgamma(50,0.5,(1/b',i,'))',sep='')))
    eval(parse(text=paste('sim',i,' - rpois(50,theta',1,')',sep='')))
    eval(parse(text=paste('sim - cbind(sim, sim',i,')',sep='')))
  }
  x11()
  par(mfrow=c(1,5))
  boxplot(c(sim1,sim2,sim3,sim4,sim5))
 
  x11()
  boxplot(sim)
 
 
  Regards,
  Pascal
 
 
  - Mail original -
  De : Raphael Fraser raphael.fra...@gmail.com
  À : r-help@r-project.org
  Cc :
  Envoyé le : Vendredi 16 mars 2012 16h09
  Objet : [R] Elegant Code
 
  Hi,
 
  Can anyone help to write a more elegant version of my code? I am sure
  this can be put into a loop but I am having trouble creating the
  objects b1,b2,b3,...,etc.
 
  b1 - rigamma(50,1,1)
  theta1 - rgamma(50,0.5,(1/b1))
  sim1 - rpois(50,theta1)
 
  b2 - rigamma(50,1,1)
  theta2 - rgamma(50,0.5,(1/b2))
  sim2 - rpois(50,theta2)
 
  b3 - rigamma(50,1,1)
  theta3 - rgamma(50,0.5,(1/b3))
  sim3 - rpois(50,theta3)
 
  b4 - rigamma(50,1,1)
  theta4 - rgamma(50,0.5,(1/b4))
  sim4 - rpois(50,theta4)
 
  b5 - rigamma(50,1,1)
  theta5 - rgamma(50,0.5,(1/b5))
  sim5 - rpois(50,theta5)
 
 
 
  par(mfrow=c(1,5))
  boxplot(sim1)
  boxplot(sim2)
  boxplot(sim3)
  boxplot(sim4)
  boxplot(sim5);
 
  Thanks,
  Raphael
 
 
  Or, just get rid of the for loops altogether, something like this
 
  trials -5
  N - 50
  b    - rigamma(N*trials, 1, 1)
  theta - rgamma(N*trials,0.5,1/b)
  sim   - rpois(N*trials,theta)
 
  dim(sim) - c(N,trials)
 
  boxplot(sim)
 
 
  Hope this is helpful,
 
  Dan
 
  Daniel Nordlund
  Bothell, WA USA
 
  __
  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-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] Singleton pattern

2012-03-16 Thread Bryan Hanson
Since no one else has bit, I'll take a stab.  I'm an experienced R person, 
but I've recently been teaching myself objective-c and I've been using 
singletons quite a bit (and mis-using them quite a bit!).  Not a computer 
scientist at all.  You've been warned.

I don't think there is a comparable concept in R.  You do have a choice of S3 
or S4 classes for your object orientation in R.  S3 is very loose in that you 
can add to S3 objects readily and abuse them a lot.  There really is no 
checking of them unless you implement it manually.  S4 objects are much 
tighter and they are less readily modified and are self-checking (I know some 
will complain about this characterization but  it's approximately correct).  So 
perhaps you want an S4 object so it's less likely to get mangled, but I doubt 
there is a way to prevent users from copying it, which would be more along the 
lines of a singleton.

You can google the archives for some great discussions of S3 vs S4 if that 
sounds interesting.

Bryan

***
Bryan Hanson
Professor of Chemistry  Biochemistry
DePauw University

On Mar 16, 2012, at 7:47 AM, David Cassany wrote:

 Hi all,
 
 I know it may not have much sense thinking about a Singleton Pattern in an
 R application which doesn't use any OOP facilities, however I'm curious to
 know if anybody faced the same issue. I've been googling but using
 singleton pattern as a key word leads to typical OOP languages like Java
 or C++ among others.
 
 So my problem is that I'd like to ensure some very big objects aren't
 copied again and again in some other variables. In the worst case I'll
 check all code by myself to ensure it but in this case the application
 won't force programmers to take it in consideration which is what I am
 really looking for.
 
 Any advice will be highly appreciated :P
 
 Thanks!
 -- 
 *David Cassany Viladomat
 Software Developer
 Transmural Biote**ch S.L*
 
   [[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] Problem reading mixed CSV file

2012-03-16 Thread jim holtman
What do you mean by Mixed?  If a field has a comma, then it is
supposed be to enclosed in quotes.  You could preprocess the file
looking for cases where there are more fields than there there are
supposed to be, and if they are always in the same place, you could
enclose them in quotes and then reprocess.  You would really have to
show what the file looks like for the different mixed cases to get a
good answer to your question.  And of course, R can do it, if we knew
what it was we are supposed to do.

So at least  provide commented, minimal, self-contained, reproducible
code and data.

On Fri, Mar 16, 2012 at 7:03 AM, Ashish Agarwal
ashish.agarw...@gmail.com wrote:
 I am having trouble reading this CSV file in R. There are six attributes
 that I need to read  - CVar1, CVar2, Location, Year, Nvar3, Nvar4. Can
 somebody help in reading this file?
 On line 10 it has city and state separated by comma. I had been a user of
 SAS where I can use different format to read in for this line. Can I do
 this in R too?

 __
 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?
Tell me what you want to do, not how you want to do it.

__
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] Faster way to implement this search?

2012-03-16 Thread Walter Anderson
I am working on a simulation where I need to count the number of matches 
for an arbitrary pattern in a large sequence of binomial factors.  My 
current code is


for(indx in 1:(length(bin.05)-3))
  if ((bin.05[indx] == test.pattern[1])  (bin.05[indx+1] == 
test.pattern[2])  (bin.05[indx+2] == test.pattern[3]))
return.values$count.match.pattern[1] = 
return.values$count.match.pattern[1] + 1


Since I am running the above code for each simulation multiple times on 
sequences of 10,000,000 factors the code is taking longer than I would 
like.   Is there a better (more R way of achieving the same answer?


Walter Anderson

__
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] quadprog error?

2012-03-16 Thread none
I forgot to attach the problem data, 'quadprog.Rdata' file, in my prior 
email.



I want to report a following error with quadprog. The solve.QP function
finds a solution to the problem below that violates the last equality
constraint. I tried to solve the same problem using ipop from kernlab
package and get the solution in which all equality constraints are
enforced. I also tried an old version of quadprog, Version: 1.4-11,
Date: 2007-07-12 and my problem is solved correctly.

I have tried to contact Berwin A. Turlach berwin.turl...@gmail.com
(maintainer for quadprog package) a week ago, with no success.


##
load(file='quadprog.Rdata') 

# solve QP using quadprog   
require(quadprog)
sol = solve.QP(Dmat, dvec, Amat, bvec, meq)
x = sol$solution
check = x %*% Amat - bvec   
# for some reason last equality constraint is violated
round(check[1:meq], 4)


# solve QP using kernlab
require(kernlab)
n = nrow(Amat)
sv = ipop(c = matrix(dvec), H = Dmat, A = t(Amat[,1:meq]),
b = bvec[1:meq], l = rep(-1000, n),
u = rep(1000, n), r = rep(0,meq))

x = primal(sv)
check = x %*% Amat - bvec   
# all constraints are ok
round(check[1:meq], 4)





__
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] Singleton pattern

2012-03-16 Thread j verzani
David Cassany david.cassany at transmuralbiotech.com writes:

 
 Hi all,
 
 I know it may not have much sense thinking about a Singleton Pattern in an
 R application which doesn't use any OOP facilities, however I'm curious to
 know if anybody faced the same issue. I've been googling but using
 singleton pattern as a key word leads to typical OOP languages like Java
 or C++ among others.
 

While it isn't too hard to implement the Singleton pattern using reference 
classes, I would think for what you want to do the memoise package can 
be used. Create a wrapper function to return the objects and the cached
value will be returned each time.


 So my problem is that I'd like to ensure some very big objects aren't
 copied again and again in some other variables. In the worst case I'll
 check all code by myself to ensure it but in this case the application
 won't force programmers to take it in consideration which is what I am
 really looking for.
 
 Any advice will be highly appreciated :P
 
 Thanks!

__
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] Singleton pattern

2012-03-16 Thread Jan T. Kim
Using the singleton pattern in R has never occurred to me so far, as
I think it applies to languages that support multiple references to
one instance. R doesn't do that, at least not in ways that would be
required for applying the singleton pattern as described in the GoF book,
anyway. One would have to use closures and / or environments to
approximate references, I suppose.

When passed around as parameters, R objects don't get copied unless
the called function starts modifying them, so if the primary concern
is to prevent unnecessary / costly copying of bulky objects, creating
the thing once and then passing it around as necessary, taking care
that called functions don't change it, is perhaps good enough.

Best regards, Jan

On Fri, Mar 16, 2012 at 12:15:27PM -0400, Bryan Hanson wrote:
 Since no one else has bit, I'll take a stab.  I'm an experienced R person, 
 but I've recently been teaching myself objective-c and I've been using 
 singletons quite a bit (and mis-using them quite a bit!).  Not a computer 
 scientist at all.  You've been warned.
 
 I don't think there is a comparable concept in R.  You do have a choice of S3 
 or S4 classes for your object orientation in R.  S3 is very loose in that you 
 can add to S3 objects readily and abuse them a lot.  There really is no 
 checking of them unless you implement it manually.  S4 objects are much 
 tighter and they are less readily modified and are self-checking (I know 
 some will complain about this characterization but  it's approximately 
 correct).  So perhaps you want an S4 object so it's less likely to get 
 mangled, but I doubt there is a way to prevent users from copying it, which 
 would be more along the lines of a singleton.
 
 You can google the archives for some great discussions of S3 vs S4 if that 
 sounds interesting.
 
 Bryan
 
 ***
 Bryan Hanson
 Professor of Chemistry  Biochemistry
 DePauw University
 
 On Mar 16, 2012, at 7:47 AM, David Cassany wrote:
 
  Hi all,
  
  I know it may not have much sense thinking about a Singleton Pattern in an
  R application which doesn't use any OOP facilities, however I'm curious to
  know if anybody faced the same issue. I've been googling but using
  singleton pattern as a key word leads to typical OOP languages like Java
  or C++ among others.
  
  So my problem is that I'd like to ensure some very big objects aren't
  copied again and again in some other variables. In the worst case I'll
  check all code by myself to ensure it but in this case the application
  won't force programmers to take it in consideration which is what I am
  really looking for.
  
  Any advice will be highly appreciated :P
  
  Thanks!
  -- 
  *David Cassany Viladomat
  Software Developer
  Transmural Biote**ch S.L*
  
  [[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.

-- 
 +- Jan T. Kim ---+
 | email: jtt...@gmail.com|
 | WWW:   http://www.jtkim.dreamhosters.com/  |
 *-=  hierarchical systems are for files, not for humans  =-*

__
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] a question about writing C extensions to functions

2012-03-16 Thread Erin Hodgess
Dear R People:

I'm not sure if I should ask this here or in Rcpp, but I thought I'd
start here first.

If I'm writing a C program, when do I know to use SEXP vs. int or float, please?

Thanks,
Erin


-- 
Erin Hodgess
Associate Professor
Department of Computer and Mathematical Sciences
University of Houston - Downtown
mailto: erinm.hodg...@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.


[R] bias sampling

2012-03-16 Thread niloo javan
hi
i want to analyze Right Censore-Length bias data under cox model with covariate.
what is the package ?
tank you.
[[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] Problem reading mixed CSV file

2012-03-16 Thread Ashish Agarwal
I want to import this CSV file into R.

The CSV file is

,,,1968,21,0
,,Boston,1968,13,0
,,Boston,1968,18,0
,,Chicago,1967,44,0
,,Providence,1968,17,0
,,Providence,1969,48,0
,,Binky,1968,24,0
,,Chicago,1968,23,0
,,Dally,1968,7,0
,,Raleigh, North Carol,1968,25,0
Addy ABC-Dogs Stars-W8.1,,Providence,1968,38,0
DEF_REQPRF/,,Dartmouth,1967,31,1
PL,,,1967,38,1
XY,PopatLal,,1967,5,1
XY,PopatLal,,1967,6,8
XY,PopatLal,,1967,7,7
XY,PopatLal,,1967,9,1
XY,PopatLal,,1967,10,1
XY,PopatLal,,1967,13,1
XY,PopatLal,Boston,1967,6,1
XY,PopatLal,Boston,1967,7,11
XY,PopatLal,Boston,1967,9,2
XY,PopatLal,Boston,1967,10,3
XY,PopatLal,Boston,1967,7,2

I tried using scan and read.table but results are not visible :(

 scan(D:/data/temp.csv,list(,,,0,0,0),sep=,) -x
Read 51 records
 x
[[1]]
 [1] ÿþ                                        
[16]                                           
[31]                                           
[46]                


 read.table(D:/data/temp.csv,header=F,sep=,) -x
 x
V1 V2
1   ÿþ NA
2  NA
3  NA
4  NA

Can somebody please help in importing this CSV file?

__
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] quadprog error?

2012-03-16 Thread David Winsemius


On Mar 16, 2012, at 12:20 PM, none wrote:

I forgot to attach the problem data, 'quadprog.Rdata' file, in my  
prior email.


Please read the Posting Guide's description of what kind of  
attachments the mail-server will accept.


--
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] Faster way to implement this search?

2012-03-16 Thread Sarah Goslee
There's almost certainly a better way, but I'd be more inclined to look for
it if you'd provide a small reproducible example so I could actually try it.
Without knowing the structure of your data, it's very hard to offer
alternatives.

Sarah

On Fri, Mar 16, 2012 at 12:59 PM, Walter Anderson wandrso...@gmail.com wrote:
 I am working on a simulation where I need to count the number of matches for
 an arbitrary pattern in a large sequence of binomial factors.  My current
 code is

    for(indx in 1:(length(bin.05)-3))
      if ((bin.05[indx] == test.pattern[1])  (bin.05[indx+1] ==
 test.pattern[2])  (bin.05[indx+2] == test.pattern[3]))
        return.values$count.match.pattern[1] =
 return.values$count.match.pattern[1] + 1

 Since I am running the above code for each simulation multiple times on
 sequences of 10,000,000 factors the code is taking longer than I would like.
   Is there a better (more R way of achieving the same answer?

 Walter Anderson

-- 
Sarah Goslee
http://www.functionaldiversity.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] Problem reading mixed CSV file

2012-03-16 Thread David Winsemius


On Mar 16, 2012, at 1:11 PM, Ashish Agarwal wrote:


I want to import this CSV file into R.

The CSV file is

,,,1968,21,0
,,Boston,1968,13,0
,,Boston,1968,18,0
,,Chicago,1967,44,0
,,Providence,1968,17,0
,,Providence,1969,48,0
,,Binky,1968,24,0
,,Chicago,1968,23,0
,,Dally,1968,7,0
,,Raleigh, North Carol,1968,25,0
Addy ABC-Dogs Stars-W8.1,,Providence,1968,38,0
DEF_REQPRF/,,Dartmouth,1967,31,1
PL,,,1967,38,1
XY,PopatLal,,1967,5,1
XY,PopatLal,,1967,6,8
XY,PopatLal,,1967,7,7
XY,PopatLal,,1967,9,1
XY,PopatLal,,1967,10,1
XY,PopatLal,,1967,13,1
XY,PopatLal,Boston,1967,6,1
XY,PopatLal,Boston,1967,7,11
XY,PopatLal,Boston,1967,9,2
XY,PopatLal,Boston,1967,10,3
XY,PopatLal,Boston,1967,7,2

I tried using scan and read.table but results are not visible :(


scan(D:/data/temp.csv,list(,,,0,0,0),sep=,) -x

Read 51 records

x

[[1]]
 [1] ÿþ   
  
[16]  
  
[31]  
  

[46]



read.table(D:/data/temp.csv,header=F,sep=,) -x
x

   V1 V2
1   ÿþ NA
2  NA
3  NA
4  NA

Can somebody please help in importing this CSV file?


Looks like an encoding mismatch. You have not offered the requested  
information about you setup so further comment would all be guesswork.  
But you can perhaps educate yourself by reading:


?Encoding

And line ten has 7 elements.

 count.fields(textConnection(,,,1968,21,0
+ ,,Boston,1968,13,0
+ ,,Boston,1968,18,0
+ ,,Chicago,1967,44,0
+ ,,Providence,1968,17,0
+ ,,Providence,1969,48,0
+ ,,Binky,1968,24,0
+ ,,Chicago,1968,23,0
+ ,,Dally,1968,7,0
+ ,,Raleigh, North Carol,1968,25,0
+ Addy ABC-Dogs Stars-W8.1,,Providence,1968,38,0
+ DEF_REQPRF/,,Dartmouth,1967,31,1
+ PL,,,1967,38,1
+ XY,PopatLal,,1967,5,1
+ XY,PopatLal,,1967,6,8
+ XY,PopatLal,,1967,7,7
+ XY,PopatLal,,1967,9,1
+ XY,PopatLal,,1967,10,1
+ XY,PopatLal,,1967,13,1
+ XY,PopatLal,Boston,1967,6,1
+ XY,PopatLal,Boston,1967,7,11
+ XY,PopatLal,Boston,1967,9,2
+ XY,PopatLal,Boston,1967,10,3
+ XY,PopatLal,Boston,1967,7,2),sep=,)
 [1] 6 6 6 6 6 6 6 6 6 7 6 6 6 6 6 6 6 6 6 6 6 6 6 6



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


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] Faster way to implement this search?

2012-03-16 Thread William Dunlap
You didn't show your complete code but the following may help you speed things 
up.
Compare a function, f0, structured like your code and one, f1, that calls sum 
once
instead of counting length(x)-3 times.

f0 - function(x, test.pattern) {
count - 0
for(indx in seq_len(length(x)-3)) {
   if ((x[indx] == test.pattern[1])  (x[indx+1] == test.pattern[2])  
(x[indx+2] == test.pattern[3])) {
   count - count + 1
   }
}
count
}

f1 - function(x, test.pattern) {
indx - seq_len(length(x)-3)
sum((x[indx] == test.pattern[1])  (x[indx+1] == test.pattern[2])  
(x[indx+2] == test.pattern[3]))
}


 bin.05 - round((log10(1:1000)%%1e-3 - log10(1:1000)%%1e-4) * 1e4) # 
 quasi-random sample of 10^7 from {0,...,9}
 system.time(print(f0(bin.05, c(2,3,3
[1] 3194
   user  system elapsed 
  14.350.00   14.35 
 system.time(print(f1(bin.05, c(2,3,3
[1] 3194
   user  system elapsed 
   0.700.210.90

You are probably also slowing things down by doing
yourList$yourCounts[1] - yourList$yourCounts[1] + 1
many times instead of
   count - yourList$yourCounts[1]
once and
   count - count + 1
many times.  The former evaluates $, [, $-, and [- many
times and the $- and [- in particular may use a fair bit of time.
   

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com


 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
 Behalf
 Of Walter Anderson
 Sent: Friday, March 16, 2012 10:00 AM
 To: R Help
 Subject: [R] Faster way to implement this search?
 
 I am working on a simulation where I need to count the number of matches
 for an arbitrary pattern in a large sequence of binomial factors.  My
 current code is
 
  for(indx in 1:(length(bin.05)-3))
if ((bin.05[indx] == test.pattern[1])  (bin.05[indx+1] ==
 test.pattern[2])  (bin.05[indx+2] == test.pattern[3]))
  return.values$count.match.pattern[1] =
 return.values$count.match.pattern[1] + 1
 
 Since I am running the above code for each simulation multiple times on
 sequences of 10,000,000 factors the code is taking longer than I would
 like.   Is there a better (more R way of achieving the same answer?
 
 Walter Anderson
 
 __
 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] Changing axis labels depending on panel in lattice

2012-03-16 Thread Saptarshi Guha
Hello,

I am lattice scatterplot that has 2 panels (could be a few more). Both
panels have a y-axis label that is different on the
left and right sides. However the right hand side axis labelling depends on
which panel i'm in .

(I am plotting two curves in one panel, the left y-axis has the scale for
the red line and the right y-axis has the scale for the blue line
I need to convert the y-lims for blue to the scales of the red line. Since
the scales depend on the panel, all i need to know
is which panel i'm in.)

Im using  ,axis=axis.PCT in xyplot and right now



axis.PCT-
function(side, ...)
{
ylim - current.panel.limits()$ylim
switch(side,
   left = {
   prettyF - pretty(ylim)
   panel.axis(side = side, outside = TRUE,text.cex=0.5,rot=0,
  at = prettyF, labels = prettyF)
   },
   axis.default(side = side, ...))

Is there anything i can do get the information regarding the panel i'm in?

Regards
Saptarshi

[[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] Changing axis labels depending on panel in lattice

2012-03-16 Thread David Winsemius


On Mar 16, 2012, at 1:34 PM, Saptarshi Guha wrote:


Hello,

I am lattice scatterplot that has 2 panels (could be a few more). Both
panels have a y-axis label that is different on the
left and right sides. However the right hand side axis labelling  
depends on

which panel i'm in .

(I am plotting two curves in one panel, the left y-axis has the  
scale for

the red line and the right y-axis has the scale for the blue line
I need to convert the y-lims for blue to the scales of the red line.  
Since

the scales depend on the panel, all i need to know
is which panel i'm in.)

Im using  ,axis=axis.PCT in xyplot and right now



axis.PCT-
   function(side, ...)
{
   ylim - current.panel.limits()$ylim
   switch(side,
  left = {
  prettyF - pretty(ylim)
  panel.axis(side = side, outside =  
TRUE,text.cex=0.5,rot=0,

 at = prettyF, labels = prettyF)
  },
  axis.default(side = side, ...))

Is there anything i can do get the information regarding the panel  
i'm in?


?panel.number





--

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] Problem reading mixed CSV file

2012-03-16 Thread Ashish Agarwal
Line 10 has City and State that too separated by comma. For line 10
how can I read differently as compared to the other lines?

On Fri, Mar 16, 2012 at 10:59 PM, David Winsemius
dwinsem...@comcast.net wrote:

 On Mar 16, 2012, at 1:11 PM, Ashish Agarwal wrote:

 I want to import this CSV file into R.

 The CSV file is

 ,,,1968,21,0
 ,,Boston,1968,13,0
 ,,Boston,1968,18,0
 ,,Chicago,1967,44,0
 ,,Providence,1968,17,0
 ,,Providence,1969,48,0
 ,,Binky,1968,24,0
 ,,Chicago,1968,23,0
 ,,Dally,1968,7,0
 ,,Raleigh, North Carol,1968,25,0
 Addy ABC-Dogs Stars-W8.1,,Providence,1968,38,0
 DEF_REQPRF/,,Dartmouth,1967,31,1
 PL,,,1967,38,1
 XY,PopatLal,,1967,5,1
 XY,PopatLal,,1967,6,8
 XY,PopatLal,,1967,7,7
 XY,PopatLal,,1967,9,1
 XY,PopatLal,,1967,10,1
 XY,PopatLal,,1967,13,1
 XY,PopatLal,Boston,1967,6,1
 XY,PopatLal,Boston,1967,7,11
 XY,PopatLal,Boston,1967,9,2
 XY,PopatLal,Boston,1967,10,3
 XY,PopatLal,Boston,1967,7,2

 I tried using scan and read.table but results are not visible :(

 scan(D:/data/temp.csv,list(,,,0,0,0),sep=,) -x

 Read 51 records

 x

 [[1]]
  [1] ÿþ                                     
 
 [16]                                        
 
 [31]                                        
 
 [46]                
 

 read.table(D:/data/temp.csv,header=F,sep=,) -x
 x

   V1 V2
 1   ÿþ NA
 2      NA
 3      NA
 4      NA

 Can somebody please help in importing this CSV file?


 Looks like an encoding mismatch. You have not offered the requested
 information about you setup so further comment would all be guesswork. But
 you can perhaps educate yourself by reading:

 ?Encoding

 And line ten has 7 elements.

 count.fields(textConnection(,,,1968,21,0
 + ,,Boston,1968,13,0
 + ,,Boston,1968,18,0
 + ,,Chicago,1967,44,0
 + ,,Providence,1968,17,0
 + ,,Providence,1969,48,0
 + ,,Binky,1968,24,0
 + ,,Chicago,1968,23,0
 + ,,Dally,1968,7,0
 + ,,Raleigh, North Carol,1968,25,0
 + Addy ABC-Dogs Stars-W8.1,,Providence,1968,38,0
 + DEF_REQPRF/,,Dartmouth,1967,31,1
 + PL,,,1967,38,1
 + XY,PopatLal,,1967,5,1
 + XY,PopatLal,,1967,6,8
 + XY,PopatLal,,1967,7,7
 + XY,PopatLal,,1967,9,1
 + XY,PopatLal,,1967,10,1
 + XY,PopatLal,,1967,13,1
 + XY,PopatLal,Boston,1967,6,1
 + XY,PopatLal,Boston,1967,7,11
 + XY,PopatLal,Boston,1967,9,2
 + XY,PopatLal,Boston,1967,10,3
 + XY,PopatLal,Boston,1967,7,2),sep=,)
  [1] 6 6 6 6 6 6 6 6 6 7 6 6 6 6 6 6 6 6 6 6 6 6 6 6



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


 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] summing transfers

2012-03-16 Thread Farley, Robert
I just want the weighted sum of all the cases where either route is found in 
VEHx and the other is found in the previous or subsequent variable.  The only 
examples I can think of producing are the following:

#
 OBDataSumm - read.spss(P:/Data/OBSurveys/OBSurvey-2010-2011/Final Delivery, 
 Metro On-Board O-D 
 Survey/LAMTA_OD_WEIGHTED_DATA_SETS_012512/LAMTA_OD_SUMMARY_WEIGHTED_012512.SAV,
  use.value.labels=TRUE, trim_values = TRUE, trim.factor.names = TRUE, 
 max.value.labels=Inf, to.data.frame=TRUE)
Warning message:
In read.spss(P:/Data/OBSurveys/OBSurvey-2010-2011/Final Delivery, Metro 
On-Board O-D 
Survey/LAMTA_OD_WEIGHTED_DATA_SETS_012512/LAMTA_OD_SUMMARY_WEIGHTED_012512.SAV,
  :
  P:/Data/OBSurveys/OBSurvey-2010-2011/Final Delivery, Metro On-Board O-D 
Survey/LAMTA_OD_WEIGHTED_DATA_SETS_012512/LAMTA_OD_SUMMARY_WEIGHTED_012512.SAV: 
Unrecognized record type 7, subtype 18 encountered in system file


 describe(OBDataSumm,num.desc=c(mean,median,var,sd,valid.n),xname=NA,maxfac=10,show.pc=TRUE)
Description of OBDataSumm 

Numeric
  meanmedian   varsd   valid.n
SAMPN2.155e+05 1.733e+05 1.151e+10 1.073e+05 3.378e+04

~snip~

expfactor1.168 1.0890.19750. 3.378e+04
expwgt   41.93 22.22  7720 87.87 3.378e+04
ltfactor0.6339   0.5   0.081280.2851 3.378e+04
ltweight  26.7 12.42  4473 66.88 3.378e+04

Factor

~snip~

VEH1
Value Count Percent
MT-802 1645 4.87 
MT-801 1211 3.58 
MT-804  975 2.89 
MT-803  568 1.68 
MT-.51  510 1.51 
MT-720  460 1.36 
MT-.60  433 1.28 
MT-.18  409 1.21 
MT-.81  396 1.17 
MT-805  396 1.17 
mode = MT-802  Valid n = 33782   467 categories - only 
first 10 shown

VEH2
Value Count Percent
  1214235.94 
MT-802 2304 6.82 
MT-801 1375 4.07 
MT-803  874 2.59 
MT-804  598 1.77 
MT-901  527 1.56 
MT-805  461 1.36 
MT-720  323 0.96 
MT-910  268 0.79 
MT-207  260 0.77 
mode = Valid n = 33782   379 categories - only 
first 10 shown

VEH3
Value Count Percent
  2579576.36 
MT-802  883 2.61 
MT-801  600 1.78 
MT-901  256 0.76 
MT-803  251 0.74 
MT-804  227 0.67 
MT-805  126 0.37 
MT-224  114 0.34 
MT-720  113 0.33 
MT-204  105 0.31 
mode = Valid n = 33782   378 categories - only 
first 10 shown

VEH4
Value Count Percent
  3153293.34 
MT-801  126 0.37 
MT-802  111 0.33 
MT-901   89 0.26 
MT-804   74 0.22 
MT-803   71 0.21 
MT-224   38 0.11 
MT-741   36 0.11 
MT-.60   34  0.1 
MT-207   33  0.1 
mode = Valid n = 33782   321 categories - only 
first 10 shown

VEH5
Value Count Percent
   ...3327098.48 
MT-803 ...   18 0.05 
MT-802 ...   13 0.04 
MT-233 ...   11 0.03 
MT-741 ...   11 0.03 
MT-804 ...   11 0.03 
MT-234 ...   10 0.03 
MT-801 ...9 0.03 
MT-901 ...9 0.03 
MT-.60 ...8 0.02 
mode = Valid n = 33782   
187 categories - only first 10 shown

VEH6
Value Count Percent
   ...3370099.76 
MT-232 ...3 0.01 
MT-741 ...3 0.01 
MT-802 

Re: [R] Problem reading mixed CSV file

2012-03-16 Thread Peter Ehlers

On 2012-03-16 10:48, Ashish Agarwal wrote:

Line 10 has City and State that too separated by comma. For line 10
how can I read differently as compared to the other lines?


Edit the file and put quotes around the city-state combination:
 Raleigh, North Carol

Also: always run count.fields() on your files before importing.

Peter Ehlers



On Fri, Mar 16, 2012 at 10:59 PM, David Winsemius
dwinsem...@comcast.net  wrote:


On Mar 16, 2012, at 1:11 PM, Ashish Agarwal wrote:


I want to import this CSV file into R.

The CSV file is

,,,1968,21,0
,,Boston,1968,13,0
,,Boston,1968,18,0
,,Chicago,1967,44,0
,,Providence,1968,17,0
,,Providence,1969,48,0
,,Binky,1968,24,0
,,Chicago,1968,23,0
,,Dally,1968,7,0
,,Raleigh, North Carol,1968,25,0
Addy ABC-Dogs Stars-W8.1,,Providence,1968,38,0
DEF_REQPRF/,,Dartmouth,1967,31,1
PL,,,1967,38,1
XY,PopatLal,,1967,5,1
XY,PopatLal,,1967,6,8
XY,PopatLal,,1967,7,7
XY,PopatLal,,1967,9,1
XY,PopatLal,,1967,10,1
XY,PopatLal,,1967,13,1
XY,PopatLal,Boston,1967,6,1
XY,PopatLal,Boston,1967,7,11
XY,PopatLal,Boston,1967,9,2
XY,PopatLal,Boston,1967,10,3
XY,PopatLal,Boston,1967,7,2

I tried using scan and read.table but results are not visible :(


scan(D:/data/temp.csv,list(,,,0,0,0),sep=,) -x


Read 51 records


x


[[1]]
  [1] ÿþ 

[16]

[31]

[46]



read.table(D:/data/temp.csv,header=F,sep=,) -x
x


   V1 V2
1   ÿþ NA
2  NA
3  NA
4  NA

Can somebody please help in importing this CSV file?



Looks like an encoding mismatch. You have not offered the requested
information about you setup so further comment would all be guesswork. But
you can perhaps educate yourself by reading:

?Encoding

And line ten has 7 elements.


count.fields(textConnection(,,,1968,21,0

+ ,,Boston,1968,13,0
+ ,,Boston,1968,18,0
+ ,,Chicago,1967,44,0
+ ,,Providence,1968,17,0
+ ,,Providence,1969,48,0
+ ,,Binky,1968,24,0
+ ,,Chicago,1968,23,0
+ ,,Dally,1968,7,0
+ ,,Raleigh, North Carol,1968,25,0
+ Addy ABC-Dogs Stars-W8.1,,Providence,1968,38,0
+ DEF_REQPRF/,,Dartmouth,1967,31,1
+ PL,,,1967,38,1
+ XY,PopatLal,,1967,5,1
+ XY,PopatLal,,1967,6,8
+ XY,PopatLal,,1967,7,7
+ XY,PopatLal,,1967,9,1
+ XY,PopatLal,,1967,10,1
+ XY,PopatLal,,1967,13,1
+ XY,PopatLal,Boston,1967,6,1
+ XY,PopatLal,Boston,1967,7,11
+ XY,PopatLal,Boston,1967,9,2
+ XY,PopatLal,Boston,1967,10,3
+ XY,PopatLal,Boston,1967,7,2),sep=,)
  [1] 6 6 6 6 6 6 6 6 6 7 6 6 6 6 6 6 6 6 6 6 6 6 6 6




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



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-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] eigenvalues of matrices of partial derivatives with ryacas

2012-03-16 Thread Adam Zeilinger

Dear Gabor,

Thank you so much for your help!  Your suggested code worked!

I have a couple of questions.  I'm trying to understand your code so I 
can use it in future programming needs.  First, my understanding of the 
first line of your code is that it creates an R function EigenValues 
that corresponds to the Yacas function of the same name:


EigenValues - function(x) Sym(EigenValues(, x, ))

The x variable is kind of a place holder for the product of the 
matrices for which I want the eigenvalues, correct?  Can you explain the 
use of the two sets of quotes in the Sym function?  Why does the x have 
to be outside quotes and why did you include the commas on either side 
of the x?


Second, the term xx^2 appears in the result of the eigenvalue call.  
If I ignore this term, this answer is equivalent to the answer I get in 
Mathematica.  How should I interpret this term, since x only appears in 
the EigenValue R function and is not part of my model?


Finally, I am using TinnR 2.3.6.3 as an R-GUI.  When I'm using Ryacas 
functions, I can send single lines of code to R via TinnR, but I get the 
following error message when I send multiple lines of code:


 source(.trPaths[4], echo=TRUE, max.deparse.length=150)
Error in srcfilecopy(filename, lines, file.info(filename)[1, mtime]) :
  unused argument(s) (file.info(filename)[1, mtime])

Any thoughts on what the problem might be and how to troubleshoot it?

Thanks again for your help!

Adam




On 3/15/2012 5:16 PM, Gabor Grothendieck wrote:

On Thu, Mar 15, 2012 at 7:51 PM, Adam Zeilingerzeil0...@umn.edu  wrote:

Hello,

I am trying to construct two matrices, F and V, composed of partial
derivatives and then find the eigenvalues of F*Inverse(V).  I have the
following equations in ryacas notation:


library(Ryacas)
FIh- Expr(betah*Sh*Iv)
FIv- Expr(betav*Sv*Ih)
VIh- Expr((muh + gamma)*Ih)
VIv- Expr(muv*Iv)

I successfully found the partial derivatives:


f11- deriv(FIh, Ih)
f12- deriv(FIh, Iv)
f21- deriv(FIv, Ih)
f22- deriv(FIv, Iv)
v11- deriv(VIh, Ih)
v12- deriv(VIh, Iv)
v21- deriv(VIv, Ih)
v22- deriv(VIv, Iv)

Next I would like to put these partial derivatives into two matrices, F and
V:


F- Expr({{f11, f12}, {f21, f22}})
V- Expr({{v11, v12}, {v21, v22}})

Finally, I would like to find the eigenvalues of F*Inverse(V).  Something
like:


  yacas(EigenValues(F*Inverse(V)))

However, this does not work.  I get the following error message:

In function While : bad argument number 1 (counting from 1)The offending
argument $ii49= $nr49 evaluated to Not Length-10CommandLine(1) : Invalid
argument

According to Mathematica, the correct eigenvalues are:

{-((Sqrt[betah] Sqrt[betav] Sqrt[Sh] Sqrt[Sv])/Sqrt[gamma muv + muh muv]),
   (Sqrt[betah] Sqrt[betav] Sqrt[Sh] Sqrt[Sv])/Sqrt[gamma muv + muh muv]}

I don't understand the error message.  Any suggestions on how to get the
correct eigenvalues using R would be greatly appreciated.  I'm using R
2.14.0.

Try doing it this way instead:

library(Ryacas)
EigenValues- function(x) Sym(EigenValues(, x, ))

Iv- Sym(Iv); Ih- Sym(Ih)
Sv- Sym(Sv); Sh- Sym(Sh)
betav- Sym(betav); betah- Sym(betah)
muv- Sym(muv); muh- Sym(muh)
gamma- Sym(gamma)

FIh- betah*Sh*Iv
FIv- betav*Sv*Ih
VIh- (muh + gamma)*Ih
VIv- muv*Iv

f11- deriv(FIh, Ih)
f12- deriv(FIh, Iv)
f21- deriv(FIv, Ih)
f22- deriv(FIv, Iv)
v11- deriv(VIh, Ih)
v12- deriv(VIh, Iv)
v21- deriv(VIv, Ih)
v22- deriv(VIv, Iv)

F- List(List(f11, f12), List(f21, f22))
V- List(List(v11, v12), List(v21, v22))

EigenValues(F * Inverse(V))

For the last line I get:


EigenValues(F*Inverse(V))

expression(Roots(xx^2 - betav * Sv * muv * (betah * Sh * (muh +
 gamma))/((muh + gamma) * muv)^2))



--
Adam Zeilinger
Post Doctoral Scholar
Department of Entomology
University of California Riverside
www.linkedin.com/in/adamzeilinger

__
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] Y-axis label on the right hand side in lattice?

2012-03-16 Thread Saptarshi Guha
Hello,

Is there a way to add ylab on the right hand side also (in lattice)?
Different from the left hand side?

Cheers
Saptarshi

[[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] Problem reading mixed CSV file

2012-03-16 Thread Ashish Agarwal
I have a file that is 5000 records and to edit that file is not easy.
Is there any way to line 10 differently to account for changes in the
third field?

On Fri, Mar 16, 2012 at 11:35 PM, Peter Ehlers ehl...@ucalgary.ca wrote:
 On 2012-03-16 10:48, Ashish Agarwal wrote:

 Line 10 has City and State that too separated by comma. For line 10
 how can I read differently as compared to the other lines?


 Edit the file and put quotes around the city-state combination:
  Raleigh, North Carol


__
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] Y-axis label on the right hand side in lattice?

2012-03-16 Thread Richard M. Heiberger
from ?xyplot
use the
ylab.right
argument



On Fri, Mar 16, 2012 at 2:11 PM, Saptarshi Guha saptarshi.g...@gmail.comwrote:

 Hello,

 Is there a way to add ylab on the right hand side also (in lattice)?
 Different from the left hand side?

 Cheers
 Saptarshi

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


Re: [R] Y-axis label on the right hand side in lattice?

2012-03-16 Thread David Winsemius


On Mar 16, 2012, at 2:53 PM, Richard M. Heiberger wrote:


from ?xyplot
use the
ylab.right
argument





On Fri, Mar 16, 2012 at 2:11 PM, Saptarshi Guha saptarshi.g...@gmail.com 
wrote:



Hello,

Is there a way to add ylab on the right hand side also (in lattice)?
Different from the left hand side?



I thought he wanted facilities provided by

doubleYScale in latticExtra package

--

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] Y-axis label on the right hand side in lattice?

2012-03-16 Thread David Winsemius


On Mar 16, 2012, at 3:03 PM, David Winsemius wrote:



On Mar 16, 2012, at 2:53 PM, Richard M. Heiberger wrote:


from ?xyplot
use the
ylab.right
argument





On Fri, Mar 16, 2012 at 2:11 PM, Saptarshi Guha saptarshi.g...@gmail.com 
wrote:



Hello,

Is there a way to add ylab on the right hand side also (in lattice)?
Different from the left hand side?



I thought he wanted facilities provided by

doubleYScale in latticExtra package

^latticeExtra^


--




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] Spatstat - coordinates in observation window

2012-03-16 Thread Rolf Turner

On 16/03/12 23:02, Lucie V wrote:

Dear R users,

I wish to run spatial point pattern analysis (e.g. pair correlation function, 
mark correlation function) for which I need to create an observation window 
(window=owin) from which the spatial analysis is generated. The command I used 
to create this observation window as follows:

X1- ppp(x, y, window=owin(c(80.58,144.96),c(101.06,165.13)), 
unitname=c(metres,metres), marks=dbh)

Surely this should read

unitname=c(metre,metres)

i.e. singular then plural.


I managed to create the observation window with this command. However, my data 
(x,y coordinates of objects in a square plot) didn't fit into this observation 
window's frame. It seems like I need to 'move or twist' my data by a certain 
angle so that they fit within the border of the observation window's frame. I'm 
not sure how to do that. Is there a command of function for that? I would be 
very grateful for any help or suggestions.

I hope I described my problem so that it is understandable.  Thank you, L.


Why did you choose to use the window owin(c(80.58,144.96),c(101.06,165.13))
if that is not the window containing your points?

In any analysis of spatial point patterns a window should be specified 
(a priori)
and this window should consist of the region in which points were 
observed or

looked for.

Remember that there is information in *where the points aren't* as well 
as in
where they *are*.  You can't tell where points aren't unless you know 
where they've

been looked for.

So your analysis would appear to be on a shaky foundation from the start.

That being said, it is very easy (though unsound and misleading) to 
construct
a window containing all your points in an a posteriori fashion.  Tools 
to do this
include the functions ripras() and clickpoly().  Note that a window need 
*not*

necessarily be a rectangle!

There are also tools for adjusting and transforming existing windows.  See
affine(), rotate(), shift(), erosion(), dilation(), and expand.owin().

Transforming the observed points so that they fit into a given window makes
no sense at all, as far as I can discern.

cheers,

Rolf Turner

__
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] ggplot2: goem_smooth and suppress messages

2012-03-16 Thread Brian Diggs

On 3/15/2012 4:11 PM, tibaker wrote:

Hi

When I run my script using ggplot and geom_smooth I get messages that I
would like to suppress:

p- ggplot(dataSubset)
p- p + aes(x = as.Date(factor(key),format=%Y%m%d)) + geom_line()
p- p + geom_smooth(span=0.2,se=FALSE,size=0.7)

The messages look like this:
geom_smooth: method=auto and size of largest group is1000, so using
loess. Use 'method = x' to change the smoothing method.
There were 15 warnings (use warnings() to see them)


The warning is printed not when p is assigned, but when it is plotted 
(printed).



I have tried
p- p + suppressMessages(geom_smooth(span=0.2,se=FALSE,size=0.7))

but this does not work. I would like to keep using method=auto but without
any messages.

Any ideas on how to suppress the messages when using geom_smooth?
Thank you!


Use suppressWarnings when printing.

p - ggplot(mtcars, aes(wt, mpg)) + geom_smooth()
suppressMessages(print(p))

If you are getting display by implicit printing of the plot, then this 
won't work.


--
Brian S. Diggs, PhD
Senior Research Associate, Department of Surgery
Oregon Health  Science University

__
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-help Digest, Vol 109, Issue 16

2012-03-16 Thread Gerald Lindsly
Q #1: yesterday:

A: 1. Restructure your database with NoSQL.  See MongoDB.org.
    2. Choose application language with which to work (and get Driver)
and write your code.
    3. R package - rmongodb.

__
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] Apt-get

2012-03-16 Thread Scott Raynaud
Ok.  When I type in sudo add-apt-repository ppa:marutter/rrutter
I get a prompt for a password.  I enter my domain password and
get some print about adding the ppa and requeting that I press
enter.  I press enter and this is followed by print stating that 
the key B04C661B is being requested from hkp sevrer 
keyserverubuntu.com followed by connection refused HTTP fetch 
error 7: couldn't connect no valid Open GPG found.
 
I'm not sure what next but I think I need to configure the keyserver.  
Tried this via the command line and it failed.  Maybe creating a 
key.txt file will work but when I search http://keyserver.ubuntu.com:11371/
for E084DAB9 that fails as well.  What next?



From: Tyler Ritchie tyler.ritc...@gmail.com

@r-project.org 
Sent: Thursday, March 15, 2012 1:36 PM
Subject: Re: [R] Apt-get


Beltrand was also on the mark, suggesting you add Michael Rutter's ppa to your 
repository sources. 

In both cases (adding  the CRAN Ubuntu repositories or Michael Rutter's ppa), 
an additional package repository is added to your system's packages. apt then 
checks that repository along with the other Ubuntu repositories and exposes the 
relevant binary R packages that Michael Rutter is curating.

So, your IS people are correct in saying that the latest version of R available 
through the Ubuntu packages is 2.13.1, but there are more up to date R 
repositories to use. If you don't have the system rights to add any additional 
repositories, you'll need your IS folks to add them for you.

-Tyler
[[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] ggplot axis limit

2012-03-16 Thread mdvaan
Hi,

This is probably an easy one, but I am new to ggplot2 and cannot find an
answer online.

I am bar plotting values of 10 groups. These values are all within a 90-100
range, so I would like leave out the area of the bars below 90. If I say
graph + scale_y_continuous(limit=c(90, 100)), it does limit the axis but
the bars disappear completely. Any solution here?

Thanks a lot!

Mathijs


--
View this message in context: 
http://r.789695.n4.nabble.com/ggplot-axis-limit-tp4478835p4478835.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] plotting border over map

2012-03-16 Thread uday
I am using following codes to plot map 

library(sp)
library(rgdal)
library(maps)
library(gplots)
library(clim.pact)
library(fields)
source(/R/PlotGridded2DMap.R)
source(/R/image.plot.fix.R)
source(/R/image.plot.plt.fix.r)

seasonal_plot-function(input,lonll=-180,latll=-90,lonres=5.,latres=3.75,write_file=TRUE,The_title=NULL){
  if(is.null(The_title)){
for (ki in 1:length(input)){
  The_title[[ki]]-sprintf(XCH4 CH4 (ppb),ki)
}
  }
  if(!is.list(input)){input=list(input)}
 lon.ll - lonll   #lower left corner of grid
 lat.ll - latll#lower left corner of grid
 lon.res- lonres   #resolution in degrees longitude
 lat.res- latres#resolution in degrees latitude

for (ki in 1:length(input)){
# plot for whole world
  sh-dim(input[[ki]]$avg)
 numpix.x   - sh[1] #number of pixels in x directions in
grid
 numpix.y   - sh[2] #number of pixels in y directions in
grid
 #print(ki)
 #print(input[[ki]]$avg)
 mat- t(input[[ki]]$avg)# length 
 xs - seq(lon.ll,by=lon.res,length=dim(mat)[2])+0.5*lon.res
#centers of cells
 ys - seq(lat.ll,by=lat.res,length=dim(mat)[1])+0.5*lat.res
#centers of cells 
 col=rich.colors(32)
 
 xlims  -c(-180,180)
 ylims  -c(-90,90)

 old.par- par(no.readonly = TRUE)
 par(mar=c(par()$mar[1:3],4))
 cex.set- 1.2
 par(cex=cex.set)
 par(mgp=c(2.0,0.3,0))
 par(tcl=-0.1) 
 opath - (/Result/scitm3/) # path to save image
 if(write_file){png(file=paste(opath,The_title[[ki]],.png,sep=
),width=1000,height=800,pointsize=23)}
 
  if(!write_file){x11()}

image.plot.fix(x=xs,y=ys,z=input[[ki]]$avg,zlim=c(1600,2000),nlevel=64,col=col,xlab=Longitude,ylab=Latitude,legend.width=0.03,
   offset=0.05,legend.only=F,lg=F)

map(database = world, add=TRUE,col=black)

 title(paste(The_title[[ki]]))
 if(write_file){dev.off()}
 
}
}

when I try to use map(database = world, add=TRUE,col=black)
I get error 
Error in map(database = world, add = TRUE, col = black) : 
  unused argument(s) (database = world)

if I comment this line then I get plot but it does not have world border. 

I really got stuck at this point and I do not know how to fix it.


--
View this message in context: 
http://r.789695.n4.nabble.com/plotting-border-over-map-tp4479163p4479163.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] ggmap crash

2012-03-16 Thread Hasan Diwan
Not sure if this is the right place to report this, but:

Am using ggmap to generate a map of a bounding box from 161
latitude/longitude pairs and the code crashes R (in ess). Data is at
http://analysis.d8u.us/~hdiwan/plotSource.csv and the code to read it
is below. I'm not sure if ess, emacs, ggmap, R, or my laptop is to
blame. Here's the code:
 rmc - read.csv('http://analysis.d8u.us/~hdiwan/rmc.csv', header=TRUE)
 siteLat = c(as.numeric(rmc$latitude))
 siteLon = c(as.numeric(rmc$longitude))
 sites - as.data.frame(cbind(siteLat, siteLon, ''))
 lats - c(floor(min(siteLat))-10, ceiling(max(siteLat))+10)
 lons - c(floor(min(siteLon))-10, ceiling(max(siteLon))+10)
 map - GetMap.bbox(c(min(siteLon)-5, max(siteLon)+5), c(min(siteLat)-5, 
 max(siteLat)+5), maptype='satellite')
[1] 
http://maps.google.com/maps/api/staticmap?center=53.277508,-9.011888zoom=5size=640x640maptype=satelliteformat=png32sensor=true;
 lonr - c(map$BBOX$ll[2], map$BBOX$ur[2])
 latr - c(map$BBOX$ll[1], map$BBOX$ur[1])
 lonr - c(map$BBOX$ll[2], map$BBOX$ur[2])
 latr - c(map$BBOX$ll[1], map$BBOX$ur[1])
 ggplot(sites, aes(siteLon, siteLat)) + annotation_raster(h_raster, lonr[1], 
 lonr[2], latr[1], latr[2]) + geom_point(aes(x=siteLon, y=siteLat), 
 colour='red', data = sites)

 *** caught segfault ***
address 0x196188000, cause 'memory not mapped'


Traceback:
 1: grid.Call.graphics(L_raster, x$raster, x$x, x$y, x$width,
x$height, resolveHJust(x$just, x$hjust), resolveVJust(x$just,
x$vjust), x$interpolate)
 2: drawDetails.rastergrob(x, recording = FALSE)
 3: drawDetails(x, recording = FALSE)
 4: drawGrob(x)
 5: recordGraphics(drawGrob(x), list(x = x), getNamespace(grid))
 6: grid.draw.grob(x$children[[i]], recording = FALSE)
 7: grid.draw(x$children[[i]], recording = FALSE)
 8: drawGTree(x)
 9: recordGraphics(drawGTree(x), list(x = x), getNamespace(grid))
10: grid.draw.gTree(x$children[[i]], recording = FALSE)
11: grid.draw(x$children[[i]], recording = FALSE)
12: drawGTree(x)
13: recordGraphics(drawGTree(x), list(x = x), getNamespace(grid))
14: grid.draw.gTree(gtable_gTree(x), recording)
15: grid.draw(gtable_gTree(x), recording)
16: grid.draw.gtable(gtable)
17: grid.draw(gtable)
18: print.ggplot(list(data = list(siteLat = c(53.277465, 53.277482,
53.277533, 53.277608, 53.277657, 53.277673, 53.277658, 53.277643,
53.27763, 53.27763, 53.277642, 53.277645, 53.277642, 53.277637,
53.277637, 53.277645, 53.277648, 53.277645, 53.27764, 53.277637,
53.277628, 53.27762, 53.277612, 53.277598, 53.277593, 53.277607,
53.277603, 53.277605, 53.27761, 53.277617, 53.277623, 53.277632,
53.277632, 53.277632, 53.27763, 53.277628, 53.277628, 53.277628,
53.277628, 53.277638, 53.277643, 53.277653, 53.277663, 53.277665,
53.277667, 53.277668, 53.27767, 53.277688, 53.277688, 53.277692,
53.2777, 53.277703, 53.277705, 53.277707, 53.277708, 53.277708,
53.277707, 53.277705, 53.277703, 53.277703, 53.277702, 53.277702,
53.2777, 53.277698, 53.277697, 53.277695, 53.27769, 53.277702,
53.27771, 53.277712, 53.277715, 53.277725, 53.277725, 53.277725,
53.277723, 53.277723, 53.277723, 53.277722, 53.27772, 53.277718,
53.27772, 53.277715, 53.277707, 53.277688, 53.27769, 53.27769,
53.277685, 53.277677, 53.277673, 53.277678, 53.277687, 53.277695,
53.277702, 53.277702, 53.277703, 53.2777, 53.277695, 53.277707,
53.277718, 53.277728, 53.277742, 53.277753, 53.277748, 53.277742,
53.277747, 53.27774, 53.277748, 53.277742, 53.277735, 53.277728,
53.277743, 53.277735, 53.27773, 53.277727, 53.277718, 53.27771,
53.277713, 53.277707, 53.277692, 53.277688, 53.277682, 53.27767,
53.277662, 53.277652, 53.277645, 53.277645, 53.277632, 53.277617,
53.277603, 53.277597, 53.277593, 53.277585, 53.277575, 53.277567,
53.277555, 53.277548, 53.277535, 53.277535, 53.277528, 53.277522,
53.277513, 53.277503, 53.277493, 53.277482, 53.277472, 53.277457,
53.277458, 53.277448, 53.277453, 53.277445, 53.277438, 53.27743,
53.277435, 53.277427, 53.277435, 53.277427, 53.277418, 53.277423,
53.277417, 53.27741, 53.277413, 53.277415, 53.277428, 53.277433,
53.277438, 53.277438, 53.277435, 53.27744, 53.277435, 53.277433,
53.277448, 53.277442, 53.277445, 53.27744, 53.27744, 53.277438,
53.277438, 53.277437, 53.277433, 53.277428, 53.277415, 53.277403,
53.27739, 53.277382, 53.277372, 53.277357, 53.27734, 53.277322,
53.2773, 53.27728, 53.277263), siteLon = c(-9.01199, -9.011975,
-9.011978, -9.01198, -9.011932, -9.011922, -9.011915, -9.011912,
-9.011907, -9.011923, -9.011932, -9.011945, -9.011958, -9.01197,
-9.011977, -9.011977, -9.01196, -9.01194, -9.011913, -9.011905,
-9.011907, -9.0119, -9.011903, -9.011903, -9.011905, -9.011912,
-9.011895, -9.011903, -9.011908, -9.011903, -9.011898, -9.011887,
-9.011885, -9.011885, -9.011883, -9.011883, -9.011885, -9.011885,
-9.011887, -9.011892, -9.011897, -9.011895, -9.011903, -9.011907,
-9.011908, -9.011912, -9.011915, -9.011922, -9.011915, -9.011918,
-9.011927, -9.011932, -9.011932, -9.011933, -9.011932, -9.011932,
-9.011932, -9.01193, -9.011928, -9.011928, -9.011928, -9.011928,

  1   2   >