[R] How to write % in pie chart?

2012-08-11 Thread Manish Gupta
HI, 

I am plotting one pie chart and need to write % inside it. How can i write %
inside it as show in figure below.

http://r.789695.n4.nabble.com/file/n4640078/pie_chart.png 

Regards



--
View this message in context: 
http://r.789695.n4.nabble.com/How-to-write-in-pie-chart-tp4640078.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] Using R as Shared Library

2012-08-11 Thread Thorsten Jolitz
Hi List, 

I find the following .so file in the R folder of my Arch Linux machine:

,--
| usr/lib/R/lib/libR.so
`--

I copied it to my home folder and changed permissons from root to my
personal user and then tried to call R functions from a different
language (that has a 'native' function to call any kind of Shared
Library on Linux). 

But to no avail - no matter if I try to call 'help' or 'imax2', I'm
always told the function doesn't exist. 

So my question is basically: whats in there in the libR.so?
Can't I call all core R functions (via 'native') with the same arguments
as on the R command line? I'm a bit confused now about how to use R as a
shared library on Linux. 

Thanks for any tips. 

--
cheers,
Thorsten

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] qpcR propagate problem

2012-08-11 Thread Robert Keams Valenzuela
I am using the propagate function of the qpcR package to estimate the
standard error for an expression.  This expression is simple enough
that I am able to calculate the first-order propagation of error,
which is what the documentation on propagate states that it does.
However, the results are not consistent.  Can someone help me figure
out where the error is?  I should note that I have applied the same
script to a simpler expression(i.e., y/x), but with different partial
derivatives, and the results are consistent (i.e., my calculation
equals the output of propagate).

The script I am using is as follows:
###
rm(list=ls())
j=1

r_mat=matrix(0,9,j)
act=matrix(0,1,j)
est=matrix(0,1,j)

for (i in 1:j){

r=matrix(rnorm(9),9,1)
r_mat[,i]=r

a=r[1]
b=r[2]
c=r[3]
var_a=abs(r[4])
var_b=abs(r[5])
var_c=abs(r[6])
var_ab=abs(r[7])
var_ac=abs(r[8])
var_bc=abs(r[9])

#f=(a*b+c)/(a*c+b)
#partial derivatives
pfpa=((a*c+b)*b-(a*b+c)*c)/(a*c+b)^2
pfpb=((a*c+b)*a-(a*b-c))/(a*c+b)^2
pfpc=((a*c+b)-(a*b+c)*a)/(a*c+b)^2
#first-order propagation of error
var_f=(pfpa^2)*var_a + (pfpb^2)*var_b + (pfpc^2)*var_c +
2*(pfpa*pfpb*var_ab + pfpa*pfpc*var_ac + pfpb*pfpc*var_bc)
act_stderr=sqrt(var_f)

print(act_stderr)
act[1,i]=act_stderr

#*Estimate standard error
EXPR <- expression((aa1*bb1+cc1)/(aa1*cc1+bb1))
aa1=c(a,sqrt(var_a))
bb1=c(b,sqrt(var_b))
cc1=c(c,sqrt(var_c))
DF <- cbind(aa1,bb1,cc1)
RES1 <- propagate(EXPR, DF, type = "stat", use.cov = TRUE,
  do.sim = FALSE, verbose = FALSE, plot = TRUE)
est_stderr=RES1$summary$Prop[2]

print(est_stderr)
est[1,i]=est_stderr

}
plot(act,est, xlim=c(0,200), ylim=c(0,200))
lm_mod <- lm(est[1,] ~ act[1,])
abline(lm_mod, col="red") # regression line (y~x)
lm_coef <- round(coef(lm_mod), 3) # extract coefficients
mtext(bquote(y == .(lm_coef[2])*x + .(lm_coef[1])), adj=1, padj=0) #
display equation

data=rbind(r_mat,act,est)
act
est
###
Thank you in advance for any input.
r...@email.arizona.edu

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 character into date solved

2012-08-11 Thread Erin Hodgess
Here it is:

 zz <- strptime(zip.df$Time,"%Y-%m-%d %H:%M:%S")
> plot(zz,zip.df$TempC,type="l")
>

Woo Hoo!

Thanks though!
Sincerely,
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] Changing character into date

2012-08-11 Thread Erin Hodgess
Dear R People:

I have a column in a data frame that has date and time (one per
minute), such as "2012-08-09 22:23:00 2012-08-09 22:24:00" etc.

What is the best way to change that into numeric dates to be used as
an x-axis, please?

I've been looking at as.Date and as.Date.numeric, but those are for
monthly/yearly data.

Thanks for any help in advance!
Sincerely,
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.


Re: [R] What's wrong with my code?

2012-08-11 Thread Berend Hasselman

stephenxqy wrote
> 
> It is a complex function, functions are quoted frequently, you may read
> from bottom up
> The independent variable for final fit is q
> 
> %%Rg0 is a function of L and b
> Rg0sq<-function(L,b)L*b/6*(1-3/2*b/L+3/2*(b/L)^2-3/4*(b/L)^3*(1-exp(-2*L/b)))
> 
> %%alpha is a defined function
> alpha<-function(x)(1+(x/3.12)^2+(x/8.67)^3)^(0.176/3)
> 
> %%w is a defined function
> w<-function(x)(1+tanh(x-1.523)/0.1477)/2
> 
> %%It is Rg^2
> Rgsq<-function(L,b)(alpha(L/b)*Rg0sq(L,b))
> 
> %%This is Rg
> Rg<-function(L,b)(Rg0sq(L,b))^0.5
> 
> %%A debye function of q, the parameters are L and b
> PDebye<-function(L,b)2*(exp(-q^2*Rg0sq(L,b))+q^2*Rg0sq(L,b)-1)/q^4/(Rg0sq(L,b))^2
> 
> %%Another function of q that quote w, PDebye, Rg, parameters are v, L and
> b
> Pexv<-function(v,L,b)w(q*Rg(L,b))*PDebye(L,b)+(1-w(q*Rg(L,b)))(1.22*(q*Rg(L,b))^(-1/v)+0.4288*(q*Rg(L,b))^(-2/v)-1.651*(q*Rg(L,b))^(-1/v))
> 
> %%Another defined function
> cf<-function(L,b,pa,pb)pa/(L/b)^pb
> 
> %%A function of q, quote Pexv, Rgsq, cf
> Psfcex<-function(v,L,b,pa,pb)Pexv(v,L,b)+cf(L,b,pa,pb)*b/L/15*(4+7/q^2/Rgsq(L,b)-(11+7/q^2/Rgsq(L,b))*exp(-q^2*Rgsq(L,b)))
> 
> %%non-linear fit
> Pfit<-function(p)sum((I-Psfcex(p[1],p[2],p[3],p[4],p[5]))^2)
> wavefit<-nlm(Pfit,c(1.5,500,5,1,0.1),hessian=TRUE)
> 
> error code: Error in c(1.5, 500, 5, 1, 0.1) : unused argument(s) (0.1)
> the fifth parameter is pb, which goes from Psfcex to cf, actually pa which
> only exist in cf is used, why not pb?
> 

1. What language is this? # starts a comment line in R not %%.
2. no data for q
3. what is I in Pfit?
4. Pexv: missing * or + or ... The expression in the function Pexv should
probably read

   
w(q*Rg(L,b))*PDebye(L,b)+(1-w(q*Rg(L,b)))*(1.22*(q*Rg(L,b))^(-1/v)+0.4288*(q*Rg(L,b))^(-2/v)-1.651*(q*Rg(L,b))^(-1/v))
 

I have inserted  * after(1-w(q*Rg(L,b))) assuming that is what you want.

Your code is not reproducible since you have not provided data for q or I.
Generating some random data and assuming I is an identity matrix with 

set.seed(123)
q <- rnorm(20) + 5 
I <- diag(length(q))

adding wavefit at the end of the script and changing the %% to # your script
runs with no errors but with warnings.
So I can't tell you why you  get the error message you got.

Finally: this is very inefficient code. There are repeated evaluations of
same thing e.g. w(q*Rg(L,b)), Rg(L,b), Rg0sq(L,b) etc.

Berend





--
View this message in context: 
http://r.789695.n4.nabble.com/What-s-wrong-with-my-code-tp4640034p4640077.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] Fill pattern for Boxplots?

2012-08-11 Thread Greg Snow
The fill patterns date back to when the main way to get quality graphs
was using a pen plotter.  Filling a rectangle with color using a pen
plotter took a long time and often resulted a soggy hole in the paper,
so the fill lines were preferred back then.  Now with high resolution
screens and printers it is easy to do the flood fill rather than the
patterns.

You need to be careful with the fill patterns, they can end up causing
moire effects (http://en.wikipedia.org/wiki/Moir%C3%A9_pattern) which
can cause false impressions of movement or distortions of size.

On Wed, Aug 8, 2012 at 5:56 PM, suse  wrote:
> Is it possible to fill the boxes of  a boxplot with filling patterns/texture
> instead of colours? Or both mixed? (for example white, grey, left diagonal
> striped, right diagonal striped) How can I do that? I searched here, but
> didn't find an answer.
> Thank you!
>
>
>
> --
> View this message in context: 
> http://r.789695.n4.nabble.com/Fill-pattern-for-Boxplots-tp4639698.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.



-- 
Gregory (Greg) L. Snow Ph.D.
538...@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] "Masked by GlobalEnv"

2012-08-11 Thread Ashok Parmar
hello everyone,
i am getting problems in graph plotting. When i attach file after adding
color attributes in my data set. i got problem of "GlobalEnv"  and masked
the followings. Like this

>attach(machm)
The following object(s) are masked _by_ '.GlobalEnv':

coll, sp
The following object(s) are masked from 'mach':

angle, area, dis, plot, sp
>xmach=dis*sin(angle/180*pi); ymach=dis*cos(angle/180*pi)
>plot(xmach,ymach, xlim=c(-5,5),ylim=c(-5,5), pch=19, cex=
machm$area*0.05,col=machm$coll)


Graph did not take right R color code.
How can i solve this problem?,  As i am the newest user of R programme.

with regards,
ashok

[[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] All combinations possible in a mutliple regression

2012-08-11 Thread Greg Snow
Look at the leaps function in the leaps package.  It will compute the
Cp statistic which is a function of AIC.

On Thu, Aug 9, 2012 at 7:28 AM, zel7223  wrote:
> Hi,
>
> I want to use four independent variables to predict the output of one
> dependent variable using a linear model lm. I want to compare all possible
> combinations of the 4 independent variables, including singles, pairs and
> triples.
>
> I was thinking of using the AIC test to compare all models and pick the best
> one.
>
> The model looks like this :
>
> lm(Y ~ X1 + X2 + X3 + X4)
>
> Thanks for your help
>
> Cheers
>
> Jean-Michel Fortin
> UOttawa
>
>
>
> --
> View this message in context: 
> http://r.789695.n4.nabble.com/All-combinations-possible-in-a-mutliple-regression-tp4639762.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.



-- 
Gregory (Greg) L. Snow Ph.D.
538...@gmail.com

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


Re: [R] Stopping all code execution when ANY error occurs (OR error handling without try/tryCatch)

2012-08-11 Thread enocko
Hi, thanks for the ideas, folks.

I'm on Windows 7, R 2.15.0 x64, RStudio 0.97.71.

I do appreciate your time... I would like to say my goal of dealing with
errors without R's error trapping tools is not nonsensical given that those
tools are cumbersome and not well-suited to the development phase of coding
where one informally runs various snippets all the time.

The suggestion of looking at IDE's is a good one because it would not be
hard for an IDE to just wait and see if any line of code gives an error, and
halt execution if so (a global option could enable this). RStudio doesn't
have this--does anyone know of something that does? I can post a suggestion
to RStudio.

Thanks,

Phil




--
View this message in context: 
http://r.789695.n4.nabble.com/Stopping-all-code-execution-when-ANY-error-occurs-OR-error-handling-without-try-tryCatch-tp4640023p4640073.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] replace funcion

2012-08-11 Thread David L Carlson
Or if you want to use recode (which you forgot to mention is in package
car):

set.seed(1)
df1<- c(sample(1:12, 50, replace=TRUE)) # sample data

library(car)
recode(df1, "c(1, 2, 3, 4, 11, 12)='invierno'; 5:10='verano'")

--
David L Carlson
Associate Professor of Anthropology
Texas A&M University
College Station, TX 77843-4352


> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-bounces@r-
> project.org] On Behalf Of arun
> Sent: Saturday, August 11, 2012 5:17 PM
> To: Dominic Roye
> Cc: R help
> Subject: Re: [R] replace funcion
> tabl
> HI,
> 
> Try this:
> set.seed(1)
>  df1<-data.frame(colA=sample(1:100,n,replace=TRUE))
> 
> numbers1<-c(1,2,3,4,11,12)
>  numbers2<-c(5,6,7,8,9,10)
>  df1$colA[df1$colA%in%numbers1]<-"invierno"
>  df1$colA[df1$colA%in%numbers2]<-"verano"
>  head(df1,10)
>  colA
> 1  27
> 2  38
> 3  58
> 4  91
> 5  21
> 6  90
> 7  95
> 8  67
> 9  63
> 10 verano
> 
> A.K.
> 
> 
> 
> - Original Message -
> From: Dominic Roye 
> To: r-help@r-project.org
> Cc:
> Sent: Saturday, August 11, 2012 3:10 PM
> Subject: [R] replace funcion
> 
> Hello everybody,
> 
> 
> I would like to replace or recode a list of numbers between 1 and 12
> (total
> 100). I have tried to make it with recode, but i have two types of
> replacements. For 1,2,3,4,11,12 => invierno and for 5,6,7,8,9 and 10 =>
> verano.
> 
> recode(datos.mx1[,7], "1='invierno'; 2='invierno';
> 3='invierno';4='invierno';11='invierno';12='invierno'")  #with this
> command
> it works perfectly, but i have only one part
> 
> recode(datos.mx1[,7], "'5'='verano'; '6'='verano';
> '7'='verano';'8'='verano';'9'='verano';'10'='verano'") #when i run this
> command it works also fine, but it clears the first change above.
> 
> I had previously tried it with the if-command, but it doesn't work. I
> hope
> someone can help me. Thank you very much.
> 
> Domi
> 
>     [[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-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] replace funcion

2012-08-11 Thread arun
HI,

Try this:
set.seed(1)
 df1<-data.frame(colA=sample(1:100,n,replace=TRUE)) 

numbers1<-c(1,2,3,4,11,12)
 numbers2<-c(5,6,7,8,9,10)
 df1$colA[df1$colA%in%numbers1]<-"invierno"
 df1$colA[df1$colA%in%numbers2]<-"verano"
 head(df1,10)
 colA
1  27
2  38
3  58
4  91
5  21
6  90
7  95
8  67
9  63
10 verano

A.K.



- Original Message -
From: Dominic Roye 
To: r-help@r-project.org
Cc: 
Sent: Saturday, August 11, 2012 3:10 PM
Subject: [R] replace funcion

Hello everybody,


I would like to replace or recode a list of numbers between 1 and 12 (total
100). I have tried to make it with recode, but i have two types of
replacements. For 1,2,3,4,11,12 => invierno and for 5,6,7,8,9 and 10 =>
verano.

recode(datos.mx1[,7], "1='invierno'; 2='invierno';
3='invierno';4='invierno';11='invierno';12='invierno'")  #with this command
it works perfectly, but i have only one part

recode(datos.mx1[,7], "'5'='verano'; '6'='verano';
'7'='verano';'8'='verano';'9'='verano';'10'='verano'") #when i run this
command it works also fine, but it clears the first change above.

I had previously tried it with the if-command, but it doesn't work. I hope
someone can help me. Thank you very much.

Domi

    [[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] help counting in data

2012-08-11 Thread jim holtman
use 'dput' to enclose your data.  I think 'cut' is what you want:

> dput(x)
c(0, 1.179, 3.729, 9.418, 18.01, 29.746, 58.662, 131.566, 2323.7
)
> dput(y)
c(5.79, 1579.52, 2323.7, 68.85, 426.07, 110.29, 108.29, 1067.6,
17.05, 22.66, 21.02, 175.88, 139.07, 144.12, 20.46, 43.4, 194.9,
47.3, 7.74, 0.4, 82.85, 9.88, 89.29, 215.1, 1.75, 0.79, 15.93,
3.91, 0.27, 0.69, 100.58, 27.8, 13.95, 53.24, 0.96, 4.15, 0.19,
0.78, 8.01, 31.75, 7.35, 6.5, 8.27, 33.91, 32.52, 3.16, 4.85,
2.78, 4.67, 1.31, 12.06, 36.71, 72.89, 1.97, 0.59, 2.58, 1.69,
2.71, 25.5, 0.35, 0.99, 3.99, 3.67, 2.07, 0.96, 5.35, 2.9, 13.77,
0.47, 0.73, 1.4, 0.74, 0.39, 1.13, 0.09, 2.38)
> z <- cut(y, x)
> table(z)
z
  (0,1.18](1.18,3.73](3.73,9.42]  (9.42,18]  (18,29.7]
17 13 12  6  5
   (29.7,58.7] (58.7,132] (132,2.32e+03]
 7  7  9


On Sat, Aug 11, 2012 at 9:59 AM, hafida  wrote:

> Hi
>
>
> >i have this data
>
> > X
>  [1]5.79 1579.52 2323.70   68.85  426.07  110.29  108.29 1067.60
> 17.05
> 22.66
> [11]   21.02  175.88  139.07  144.12   20.46   43.40  194.90   47.30
>  7.74
> 0.40
> [21]   82.859.88   89.29  215.101.750.79   15.933.91
>  0.27
> 0.69
> [31]  100.58   27.80   13.95   53.240.964.150.190.78
>  8.01
> 31.75
> [41]7.356.508.27   33.91   32.523.164.852.78
>  4.67
> 1.31
> [51]   12.06   36.71   72.891.970.592.581.692.71
> 25.50
> 0.35
> [61]0.993.993.672.070.965.352.90   13.77
>  0.47
> 0.73
> [71]1.400.740.391.130.092.38
>
>  >and i have an intervale   I[j]<- leftaj, rightajHERE I
> CAN
> T PROGRAMATE THIS INTERVAL
>
> >SO i have
>
> >> leftaj
> [1] 0   1.179   3.729   9.418  18.010  29.746  58.662 131.566
> > rightaj
> [1]1.1793.7299.418   18.010   29.746   58.662  131.566 2323.700
>
>
>  >i want to counting the number of   Xhows in the intervale[leftaj,
> rightaj]
>
> >thanks for helping
> >hafida
>
>
>
>
> --
> View this message in context:
> http://r.789695.n4.nabble.com/help-counting-in-data-tp4640033.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.

[[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] replace funcion

2012-08-11 Thread arun
HI,

I guess this should also work.
set.seed(1)
 df1<-data.frame(colA=sample(1:100,n,replace=TRUE))
numbers1<-c(1,2,3,4,11,12)
 numbers2<-c(5,6,7,8,9,10)

df1[df1$colA%in%numbers1,]<-"invierno"
df1[df1$colA%in%numbers2,]<-"verano"
#or
set.seed(1)
 df1<-data.frame(colA=sample(1:100,n,replace=TRUE))
within(df1,{colA[colA%in%numbers1]<-"invierno";colA[colA%in%numbers2]<-"verano"})

A.K.




- Original Message -
From: Dominic Roye 
To: r-help@r-project.org
Cc: 
Sent: Saturday, August 11, 2012 3:10 PM
Subject: [R] replace funcion

Hello everybody,


I would like to replace or recode a list of numbers between 1 and 12 (total
100). I have tried to make it with recode, but i have two types of
replacements. For 1,2,3,4,11,12 => invierno and for 5,6,7,8,9 and 10 =>
verano.

recode(datos.mx1[,7], "1='invierno'; 2='invierno';
3='invierno';4='invierno';11='invierno';12='invierno'")  #with this command
it works perfectly, but i have only one part

recode(datos.mx1[,7], "'5'='verano'; '6'='verano';
'7'='verano';'8'='verano';'9'='verano';'10'='verano'") #when i run this
command it works also fine, but it clears the first change above.

I had previously tried it with the if-command, but it doesn't work. I hope
someone can help me. Thank you very much.

Domi

    [[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] help counting in data

2012-08-11 Thread arun


HI,

Not sure whether this is what you wanted.

dat3<-c(5.79, 1579.52, 2323.70, 68.85,  426.07,  110.29, 108.29, 1067.60,  
17.05, 22.66,
 21.02,  175.88,  139.07,  144.12, 20.46,  43.40, 194.90, 47.30,  7.74, 0.40,
  82.85, 9.88, 89.29,  215.10, 1.75,  0.79, 15.93,  3.91,  0.27,  0.69,
 100.58, 27.80, 13.95, 53.24,  0.96, 4.15, 0.19, 0.78, 8.01,  31.75,
 7.35, 6.50, 8.27, 33.91, 32.52, 3.16, 4.85, 2.78, 4.67, 1.31,
 12.06, 36.71, 72.89, 1.97, 0.59, 2.58, 1.69, 2.71, 25.50, 0.35,
 0.99, 3.99, 3.67, 2.07, 0.96, 5.35, 2.90, 13.77, 0.47,  0.73,
1.40, 0.74, 0.39, 1.13, 0.09, 2.38) 
leftaj<-c( 0, 1.179,3.729,9.418, 18.010, 29.746, 58.662, 131.566)
rightaj<-c(1.179, 3.729, 9.418, 18.010, 29.746, 58.662, 131.566, 2323.700) 
 leftajmax<-max(leftaj)
 rightajmax<-max(rightaj)
 leftajmin<-min(leftaj)
rightajmin<-min(rightaj)
dat3[(dat3leftajmax)|(dat3>leftajmin & dat3leftajmax)|(dat3>leftajmin & 
dat3
To: r-help@r-project.org
Cc: 
Sent: Saturday, August 11, 2012 9:59 AM
Subject: [R] help  counting in data

Hi


>i have this data

> X
[1]    5.79 1579.52 2323.70   68.85  426.07  110.29  108.29 1067.60   17.05  
22.66
[11]   21.02  175.88  139.07  144.12   20.46   43.40  194.90   47.30    7.74  
0.40
[21]   82.85    9.88   89.29  215.10    1.75    0.79   15.93    3.91    0.27  
0.69
[31]  100.58   27.80   13.95   53.24    0.96    4.15    0.19    0.78    8.01  
31.75
[41]    7.35    6.50    8.27   33.91   32.52    3.16    4.85    2.78    4.67  
1.31
[51]   12.06   36.71   72.89    1.97    0.59    2.58    1.69    2.71   25.50  
0.35
[61]    0.99    3.99    3.67    2.07    0.96    5.35    2.90   13.77    0.47  
0.73
[71]    1.40    0.74    0.39    1.13    0.09    2.38

>and i have an intervale       I[j]<- leftaj, rightaj            HERE I CAN
T PROGRAMATE THIS INTERVAL

>SO i have 

>> leftaj
[1]     0           1.179   3.729   9.418  18.010  29.746  58.662 131.566
> rightaj
[1]    1.179    3.729    9.418   18.010   29.746   58.662  131.566 2323.700


>i want to counting the number of   X    hows in the intervale    [leftaj,
rightaj]

>thanks for helping
>hafida




--
View this message in context: 
http://r.789695.n4.nabble.com/help-counting-in-data-tp4640033.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] Parsing large XML documents in R - how to optimize the speed?

2012-08-11 Thread Erdal Karaca
If this is an option for you: An xml database can handle (very) huge xml
files and let you query nodes very efficiently.
Then, you could query the xml databse from R (using REST) to do your
statistics.

There are some open source xquery/xml databases available.

2012/8/11 Frederic Fournier 

> Hello everyone,
>
> I would like to parse very large xml files from MS/MS experiments and
> create R objects from their content. (By very large, I mean going up to
> 5-10Gb, although I am using a 'small' 40M file to test my code.)
>
> My first attempt at parsing the 40M file, using the XML package, took more
> than 2200 seconds and left me quite disappointed.
> I managed to cut that down to around 40 seconds by:
> -using the 'useInternalNodes' option of the XML package when parsing
> the xml tree;
> -vectorizing the parsing (i.e., replacing loops like "for(node in
> group.of.nodes) {...}" by "sapply(group.of.node, function(node){...}")
> I gained another 5 seconds by making small changes to the functions used
> (like replacing 'getNodeset' by 'xmlElementsByTagName' when I don't need to
> navigate to the children nodes).
> Now I am blocked at around 35 seconds and I would still like to cut this
> time by a 5x, but I have no clue what to do to achieve this gain. I'll try
> to expose as briefly as possible the relevant structure of the xml file I
> am parsing, the structure of the R object I want to create, and the type of
> functions I am using to do it. I hope that one of you will be able to point
> me towards a better and quicker way of doing the parsing!
>
>
> Here is the (simplified) structure of the relevant nodes of the xml file:
>
>  (many many nodes)
>(a couple of proteins per model node)
>  (1 per protein node)
>(1 or more per peptide node)
>  (0 or more per domain node)
> 
>   
> 
>   
> 
>
> Here is the basic structure of the R object that I want to create:
>
> 'result' object that contains:
>   -various attributes
>   -a list of 'protein' objects, each of which containing:
>   -various attributes
>   -a list of 'peptide' objects, each of which containing:
> -various attributes
> -a list of 'aa' objects, each of which consisting of a couple of
> attributes.
>
> Here is the basic structure of the code:
>
> xml.doc <- xmlTreeParse("file", getDTD=FALSE, useInternalNodes=TRUE)
> result <- new('S4_result_class')
> result@proteins <- xpathApply(xml.doc, "//model/protein",
> function(protein.node) {
>   protein <- new('S4_protein_class')
>   ## fill in a couple of attributes of the protein object using xmlValue
> and xmlAttrs(protein.node)
>   protein@peptides <- xpathApply(protein.node, "./peptide",
> function(peptide.node) {
> peptide <- new('S4_peptide_class')
> ## fill in a couple of attributes of the peptide object using xmlValue
> and xmlAttrs(peptide.node)
> peptide@aas <- sapply(xmlElementsByTagName(peptide.node, name="aa"),
> function(aa.node) {
>   aa <- new('S4_aa_class')
>   ## fill in a couple of attributes of the 'aa' object using xmlValue
> and xmlAttrs(aa.node)
> })
>   })
> })
> free(xml.doc)
>
>
> Does anyone know a better and quicker way of doing this?
>
> Sorry for the very long message and thank you very much for your time and
> help!
>
> Frederic
>
> [[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] help counting in data

2012-08-11 Thread Rui Barradas

Hello,

Post your data using dput(). Copy the output of dput(X) and paste it in 
a post.

Anyway, you can try the following.

sum( leftaj <= X & X <= rightaj )

Hope this helps,

Rui Barradas

Em 11-08-2012 14:59, hafida escreveu:

Hi



i have this data
X

  [1]5.79 1579.52 2323.70   68.85  426.07  110.29  108.29 1067.60   17.05
22.66
[11]   21.02  175.88  139.07  144.12   20.46   43.40  194.90   47.307.74
0.40
[21]   82.859.88   89.29  215.101.750.79   15.933.910.27
0.69
[31]  100.58   27.80   13.95   53.240.964.150.190.788.01
31.75
[41]7.356.508.27   33.91   32.523.164.852.784.67
1.31
[51]   12.06   36.71   72.891.970.592.581.692.71   25.50
0.35
[61]0.993.993.672.070.965.352.90   13.770.47
0.73
[71]1.400.740.391.130.092.38

  >and i have an intervale   I[j]<- leftaj, rightajHERE I CAN
T PROGRAMATE THIS INTERVAL


SO i have

leftaj

[1] 0   1.179   3.729   9.418  18.010  29.746  58.662 131.566

rightaj

[1]1.1793.7299.418   18.010   29.746   58.662  131.566 2323.700


  >i want to counting the number of   Xhows in the intervale[leftaj,
rightaj]


thanks for helping
hafida




--
View this message in context: 
http://r.789695.n4.nabble.com/help-counting-in-data-tp4640033.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] replace funcion

2012-08-11 Thread Rui Barradas

Hello,

Try the following, using index vectors, not recode().

inx <- datos.mx1[, 7] %in% 5:10
datos.mx1[inx, 7] <- "verano"
datos.mx1[!inx, 7] <- "invierno"

Hope this helps,

Rui Barradas

Em 11-08-2012 20:10, Dominic Roye escreveu:

Hello everybody,


I would like to replace or recode a list of numbers between 1 and 12 (total
100). I have tried to make it with recode, but i have two types of
replacements. For 1,2,3,4,11,12 => invierno and for 5,6,7,8,9 and 10 =>
verano.

recode(datos.mx1[,7], "1='invierno'; 2='invierno';
3='invierno';4='invierno';11='invierno';12='invierno'")  #with this command
it works perfectly, but i have only one part

recode(datos.mx1[,7], "'5'='verano'; '6'='verano';
'7'='verano';'8'='verano';'9'='verano';'10'='verano'") #when i run this
command it works also fine, but it clears the first change above.

I had previously tried it with the if-command, but it doesn't work. I hope
someone can help me. Thank you very much.

Domi

[[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] Imputing data below detection limit

2012-08-11 Thread aynumazi
Hello,

I'm trying to impute data below detection limit (with multiple detection
limits)
so i need just a method or a code for imputation and then extract the
complete dataset to do the analyses.
Is there any package which could do that simply as i'm a beginner in R

Thank you



--
View this message in context: 
http://r.789695.n4.nabble.com/Imputing-data-below-detection-limit-tp4640057.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] replace funcion

2012-08-11 Thread Dominic Roye
Hello everybody,


I would like to replace or recode a list of numbers between 1 and 12 (total
100). I have tried to make it with recode, but i have two types of
replacements. For 1,2,3,4,11,12 => invierno and for 5,6,7,8,9 and 10 =>
verano.

recode(datos.mx1[,7], "1='invierno'; 2='invierno';
3='invierno';4='invierno';11='invierno';12='invierno'")  #with this command
it works perfectly, but i have only one part

recode(datos.mx1[,7], "'5'='verano'; '6'='verano';
'7'='verano';'8'='verano';'9'='verano';'10'='verano'") #when i run this
command it works also fine, but it clears the first change above.

I had previously tried it with the if-command, but it doesn't work. I hope
someone can help me. Thank you very much.

Domi

[[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] plotting profile likelihood curves

2012-08-11 Thread adw11
oops, Line 5 of the code should read:

glm2<-glm(lot2 ~ log(u), data=clotting, family=Gamma) 





--
View this message in context: 
http://r.789695.n4.nabble.com/plotting-profile-likelihood-curves-tp4639947p4640047.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] unsued argument

2012-08-11 Thread stephenxqy
It is a complex function, functions are quoted frequently, you may read from
bottom up
The independent variable for final fit is q


%%Rg0 is a function of L and b
Rg0sq<-function(L,b)L*b/6*(1-3/2*b/L+3/2*(b/L)^2-3/4*(b/L)^3*(1-exp(-2*L/b)))

%%alpha is a defined function
alpha<-function(x)(1+(x/3.12)^2+(x/8.67)^3)^(0.176/3)

%%w is a defined function
w<-function(x)(1+tanh(x-1.523)/0.1477)/2

%%It is Rg^2
Rgsq<-function(L,b)(alpha(L/b)*Rg0sq(L,b))

%%This is Rg
Rg<-function(L,b)(Rg0sq(L,b))^0.5

%%A debye function of q, the parameters are L and b
PDebye<-function(L,b)2*(exp(-q^2*Rg0sq(L,b))+q^2*Rg0sq(L,b)-1)/q^4/(Rg0sq(L,b))^2

%%Another function of q that quote w, PDebye, Rg, parameters are v, L and b
Pexv<-function(v,L,b)w(q*Rg(L,b))*PDebye(L,b)+(1-w(q*Rg(L,b)))(1.22*(q*Rg(L,b))^(-1/v)+0.4288*(q*Rg(L,b))^(-2/v)-1.651*(q*Rg(L,b))^(-1/v))

%%Another defined function
cf<-function(L,b,pa,pb)pa/(L/b)^pb

%%A function of q, quote Pexv, Rgsq, cf
Psfcex<-function(v,L,b,pa,pb)Pexv(v,L,b)+cf(L,b,pa,pb)*b/L/15*(4+7/q^2/Rgsq(L,b)-(11+7/q^2/Rgsq(L,b))*exp(-q^2*Rgsq(L,b)))

%%non-linear fit
Pfit<-function(p)sum((I-Psfcex(p[1],p[2],p[3],p[4],p[5]))^2)
wavefit<-nlm(Pfit,c(1.5,500,5,1,0.1),hessian=TRUE)

error code: Error in c(1.5, 500, 5, 1, 0.1) : unused argument(s) (0.1)
the fifth parameter is pb, which goes from Psfcex to alpha, actually L,b and
pa in alpha are used, why not pb?





--
View this message in context: 
http://r.789695.n4.nabble.com/unsued-argument-tp4640034.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] choosing multiple columns

2012-08-11 Thread arun
HI,

Try this:

dat1<-as.data.frame(matrix(rnorm(50,5),ncol=10))
colnames(dat1)<-paste0("OFB",1:10)
#to select first 8 columns - easy method

dat1[,1:8]
#2nd method
wanted<-paste0("OFB",1:8)
dat1[,colnames(dat1)%in%wanted]

#3rd method
#regular expression to select 3rd, 5th columns
dat1[grep("[[:alnum:]][c(3,5)]",colnames(dat1))]

# OFB3 OFB5
#1 6.378474 7.490392
#2 5.323282 4.728561
#3 5.415081 4.661548
#4 4.000541 5.286831
#5 3.598919 6.080370


dat2<-data.frame(dat1,CFB=rnorm(5,15))
#select columns having OFB as column name

dat2[grep("OFB",colnames(dat2))]
#select 4-8 columns

dat2[grep("[4-8]",colnames(dat2))]

 #    OFB4 OFB5 OFB6 OFB7 OFB8
#1 4.545049 7.490392 5.441275 3.433050 4.656184
#2 5.015531 4.728561 5.429073 5.268677 5.569176
#3 5.533485 4.661548 5.586189 4.694112 5.209213
#4 6.427448 5.286831 5.521572 4.036457 5.532234
#5 5.500054 6.080370 6.259925 3.946102 4.554102

Hope this helps.

A.K.







- Original Message -
From: Sachinthaka Abeywardana 
To: r-help@r-project.org
Cc: 
Sent: Saturday, August 11, 2012 7:59 AM
Subject: [R] choosing multiple columns

Hi all,

I have a data frame that has the columns OFB1, OFB2, OFB3,... OFB10.

How do I select the first 8 columns efficiently without typing each and
every one of them. i.e. I want something like:

a<-data.frame(initial_data$OFB1-10) #i know this is wrong, what would be
the correct syntax?

Thanks,
Sachin

    [[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] Parsing large XML documents in R - how to optimize the speed?

2012-08-11 Thread Duncan Temple Lang

Hi Frederic

  You definitely want to be using xmlParse() (or equivalently
  xmlTreeParse( , useInternalNodes = TRUE)).

  This then allows use of getNodeSet()

  I would suggest you use Rprof() to find out where the bottlenecks arise,
   e.g. in the XML functions or in S4 code, or in your code that assembles the
R objects from the XML.

  I'm happy to take a look at speeding it up if you can make the test file 
available
and show me your code.

D.
On 8/10/12 3:46 PM, Frederic Fournier wrote:
> Hello everyone,
> 
> I would like to parse very large xml files from MS/MS experiments and
> create R objects from their content. (By very large, I mean going up to
> 5-10Gb, although I am using a 'small' 40M file to test my code.)
> 
> My first attempt at parsing the 40M file, using the XML package, took more
> than 2200 seconds and left me quite disappointed.
> I managed to cut that down to around 40 seconds by:
> -using the 'useInternalNodes' option of the XML package when parsing
> the xml tree;
> -vectorizing the parsing (i.e., replacing loops like "for(node in
> group.of.nodes) {...}" by "sapply(group.of.node, function(node){...}")
> I gained another 5 seconds by making small changes to the functions used
> (like replacing 'getNodeset' by 'xmlElementsByTagName' when I don't need to
> navigate to the children nodes).
> Now I am blocked at around 35 seconds and I would still like to cut this
> time by a 5x, but I have no clue what to do to achieve this gain. I'll try
> to expose as briefly as possible the relevant structure of the xml file I
> am parsing, the structure of the R object I want to create, and the type of
> functions I am using to do it. I hope that one of you will be able to point
> me towards a better and quicker way of doing the parsing!
> 
> 
> Here is the (simplified) structure of the relevant nodes of the xml file:
> 
>  (many many nodes)
>(a couple of proteins per model node)
>  (1 per protein node)
>(1 or more per peptide node)
>  (0 or more per domain node)
> 
>   
> 
>   
> 
> 
> Here is the basic structure of the R object that I want to create:
> 
> 'result' object that contains:
>   -various attributes
>   -a list of 'protein' objects, each of which containing:
>   -various attributes
>   -a list of 'peptide' objects, each of which containing:
> -various attributes
> -a list of 'aa' objects, each of which consisting of a couple of
> attributes.
> 
> Here is the basic structure of the code:
> 
> xml.doc <- xmlTreeParse("file", getDTD=FALSE, useInternalNodes=TRUE)
> result <- new('S4_result_class')
> result@proteins <- xpathApply(xml.doc, "//model/protein",
> function(protein.node) {
>   protein <- new('S4_protein_class')
>   ## fill in a couple of attributes of the protein object using xmlValue
> and xmlAttrs(protein.node)
>   protein@peptides <- xpathApply(protein.node, "./peptide",
> function(peptide.node) {
> peptide <- new('S4_peptide_class')
> ## fill in a couple of attributes of the peptide object using xmlValue
> and xmlAttrs(peptide.node)
> peptide@aas <- sapply(xmlElementsByTagName(peptide.node, name="aa"),
> function(aa.node) {
>   aa <- new('S4_aa_class')
>   ## fill in a couple of attributes of the 'aa' object using xmlValue
> and xmlAttrs(aa.node)
> })
>   })
> })
> free(xml.doc)
> 
> 
> Does anyone know a better and quicker way of doing this?
> 
> Sorry for the very long message and thank you very much for your time and
> help!
> 
> Frederic
> 
>   [[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] How do I find the apparent magnitude of a galaxy from a FITS file?

2012-08-11 Thread andrej
> > sos::findFn('fits astronomical')
>found 4 matches;  retrieving 1 page 

Alright I installed SOS, but in the line below "found 4 matches;  retrieving
1 page" R spit out the following:

"Error in print.findFn(list(Count = 1, MaxScore = 1, TotalScore = 1, Package
= "FITSio",  : 
could not find function "brew""

I used FITSio before, so I know I can just install that... the point of me
posting was to see if anyone here had actually used it to analyze the
images. As I said before, this is an optical telescope image (which can be
viewed in SAOimageDS9); let's just say that's from the HST.



--
View this message in context: 
http://r.789695.n4.nabble.com/How-do-I-find-the-apparent-magnitude-of-a-galaxy-from-a-FITS-file-tp4639907p4640053.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] Submission

2012-08-11 Thread he chen
To someone who may concern,

I want to continue the submission. of r-help list.

Thanks a lot!

Chen



-- 

Best Regards,
Yours,
Chen He
PhD Candidate
Institute of Population Research
Peking University, Beijing, 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.


[R] help counting in data

2012-08-11 Thread hafida
Hi


>i have this data

> X
 [1]5.79 1579.52 2323.70   68.85  426.07  110.29  108.29 1067.60   17.05  
22.66
[11]   21.02  175.88  139.07  144.12   20.46   43.40  194.90   47.307.74   
0.40
[21]   82.859.88   89.29  215.101.750.79   15.933.910.27   
0.69
[31]  100.58   27.80   13.95   53.240.964.150.190.788.01  
31.75
[41]7.356.508.27   33.91   32.523.164.852.784.67   
1.31
[51]   12.06   36.71   72.891.970.592.581.692.71   25.50   
0.35
[61]0.993.993.672.070.965.352.90   13.770.47   
0.73
[71]1.400.740.391.130.092.38

 >and i have an intervale   I[j]<- leftaj, rightajHERE I CAN
T PROGRAMATE THIS INTERVAL

>SO i have 

>> leftaj
[1] 0   1.179   3.729   9.418  18.010  29.746  58.662 131.566
> rightaj
[1]1.1793.7299.418   18.010   29.746   58.662  131.566 2323.700


 >i want to counting the number of   Xhows in the intervale[leftaj,
rightaj]

>thanks for helping
>hafida




--
View this message in context: 
http://r.789695.n4.nabble.com/help-counting-in-data-tp4640033.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] Ylim problem - plot.correlog, ncf package

2012-08-11 Thread Pyhrell
Hi, 

I'm doing cross-correlation correlograms with the ncf package. I have four
study sites ; four correlograms. 
I'd like to get the same y scale for the four of them... only, using
"ylim=c(-1,1)" does not change the y scale never and I don't know why. I
tried with plot() too. 

Is there another option to change the ylim in plots ?

Example with only one correlog (all work but ylim). They all have the same
form. 

cross_calf2 <- correlog(calf2$X,calf2$Y, calf2$species1, calf2$species2,
increment=2)
plot.correlog(cross_calf2,ylim=c(-1,1))

Thanks !

Pyh. 



--
View this message in context: 
http://r.789695.n4.nabble.com/Ylim-problem-plot-correlog-ncf-package-tp4640044.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] cannot allocate a vector of size error, what explodes the the memory consumption?

2012-08-11 Thread Martin Ivanov
 Dear R users,

I keep getting the message "Error: cannot allocate a vector of size 543.2 Mb" 
on my 64 bit Linux machine with 4 Gb of memory. I studied the problem and it 
occurs at the last lines of my code:

..
a <- laply(.);
save(a, file= "file.RData");
rm(a);

"a" is a 4-d array of size about 600 Mb. 3 minutes before R exits and displays 
the error message, the 
memory consumption of R (diagnosed with top) is 1.8 Gb. 2 minutes before the 
error, the memory consumption of R suddenly expands to 2.8 Gb and one minute 
before the error it is 3 Gb. This is why I suspect the problem 
is with my code. I have checked the same code with smaller data sets, it works 
perfectly. But with larger data sets, that is when the size of "a" gets bigger 
than, say, about 500 Mb, I get the error. 
Actually 99% of the time the memory consumption is up to 1.8 Gb. This is while 
things are going within laply.
And at the end, at these 3 last lines something causes more than doubling of 
the R memory consumption.
Have you got any idea what the culprit is?

Any suggestions will be appreciated.

Best regards,
Martin

-
Гражданска отговорност – Цените на компаниите
http://www.sdi.bg/onlineInsurance/?utm_source=gbg&utm_medium=txtLink&utm_content=home

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Trouble with Spatial Data Example Script

2012-08-11 Thread David L Carlson
That is it. If you are going to use source() change

spplot(gadm, "language", col.regions=col, main="Swiss Language
  Regions")

To

print(spplot(gadm, "language", col.regions=col, main="Swiss Language
  Regions"))

---
David


> -Original Message-
> From: R. Michael Weylandt [mailto:michael.weyla...@gmail.com]
> Sent: Saturday, August 11, 2012 12:27 PM
> To: Lorenzo Isella
> Cc: dcarl...@tamu.edu; John Kane; r-h...@stat.math.ethz.ch
> Subject: Re: [R] Trouble with Spatial Data Example Script
> 
> I have no experience with spplot() or maps in general, but might this
> be more or less tied to R FAQ 7.22?
> 
> Michael
> 
> On Sat, Aug 11, 2012 at 12:00 PM, Lorenzo Isella
>  wrote:
> > Hello,
> > The situation is a bit odd.
> > If I open an R session and I paste there the script, then it does
> work.
> > However, if I save it as a text file and then I run it with the
> > source("myfile.R") command, then I fall back to the case that started
> this
> > thread i.e. I see nothing.
> > Does anybody have a clue at what is going on?
> > I paste below the output of sessionInfo(), which is the same no
> matter
> > whether I paste the commands in a shell or use a .R file.
> >
> >
> > sessionInfo()
> > R version 2.15.1 (2012-06-22)
> > Platform: x86_64-pc-linux-gnu (64-bit)
> >
> > locale:
> >  [1] LC_CTYPE=en_US.UTF-8   LC_NUMERIC=C
> >  [3] LC_TIME=en_US.UTF-8LC_COLLATE=en_US.UTF-8
> >  [5] LC_MONETARY=en_US.UTF-8LC_MESSAGES=en_US.UTF-8
> >  [7] LC_PAPER=C LC_NAME=C
> >  [9] LC_ADDRESS=C   LC_TELEPHONE=C
> > [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
> >
> > attached base packages:
> > [1] stats graphics  grDevices utils datasets  methods   base
> >
> > other attached packages:
> > [1] sp_0.9-99
> >
> > loaded via a namespace (and not attached):
> > [1] grid_2.15.1lattice_0.20-6
> >
> >
> > Many thanks
> >
> > Lorenzo
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> > On Sat, 11 Aug 2012 17:18:43 +0200, David L Carlson
> 
> > wrote:
> >
> >> Can you get other plotting commands to work? E.g.
> >>
> >> plot(1:5, 1:5)
> >>
> >>> -Original Message-
> >>> From: Lorenzo Isella [mailto:lorenzo.ise...@gmail.com]
> >>> Sent: Saturday, August 11, 2012 3:20 AM
> >>> To: dcarl...@tamu.edu
> >>> Subject: Re: [R] Trouble with Spatial Data Example Script
> >>>
> >>> Thanks for your reply.
> >>> I am running R 2.15.1 on debian testing, amd64 architecture.
> >>>
> >>>
> >>>
> >>>
> >>> ~$ R
> >>>
> >>> R version 2.15.1 (2012-06-22) -- "Roasted Marshmallows"
> >>> Copyright (C) 2012 The R Foundation for Statistical Computing
> >>> ISBN 3-900051-07-0
> >>> Platform: x86_64-pc-linux-gnu (64-bit)
> >>>
> >>>
> >>> and when I run the script, this is what I see
> >>>
> >>>
> >>>
> >>> source('map-switzerland.R')
> >>> [1] "gadm"
> >>>
> >>> gadm contains the data, but I do not see any map.
> >>> Any hint about what is going on?
> >>> Cheers
> >>>
> >>> Lorenzo
> >>>
> >>>
> >>>
> >>>
> >>>
> >>> On Fri, 10 Aug 2012 23:43:34 +0200, David L Carlson
> 
> >>> wrote:
> >>>
> >>> > The script is working for me. Did you get any error or warning
> >>> messages?
> >>> > What version of R are you using? What operating system does your
> >>> > computer use? When the command, print(load(con)), runs, what
> message
> >>> do
> >>> > you see?
> >>> >
> >>> > --
> >>> > David L Carlson
> >>> > Associate Professor of Anthropology
> >>> > Texas A&M University
> >>> > College Station, TX 77843-4352
> >>> >
> >>> >
> >>> >> -Original Message-
> >>> >> From: r-help-boun...@r-project.org [mailto:r-help-bounces@r-
> >>> >> project.org] On Behalf Of Lorenzo Isella
> >>> >> Sent: Friday, August 10, 2012 3:21 PM
> >>> >> To: r-h...@stat.math.ethz.ch
> >>> >> Subject: [R] Trouble with Spatial Data Example Script
> >>> >>
> >>> >> Dear All,
> >>> >> I need to do something relatively simple: generate a map of
> Europe
> >>> and
> >>> >> paint the various states with different colors (only 3-4 are
> needed)
> >>> >> according to a rule.
> >>> >> I would like to keep it as simple as possible and the script
> >>> resorting
> >>> >> to
> >>> >> the sp package that I found at
> >>> >>
> >>> >> http://bit.ly/Oc71ub
> >>> >>
> >>> >> is exactly what I am looking for (I need to repeat the exercise
> with
> >>> >> Europe instead of Switzerland and to have a legend).
> >>> >> However, when I try to run the script (which I also paste at the
> end
> >>> of
> >>> >> the email), well, nothing happens and I certainly do not see a
> map
> >>> of
> >>> >> Switzerland.
> >>> >> I am not familiar with the sp package, but am I missing the
> obvious?
> >>> >> Any help is appreciated.
> >>> >> Best Regards
> >>> >>
> >>> >> Lorenzo
> >>> >>
> >>> >> à
> >>> >>
> >>> >> library(sp)
> >>> >> con <- url("http://gadm.org/data/rda/CHE_adm1.RData";)
> >>> >> print(load(con))
> >>> >> close(con)
> >>> >>
> >>> >>
> >>> >>
> >>> >>

Re: [R] Alternating between "for loops"

2012-08-11 Thread Rui Barradas

Hello,

I'm not sure it works, but try the following.

for(j in which(dtp)){
  for (q in 1:N){
if(y[q, j] %in% c("d", "D")) break
[...etc...]

and in the other loop the same,

for (j in which(!dtp)) {
  for (q in 1:N) {
if(y[q, j] %in% c("d", "D")) break
[...etc...]


Em 10-08-2012 20:42, Claudia Penaloza escreveu:

This is what my code looks like now. However, there is one thing I
can't/don't know how to fix.
I can't get it to be "once dead always dead", i.e., in any given row, after
a "D" or a "d" there should be only zeros.
I've tried applying a flag to break the loop if dead but I can't get it to
work.
Could you please help me with this?

Thank you for your time,
Claudia

J = 24
N = 10
S = .9
PsiADd = 0.4
PsiAA = .4
PsiaA = .3
p = .5
c = p

y <- matrix(0,N,J)
y[,1]="A"
dtp <- rep(c(TRUE, TRUE, FALSE, FALSE), 6)[seq_len(J)]
for(j in which(dtp)){
   for (q in 1:N){
 (observable <- TRUE)
 if(j %% 2){
   if (runif(1,0,1)<=S) {
 if (observable) {
   observable <- (runif(1,0,1)<=PsiAA)
 } else {
   observable <- (runif(1,0,1)<=PsiaA)
 }
 if (observable) {
   if (runif(1,0,1) <= p) y[q,j] <- "A"
 }
   } else {
 y[q,j] <- ifelse(runif(1,0,1) <= PsiADd,"d","D")
 break
   }
 } else {
   if(observable){
if(runif(1,0,1) <= c) y[q,j] <- "A"
   }
 }
   }
 }

for (j in which(!dtp)) {
   for (q in 1:N) {
 if (j %% 2) {
   if (observable) {
 observable <- runif(1, 0, 1) <= PsiAA
   } else {
 observable <- runif(1, 0, 1) <= PsiaA
   }
   if (observable) {
 if (runif(1, 0, 1) <= p) y[q, j] <- "A"
   }
 } else {
   if (observable) {
 if (runif(1, 0, 1) <= c) y[q, j] <- "A"
   }
 }
   }
}
On Wed, Aug 8, 2012 at 2:04 PM, Claudia Penaloza
wrote:


Answers inserted in BLUE below

On Thu, Aug 2, 2012 at 5:34 PM, Claudia Penaloza <
claudiapenal...@gmail.com> wrote:


Thank you very much for all your suggestions. I am very sorry my code is
so crude (it gives me a headache too!), I'm very new to R programing. I
will have to look at your suggestions/questions very carefully (I'm barely
holding on at this point) and get back to you (Dr. Winsemius) with some
answers.

Thank you!
Claudia

On Wed, Aug 1, 2012 at 2:11 PM, David Winsemius wrote:


On Aug 1, 2012, at 12:02 PM, Mercier Eloi wrote:

  Your code almost gave me a headache. :-/
I had a similar reaction. However, my approach might have been to
request a more complete verbal description of the data structures being
operated on and the methods and assumptions being used. Generally it is
going to be easier to go from a procedural description to good R code than
it is to go from a SAS Data Proc ... even if it were tested and debugged...
and yours was not even debugged.


  ##**##**

# Robust design with Markovian emigration and dummy time periods
##**##**
J = 24
N = 10
S = .9
PsiAD = 0.06
PsiAd = 0.04
PsiAA = .4
PsiaA = .3
p = .5
c = p
y <- matrix(0,N,J)


# So is 'y' a matrix of states where the N rows are levels and the J
columns are discrete times?
# Actually I decided that context suggested you were using letters to
represent states.


Yes, 'y' is a matrix of state, N rows are levels (independent of each

other) and J columns are discrete times.
Yes, I am using letters to represent states.


  y[,1]="A"
# So we start with N 's in state "A"?
# It seems as though it might be the case that every row is independent
of the others.
# .. and you are performing ( replicate()-ing in R terminology) this
test N times
# states:
#("A" "D")
#("a" "d")
#transitions:
matrix( c( runif(1, 0, 1) <= 0.4, # A -> A
   runif(1,0,1) <= 0.3,  # a -> A
   runif(1,0,1) <= 0.06. # A -> D
   runif(1,0,1) <= 0.04  # A -> d) )

# What is state "a"?
# How do you get from A to a?
# can you get from D or d to A or a?


Yes, we start with N "individuals" in state "A", each individual is

independent of each other.
State "a" is an unobserved (!observable) version of state "A"
(biologically, an individual that has temporarily left the sampling area
and is not available for capture)
  An individual in state "A" transitions to state "a" if it is observable
and doesn't stay (stay >= AA)
"D" and "d" are dead (absorbing) states. Once in either "D" or "d", the
individual can no longer transition and is no longer "captured" (the row
should only have zeros after a "D" or a "d")






# Not sure I have gotten the model assumptions down.
# Is D" or "d" an absorbing state such as "dead or "Dead"?


Yes.
dtp <- rep(c(TRUE, TRUE, FALSE, FALSE), 6)[seq_len(J)]


#Presumably the "dummy time periods"


Yes.



for(j in which(dtp)){   # j will be c(1,2, 5,6, 9,10 , ..., 21,22)



  for (q in 1:N){  # This can almost surely become vectorized

(obser

Re: [R] Trouble with Spatial Data Example Script

2012-08-11 Thread R. Michael Weylandt
I have no experience with spplot() or maps in general, but might this
be more or less tied to R FAQ 7.22?

Michael

On Sat, Aug 11, 2012 at 12:00 PM, Lorenzo Isella
 wrote:
> Hello,
> The situation is a bit odd.
> If I open an R session and I paste there the script, then it does work.
> However, if I save it as a text file and then I run it with the
> source("myfile.R") command, then I fall back to the case that started this
> thread i.e. I see nothing.
> Does anybody have a clue at what is going on?
> I paste below the output of sessionInfo(), which is the same no matter
> whether I paste the commands in a shell or use a .R file.
>
>
> sessionInfo()
> R version 2.15.1 (2012-06-22)
> Platform: x86_64-pc-linux-gnu (64-bit)
>
> locale:
>  [1] LC_CTYPE=en_US.UTF-8   LC_NUMERIC=C
>  [3] LC_TIME=en_US.UTF-8LC_COLLATE=en_US.UTF-8
>  [5] LC_MONETARY=en_US.UTF-8LC_MESSAGES=en_US.UTF-8
>  [7] LC_PAPER=C LC_NAME=C
>  [9] LC_ADDRESS=C   LC_TELEPHONE=C
> [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
>
> attached base packages:
> [1] stats graphics  grDevices utils datasets  methods   base
>
> other attached packages:
> [1] sp_0.9-99
>
> loaded via a namespace (and not attached):
> [1] grid_2.15.1lattice_0.20-6
>
>
> Many thanks
>
> Lorenzo
>
>
>
>
>
>
>
>
>
>
> On Sat, 11 Aug 2012 17:18:43 +0200, David L Carlson 
> wrote:
>
>> Can you get other plotting commands to work? E.g.
>>
>> plot(1:5, 1:5)
>>
>>> -Original Message-
>>> From: Lorenzo Isella [mailto:lorenzo.ise...@gmail.com]
>>> Sent: Saturday, August 11, 2012 3:20 AM
>>> To: dcarl...@tamu.edu
>>> Subject: Re: [R] Trouble with Spatial Data Example Script
>>>
>>> Thanks for your reply.
>>> I am running R 2.15.1 on debian testing, amd64 architecture.
>>>
>>>
>>>
>>>
>>> ~$ R
>>>
>>> R version 2.15.1 (2012-06-22) -- "Roasted Marshmallows"
>>> Copyright (C) 2012 The R Foundation for Statistical Computing
>>> ISBN 3-900051-07-0
>>> Platform: x86_64-pc-linux-gnu (64-bit)
>>>
>>>
>>> and when I run the script, this is what I see
>>>
>>>
>>>
>>> source('map-switzerland.R')
>>> [1] "gadm"
>>>
>>> gadm contains the data, but I do not see any map.
>>> Any hint about what is going on?
>>> Cheers
>>>
>>> Lorenzo
>>>
>>>
>>>
>>>
>>>
>>> On Fri, 10 Aug 2012 23:43:34 +0200, David L Carlson 
>>> wrote:
>>>
>>> > The script is working for me. Did you get any error or warning
>>> messages?
>>> > What version of R are you using? What operating system does your
>>> > computer use? When the command, print(load(con)), runs, what message
>>> do
>>> > you see?
>>> >
>>> > --
>>> > David L Carlson
>>> > Associate Professor of Anthropology
>>> > Texas A&M University
>>> > College Station, TX 77843-4352
>>> >
>>> >
>>> >> -Original Message-
>>> >> From: r-help-boun...@r-project.org [mailto:r-help-bounces@r-
>>> >> project.org] On Behalf Of Lorenzo Isella
>>> >> Sent: Friday, August 10, 2012 3:21 PM
>>> >> To: r-h...@stat.math.ethz.ch
>>> >> Subject: [R] Trouble with Spatial Data Example Script
>>> >>
>>> >> Dear All,
>>> >> I need to do something relatively simple: generate a map of Europe
>>> and
>>> >> paint the various states with different colors (only 3-4 are needed)
>>> >> according to a rule.
>>> >> I would like to keep it as simple as possible and the script
>>> resorting
>>> >> to
>>> >> the sp package that I found at
>>> >>
>>> >> http://bit.ly/Oc71ub
>>> >>
>>> >> is exactly what I am looking for (I need to repeat the exercise with
>>> >> Europe instead of Switzerland and to have a legend).
>>> >> However, when I try to run the script (which I also paste at the end
>>> of
>>> >> the email), well, nothing happens and I certainly do not see a map
>>> of
>>> >> Switzerland.
>>> >> I am not familiar with the sp package, but am I missing the obvious?
>>> >> Any help is appreciated.
>>> >> Best Regards
>>> >>
>>> >> Lorenzo
>>> >>
>>> >> à
>>> >>
>>> >> library(sp)
>>> >> con <- url("http://gadm.org/data/rda/CHE_adm1.RData";)
>>> >> print(load(con))
>>> >> close(con)
>>> >>
>>> >>
>>> >>
>>> >> language <- c("german", "german", "german","german",
>>> >>   "german","german","french", "french",
>>> >>   "german","german","french", "french",
>>> >>   "german", "french","german","german",
>>> >>   "german","german","german", "german",
>>> >>   "german","italian","german","french",
>>> >>   "french","german","german")
>>> >> gadm$language <- as.factor(language)
>>> >> col = rainbow(length(levels(gadm$language)))
>>> >> spplot(gadm, "language", col.regions=col, main="Swiss Language
>>> >> Regions")
>>> >>
>>> >> ###
>>> >>
>>> >> __
>>> >> R-help@r-project.org mailing list
>>> >> https://stat.ethz.ch/mailman/listinfo/r-help
>>> >> PLEASE do read the posting guide http://www.R-project.org/posting-
>>> >> guide.html
>>> >> and provide commented, minima

Re: [R] Trouble with Spatial Data Example Script

2012-08-11 Thread Lorenzo Isella

Hello,
The situation is a bit odd.
If I open an R session and I paste there the script, then it does work.
However, if I save it as a text file and then I run it with the  
source("myfile.R") command, then I fall back to the case that started this  
thread i.e. I see nothing.

Does anybody have a clue at what is going on?
I paste below the output of sessionInfo(), which is the same no matter  
whether I paste the commands in a shell or use a .R file.



sessionInfo()
R version 2.15.1 (2012-06-22)
Platform: x86_64-pc-linux-gnu (64-bit)

locale:
 [1] LC_CTYPE=en_US.UTF-8   LC_NUMERIC=C
 [3] LC_TIME=en_US.UTF-8LC_COLLATE=en_US.UTF-8
 [5] LC_MONETARY=en_US.UTF-8LC_MESSAGES=en_US.UTF-8
 [7] LC_PAPER=C LC_NAME=C
 [9] LC_ADDRESS=C   LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C

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

other attached packages:
[1] sp_0.9-99

loaded via a namespace (and not attached):
[1] grid_2.15.1lattice_0.20-6


Many thanks

Lorenzo










On Sat, 11 Aug 2012 17:18:43 +0200, David L Carlson   
wrote:



Can you get other plotting commands to work? E.g.

plot(1:5, 1:5)


-Original Message-
From: Lorenzo Isella [mailto:lorenzo.ise...@gmail.com]
Sent: Saturday, August 11, 2012 3:20 AM
To: dcarl...@tamu.edu
Subject: Re: [R] Trouble with Spatial Data Example Script

Thanks for your reply.
I am running R 2.15.1 on debian testing, amd64 architecture.




~$ R

R version 2.15.1 (2012-06-22) -- "Roasted Marshmallows"
Copyright (C) 2012 The R Foundation for Statistical Computing
ISBN 3-900051-07-0
Platform: x86_64-pc-linux-gnu (64-bit)


and when I run the script, this is what I see



source('map-switzerland.R')
[1] "gadm"

gadm contains the data, but I do not see any map.
Any hint about what is going on?
Cheers

Lorenzo





On Fri, 10 Aug 2012 23:43:34 +0200, David L Carlson 
wrote:

> The script is working for me. Did you get any error or warning
messages?
> What version of R are you using? What operating system does your
> computer use? When the command, print(load(con)), runs, what message
do
> you see?
>
> --
> David L Carlson
> Associate Professor of Anthropology
> Texas A&M University
> College Station, TX 77843-4352
>
>
>> -Original Message-
>> From: r-help-boun...@r-project.org [mailto:r-help-bounces@r-
>> project.org] On Behalf Of Lorenzo Isella
>> Sent: Friday, August 10, 2012 3:21 PM
>> To: r-h...@stat.math.ethz.ch
>> Subject: [R] Trouble with Spatial Data Example Script
>>
>> Dear All,
>> I need to do something relatively simple: generate a map of Europe
and
>> paint the various states with different colors (only 3-4 are needed)
>> according to a rule.
>> I would like to keep it as simple as possible and the script
resorting
>> to
>> the sp package that I found at
>>
>> http://bit.ly/Oc71ub
>>
>> is exactly what I am looking for (I need to repeat the exercise with
>> Europe instead of Switzerland and to have a legend).
>> However, when I try to run the script (which I also paste at the end
of
>> the email), well, nothing happens and I certainly do not see a map
of
>> Switzerland.
>> I am not familiar with the sp package, but am I missing the obvious?
>> Any help is appreciated.
>> Best Regards
>>
>> Lorenzo
>>
>> à
>>
>> library(sp)
>> con <- url("http://gadm.org/data/rda/CHE_adm1.RData";)
>> print(load(con))
>> close(con)
>>
>>
>>
>> language <- c("german", "german", "german","german",
>>   "german","german","french", "french",
>>   "german","german","french", "french",
>>   "german", "french","german","german",
>>   "german","german","german", "german",
>>   "german","italian","german","french",
>>   "french","german","german")
>> gadm$language <- as.factor(language)
>> col = rainbow(length(levels(gadm$language)))
>> spplot(gadm, "language", col.regions=col, main="Swiss Language
>> Regions")
>>
>> ###
>>
>> __
>> R-help@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/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] Time Series Have Date Show Days of the Week

2012-08-11 Thread G See
Alternatively, xts has a convenience function for this

.indexwday(SPY)
will give weekdays as numbers with Sunday being 0 and Saturday being 6.

There are also several similar functions
 .indexDate(x)
 .indexday(x)
 .indexmday(x)
 .indexwday(x)
 .indexweek(x)
 .indexmon(x)
 .indexyday(x)
 .indexyear(x)
 .indexhour(x)
 .indexmin(x)
 .indexsec(x)

Regards,
Garrett

On Wed, Aug 1, 2012 at 6:04 PM, R. Michael Weylandt
 wrote:
> On Wed, Aug 1, 2012 at 12:54 PM, Douglas Karabasz
>  wrote:
>> I used quantmod to pull in price data from the ticker SPY.  The data has
>> date and closing price.  I would like to show the day of the week for each
>> closing price.  Is that possible?  Also, I would like to add the back into
>> the data frame in a new column without changing the structure of the data
>> set if possible.
>>
>>
>>
>>  SPY
>>
>> 2009-01-02 92.96
>>
>> 2009-01-05 92.85
>>
>> 2009-01-06 93.47
>>
>> 2009-01-07 90.67
>>
>> 2009-01-08 91.04
>>
>> 2009-01-09 89.09
>>
>>
>>
>>> str(SP500)
>>
>> An 'xts' object from 2009-01-02 to 2012-07-31 containing:
>>
>>   Data: num [1:902, 1] 93 92.8 93.5 90.7 91 ...
>>
>> - attr(*, "dimnames")=List of 2
>>
>>   ..$ : NULL
>>
>>   ..$ : chr "SPY"
>>
>>   Indexed by objects of class: [Date] TZ:
>>
>>   xts Attributes:
>>
>> List of 4
>>
>> $ tclass : chr [1:2] "POSIXct" "POSIXt"
>>
>> $ tzone  : chr ""
>>
>> $ src: chr "yahoo"
>>
>> $ updated: POSIXct[1:1], format: "2012-07-31 17:59:16"
>>
>
> Hi Doug,
>
> No, this isn't quite doable. I'll give a somewhat technical
> description of why and then I'll propose a work around
>
>  Technical Stuff ---
>
> An "xts" object consists of two fundamental parts -- an index which is
> numeric (seconds since the epoch usually) and its "coredata" which is,
> in your case, the prices. The "coredata" is and must be all of the
> same "type" -- either integer, double, or string; internally, this is
> because it's all actually a matrix, which is in turn an atomic vector,
> and to be any sort of performant, we need them all of the same type.
> So there's no way for the coredata to have the _number_ 24 and the
> _string_ day of the week "tuesday".  We'll come back to this though.
>
> So you might ask about the index... xts hard-codes selected index
> classes to work. None of them currently have printing methods that
> write out the day of the week like you want, though you could define
> your own time index and use it in zoo if desired. That's almost
> certainly overkill though.
>
>  What to do 
>
> In light of the above, the easiest thing is probably to encode the day
> of the week as an integer if you really need it for calculations:
>
> as.numeric(factor(strptime(index(x), "%A")))
>
> will create that and then you can cbind() it on.
>
> Alternatively, you can cbind() just strptime(index(... on and you will
> change the coredata() to character. I'd do this instead if you're only
> looking for human output. Even better on the "just look" pretty front
> would be to make it into a data.frame for printing only:
>
> data.frame(x, `Day of the Week` = strptime(index(x), "%A"))
>
> but again -- that's only for printing: it will destroy the "xts"-ness.
>
> Best,
> Michael
>
>>
>>
>> Thank you,
>>
>> Douglas
>>
>>
>>
>>
>> [[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-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Function definition: where is the error in the "for" loop?

2012-08-11 Thread Dr. Holger van Lishaut

Am 11.08.2012, 01:18 Uhr, schrieb Rui Barradas :


[...] The solution is obviously to write 'for', with lowercase 'f'.

Hope this helps,


Dear Mr Barradas,

indeed it did help,
thank you very much!

Best regards
Holger van Lishaut

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Function definition: where is the error in the "for" loop?

2012-08-11 Thread Dr. Holger van Lishaut

Am 11.08.2012, 01:18 Uhr, schrieb Rui Barradas :


[...] The solution is obviously to write 'for', with lowercase 'f'.

Hope this helps,


Dear Mr Barradas,

indeed it did help, thank you very much!

Best regards
Holger van Lishaut

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 do I find the apparent magnitude of a galaxy from a FITS file?

2012-08-11 Thread David L Carlson
Actually you could find it with RSiteSearch("FITS") which comes with base R
as the first hit:

1. R: Read a single data set from a FITS file (score: 51)
Author: unknown
Date: Wed, 22 Feb 2012 19:25:09 -0500
Read a single data set from a FITS file Description Usage Arguments
Details Value Note Author(s) References See Also Examples page for readFITS
{FITSio} readFITS {FITSio} R Documentation Read a sing
http://finzi.psych.upenn.edu/R/library/FITSio/html/readFITS.html (8,088
bytes)

That leads you to FITSio, the package that you probably want to install and
learn how to use to read FITS files.

A little work with google leads to 
http://fits.gsfc.nasa.gov/
http://en.wikipedia.org/wiki/FITS

It appears that FITS is an image and table format for storing astronomical
data so there is more than one kind of FITS file. You haven't told us what
kind of FITS file you are using or where it came from (although that
probably wouldn't help in this case since we answer questions about R not
astronomy). You probably need to re-visit the web site from which you
obtained the data and do a little research on your own (e.g.
http://www.sdss.org/dr7/).

--
David L Carlson
Associate Professor of Anthropology
Texas A&M University
College Station, TX 77843-4352





> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-bounces@r-
> project.org] On Behalf Of David Winsemius
> Sent: Friday, August 10, 2012 8:36 PM
> To: andrej
> Cc: r-help@r-project.org
> Subject: Re: [R] How do I find the apparent magnitude of a galaxy from
> a FITS file?
> 
> 
> On Aug 10, 2012, at 4:06 PM, andrej wrote:
> 
> > I put "sos::findFn('fits')" into the search engine and it returned 0
> > results,
> > so how are you finding this?
> 
> 'sos' is an R package. I'm guessing you did not install and load 'sos'
> before typing that command at the console.  (You might be able to get
> away without loading by using the double-colon maneuver.) That was not
> a particularly well crafted search strategy IMO,  given the number of
> times that the word 'fit' or 'fits' will appear in statistical
> documentation.
> 
> sos::findFn('fits')
> found 2482 matches;  retrieving 20 pages, 400 matches.
> 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
> 
> Nonetheless, it "worked". The browser page coming up from that search
> had the package FITSio 25th line.
> 
> Better might have been:
> 
>  > sos::findFn('fits astronomical')
> found 4 matches;  retrieving 1 page
> 
> > Also: Why was my mailing list message rejected as a duplicate?
> 
> Because you posted two duplicate messages. One of them was forwarded
> to the list.
> 
> > I don't even understand how these underground subscriptions work, am
> > I off the mailing
> > list because it's a duplicate?
> 
> No. You were just notified in hopes that you would stop sending
> duplicates. The list-server thinks you are a subscriber, but for some
> reason it will keep on sending posting from new subscribers to the
> moderation queue for the first 24 hours. That's not something that
> moderator have control over. Don't complain, we don't like it either.
> 
> I don't understand the term "underground subscriptions". Mailing lists
> can be public or private. Ours is rather public, having multiple
> mirrors and search engines around the world. Our host university's
> site-admins have installed fairly stringent filters in an effort to
> prevent their domain from being automatically flagged as a source of
> spam. Some domains like hotmail.com have a high probability of being
> flagged for moderator review. Some posters from hotmail are on
> perpetual review, despite being perfectly fine citizens.
> 
> 
> > --
> > View this message in context: http://r.789695.n4.nabble.com/How-do-I-
> find-the-apparent-magnitude-of-a-galaxy-from-a-FITS-file-
> tp4639907p4639996.html
> > Sent from the R help mailing list archive at Nabble.com.
> 
> Nabble is not the r-help mailing list. You should read the Posting
> Guide and learn to include context with your replies. Nabble users are
> notorious for faling to heed that request.)
> 
> --
> 
> David Winsemius, MD
> Alameda, CA, 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] How do I find the apparent magnitude of a galaxy from a FITS file?

2012-08-11 Thread Michael Weylandt


On Aug 11, 2012, at 6:34 AM, andrej  wrote:

> 
> [2] I obtained R (actually R64) from the following website:
> http://cran.cnr.berkeley.edu/bin/macosx/
> 
> I guess it didn't come with an 'sos' package. I assume it's here:
> http://cran.r-project.org/web/packages/sos/index.html
> 
> and when I download/expand the package, I get a bunch of files, but I didn't
> see anything in them or the sos.pdf manual that tells me where the files go.

Since you're on a Mac, it's much easier to simply type

install.packages("sos")

Inside R to install the package (which you only need to do once) and then 

library(sos)

In each session you wish to use it to load the package


Michael

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Function definition: where is the error in the "for" loop?

2012-08-11 Thread David L Carlson
There is no command "For" in R. It is "for" and R is case sensitive.

--
David L Carlson
Associate Professor of Anthropology
Texas A&M University
College Station, TX 77843-4352


> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-bounces@r-
> project.org] On Behalf Of Dr. Holger van Lishaut
> Sent: Friday, August 10, 2012 4:16 PM
> To: r-help@r-project.org
> Subject: [R] Function definition: where is the error in the "for" loop?
> 
> Dear all,
> 
> The following function code fails with errors (see below):
> 
> RegPlots <- function (data, ContrVar, RespVar){
>intNmbrRows<-length(RespVar);intNmbrCols<-lenght(ContrVar)
>par(mfrow=c(intNmbrRows,intNmbrCols))
>For(i in 1:intNmbrRows){
>For (j in 1:intNmbrCols){
>RegGraf(data,ContrVar[i],RespVar[j])
>}
>}
>par(mfrow=c(1,1))
> 
> #(RegGraf is another function that creates a plot and that runs
> flawlessly)
> 
> Output (translated to english):
> 
> > RegPlots <- function (data, ContrVar, RespVar){
> + intNmbrRows<-length(RespVar);intNmbrCols<-lenght(ContrVar)
> + par(mfrow=c(intNmbrRows,intNmbrCols))
> + For(i in 1:intNmbrRows){
> Error: Unexpected 'in' in:
> "par(mfrow=c(intNmbrRows,intNmbrCols))
>For(i in"
> > For (j in 1:intNmbrCols){
> Error: Unexpected 'in' in "For (j in"
> > RegGraf(data,ContrVar[i],RespVar[j])
> Error in RegGraf(data, ContrVar[i], RespVar[j]) :
>  Object 'ContrVar' not found
> > }
> Error: Unexpected '}' in "}"
> > }
> Error: Unexpected '}' in "}"
> > par(mfrow=c(1,1))
> 
> Can someone please show me what is wrong?
> 
> Thanks in advance
> Holger
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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] Batch Mode for Windows

2012-08-11 Thread FJ M

I have a batch file to run R commands in a text file and an output file that I 
use. 
 
"C:\Program Files\R\R-2.13.2\bin\x64\R.exe" CMD BATCH
"C:\Users\Frank\Documents\R\Scripts\TLT_2012.txt" 
"C:\Users\Frank\Documents\R\Scripts\TLT_2012.out"
PAUSE 
 
I worked in an environment that you had to fully specify a path, hence

 "C:\Program Files\R\R-2.13.2\bin\x64\R.exe"
 
which I continue as a personal "best practices."
 
TLT_2012.txt starts with
 
colors <- c("red", "blue", "darkgreen", "gold", "black")
labels <- c("8/11/2011","11/3/2011", "2/28/2012", "5/9/2012")
pdf("C:\\Users\\Frank\\Documents\\R\\Scripts\\TLT_2012.pdf")
.
.
.
 
TLT_2012.out contains the R output and in particular the errors and warnings. I 
always consult the .out file first since I usually have errors :).
 
Best,
 
Frank
Chicago, IL 
 

> Date: Fri, 10 Aug 2012 13:59:34 -0700
> From: sx...@mtlakes.org
> To: r-help@r-project.org
> Subject: [R] Batch Mode for Windows
> 
> Hi, I have researched batch mode for windows and could not find anything that
> worked.
> I know the code should be
> 
> $ R CMD BATCH inputfile.R outputfile.Rout
> or
> R  outputfile.Rout
> 
> I tried these without success. I need detailed, step by step instructions on
> how to do this. I have tried typing C:\R\bin\x64\Rgui.exe before it, but
> this just opens R.
> 
> When I tried to do this, it said that $, R, etc. are not recognizable
> commands. In other instances it said that the arguments R, CMD, and BATCH
> were ignored. What specifically should I do to make this work? I thought I
> was supposed to change the directory to the folder where my input file was
> stored, but this did not work either. 
> 
> 
> 
> --
> View this message in context: 
> http://r.789695.n4.nabble.com/Batch-Mode-for-Windows-tp4639977.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] Problem when creating matrix of values based on covariance matrix

2012-08-11 Thread Boel Brynedal
Hi, thanks for the reply.
I am not assuming that the supplied covariance vector in any way
captures the 'true' covariance matrix of the population, but thats not
what I am after either. I just want to simulate data that has a
similar covariance as that covariance matrix. And the numbers are so
hugely different! Could sampling error cause that? Could the
covariance structure be too complicated to simulate?

And yes, I should probably post this on a stat-list, true.

Thanks,
Bo

2012/8/11 Bert Gunter :
> Sampling error?   Do you realize how large a sample size you would
> need to precisely estimate an 8000 x 8000 covariance matrix? Probably
> exceeds the number of stars in our galaxy...
>
> Numerical issues may also play a role, but I am too ignorant on this
> aspect to offer advice.
>
> Finally, this is really not an R question, so you would probably do
> better to post on a stats site like stats.stackexchange.com rather
> than here.
>
> -- Bert
>
> On Sat, Aug 11, 2012 at 7:17 AM, Boel Brynedal  wrote:
>> Hi,
>>
>> I want to simulate a data set with similar covariance structure as my
>> observed data, and have calculated a covariance matrix (dimensions
>> 8368*8368). So far I've tried two approaches to simulating data:
>> rmvnorm from the mvtnorm package, and by using the Cholesky
>> decomposition 
>> (http://www.cerebralmastication.com/2010/09/cholesk-post-on-correlated-random-normal-generation/).
>> The problem is that the resulting covariance structure in my simulated
>> data is very different from the original supplied covariance vector.
>> Lets just look at some of the values:
>>
>>> cov8[1:4,1:4] # covariance of simulated data
>> X1  X2 X3 X4
>> X1 34515296.0099956.69   369538.1  1749086.6
>> X299956.69 34515296.00  2145289.9  -624961.1
>> X3   369538.08  2145289.93 34515296.0  -163716.5
>> X4  1749086.62  -624961.09  -163716.5 34515296.0
>>> CEUcovar[1:4,1:4]
>>  [,1] [,2]  [,3] [,4]
>> [1,] 0.1873402987  0.001837229  0.0009009272  0.010324521
>> [2,] 0.0018372286  0.188665853  0.0124216535 -0.001755035
>> [3,] 0.0009009272  0.012421654  0.1867835412 -0.000142395
>> [4,] 0.0103245214 -0.001755035 -0.0001423950  0.192883488
>>
>> So the distribution of the observed covariance is very narrow compared
>> to the simulated data.
>>
>> None of the eigenvalues of the observed covariance matrix are
>> negative, and it appears to be a positive definite matrix. Here is
>> what I did to create the simulated data:
>>
>> Chol <- chol(CEUcovar)
>> Z <- matrix(rnorm(20351 * 8368), 8368)
>> X <- t(Chol) %*% Z
>> sample8 <- data.frame(as.matrix(t(X)))
>>> dim(sample8)
>> [1] 20351  8368
>> cov8=cov(sample8,method='spearman')
>>
>> [earlier I've also tried sample8 <- rmvnorm(1000,
>> mean=rep(0,ncol(CEUcovar)), sigma=CEUcovar, method="eigen") with as
>> 'bad' results, much larger covariance values in the simulated data ]
>>
>> Any ideas of WHY the simulated data have such a different covariance?
>> Any experience with similar issues? Would be happy to supply the
>> covariance matrix if anyone wants to give it a try.
>> Any suggestions? Anything apparent that I left our or neglected?
>>
>> Any advice would be highly appreciated.
>> Best,
>> Bo
>>
>> __
>> R-help@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/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.


Re: [R] How to add values on bar of groouped bar plot using mtext?

2012-08-11 Thread Uwe Ligges



On 11.08.2012 04:55, Manish Gupta wrote:

How to write values on bars using mtext?

Grouped Bar Plot
counts <- table(mtcars$vs, mtcars$gear) barplot(counts, main="Car
Distribution by Gears and VS",xlab="Number of Gears",
col=c("darkblue","red"),legend = rownames(counts), beside=TRUE, horiz=TRUE)

mtext(counts ) # But poistion is not at each bar.

How can i put corresponsing values on each bars of  plot?


Look at the output of barplot, it returns the locations:

bp <- barplot(counts, main = "Car Distribution by Gears and VS",
xlab = "Number of Gears", col = c("darkblue", "red"),
legend = rownames(counts), beside = TRUE, horiz = TRUE)
bp
mtext(side = 2, at = bp, text = counts)



Uwe Ligges







Regards




--
View this message in context: 
http://r.789695.n4.nabble.com/How-to-add-values-on-bar-of-groouped-bar-plot-using-mtext-tp4640014.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] Problem when creating matrix of values based on covariance matrix

2012-08-11 Thread Bert Gunter
Sampling error?   Do you realize how large a sample size you would
need to precisely estimate an 8000 x 8000 covariance matrix? Probably
exceeds the number of stars in our galaxy...

Numerical issues may also play a role, but I am too ignorant on this
aspect to offer advice.

Finally, this is really not an R question, so you would probably do
better to post on a stats site like stats.stackexchange.com rather
than here.

-- Bert

On Sat, Aug 11, 2012 at 7:17 AM, Boel Brynedal  wrote:
> Hi,
>
> I want to simulate a data set with similar covariance structure as my
> observed data, and have calculated a covariance matrix (dimensions
> 8368*8368). So far I've tried two approaches to simulating data:
> rmvnorm from the mvtnorm package, and by using the Cholesky
> decomposition 
> (http://www.cerebralmastication.com/2010/09/cholesk-post-on-correlated-random-normal-generation/).
> The problem is that the resulting covariance structure in my simulated
> data is very different from the original supplied covariance vector.
> Lets just look at some of the values:
>
>> cov8[1:4,1:4] # covariance of simulated data
> X1  X2 X3 X4
> X1 34515296.0099956.69   369538.1  1749086.6
> X299956.69 34515296.00  2145289.9  -624961.1
> X3   369538.08  2145289.93 34515296.0  -163716.5
> X4  1749086.62  -624961.09  -163716.5 34515296.0
>> CEUcovar[1:4,1:4]
>  [,1] [,2]  [,3] [,4]
> [1,] 0.1873402987  0.001837229  0.0009009272  0.010324521
> [2,] 0.0018372286  0.188665853  0.0124216535 -0.001755035
> [3,] 0.0009009272  0.012421654  0.1867835412 -0.000142395
> [4,] 0.0103245214 -0.001755035 -0.0001423950  0.192883488
>
> So the distribution of the observed covariance is very narrow compared
> to the simulated data.
>
> None of the eigenvalues of the observed covariance matrix are
> negative, and it appears to be a positive definite matrix. Here is
> what I did to create the simulated data:
>
> Chol <- chol(CEUcovar)
> Z <- matrix(rnorm(20351 * 8368), 8368)
> X <- t(Chol) %*% Z
> sample8 <- data.frame(as.matrix(t(X)))
>> dim(sample8)
> [1] 20351  8368
> cov8=cov(sample8,method='spearman')
>
> [earlier I've also tried sample8 <- rmvnorm(1000,
> mean=rep(0,ncol(CEUcovar)), sigma=CEUcovar, method="eigen") with as
> 'bad' results, much larger covariance values in the simulated data ]
>
> Any ideas of WHY the simulated data have such a different covariance?
> Any experience with similar issues? Would be happy to supply the
> covariance matrix if anyone wants to give it a try.
> Any suggestions? Anything apparent that I left our or neglected?
>
> Any advice would be highly appreciated.
> Best,
> Bo
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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.


Re: [R] Stopping all code execution when ANY error occurs (OR error handling without try/tryCatch)

2012-08-11 Thread Uwe Ligges
Easy: Wrap your code into a function. A function by default exits on the 
first error.


Best,
Uwe Ligges





On 11.08.2012 10:07, enocko wrote:

Hi all,

I often run a bunch of code with Run Selection, and, after it's done
running, I find there have been like 20 errors, all due to an error that
occurred early in my code, which caused problems from there on. (I must then
scroll up through lots of code to find it.)

What I would like is for R to stop executing when an error occurs.

I am aware of a few solutions:
1. Put all the code in a function
2. Put all the code in a tryCatch statement with error handling
3. *partial solution only* Replace stop() with my own function, so at least
if the errors are coming from a call to stop, I can catch them and halt all
code execution. (I do this halting with a hack involving quit() and .Last(),
so also please let me know if there's a better way)

However, I don't want to put all the code in braces while I'm just
developing/playing around with code. I run various snippets of code all the
time, and it's time consuming to always make a tryCatch or function
surrounding whatever I'm executing.

Is there any way to do a kind of global error handling, so I could source()
some file once and then have it set for the rest of my session that day?

To see multiple errors that R doesn't stop, you can put these 2 lines into a
script and do Run Selection:
5[[2]] <- 1
list() <- 1

You'll notice that 2 errors occur, whereas what I want is for execution to
just stop after the first error, so that the second line never gets run.

Thanks very much,

Phil



--
View this message in context: 
http://r.789695.n4.nabble.com/Stopping-all-code-execution-when-ANY-error-occurs-OR-error-handling-without-try-tryCatch-tp4640023.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] Stopping all code execution when ANY error occurs (OR error handling without try/tryCatch)

2012-08-11 Thread Bert Gunter
1. You probably need to tell us on what platform (OS, version) you are
running, as requested by the posting guide.

2. To me, it sounds like your question is: How can I avoid using the
error trapping tools built into R but still trap errors. If so, pretty
nonsensical, no?

3. But maybe someone else can suggest something useful. My thought is
that what you really need is to think out of the box and use a better
IDE. Check out CRAN for alternatives, but ESS, RStudio, Tinn-R, and
WInedit immediately come to mind. what will work for you depends on
your platform (ergo 1 above).

Cheers,
Bert

On Sat, Aug 11, 2012 at 1:07 AM, enocko  wrote:
> Hi all,
>
> I often run a bunch of code with Run Selection, and, after it's done
> running, I find there have been like 20 errors, all due to an error that
> occurred early in my code, which caused problems from there on. (I must then
> scroll up through lots of code to find it.)
>
> What I would like is for R to stop executing when an error occurs.
>
> I am aware of a few solutions:
> 1. Put all the code in a function
> 2. Put all the code in a tryCatch statement with error handling
> 3. *partial solution only* Replace stop() with my own function, so at least
> if the errors are coming from a call to stop, I can catch them and halt all
> code execution. (I do this halting with a hack involving quit() and .Last(),
> so also please let me know if there's a better way)
>
> However, I don't want to put all the code in braces while I'm just
> developing/playing around with code. I run various snippets of code all the
> time, and it's time consuming to always make a tryCatch or function
> surrounding whatever I'm executing.
>
> Is there any way to do a kind of global error handling, so I could source()
> some file once and then have it set for the rest of my session that day?
>
> To see multiple errors that R doesn't stop, you can put these 2 lines into a
> script and do Run Selection:
> 5[[2]] <- 1
> list() <- 1
>
> You'll notice that 2 errors occur, whereas what I want is for execution to
> just stop after the first error, so that the second line never gets run.
>
> Thanks very much,
>
> Phil
>
>
>
> --
> View this message in context: 
> http://r.789695.n4.nabble.com/Stopping-all-code-execution-when-ANY-error-occurs-OR-error-handling-without-try-tryCatch-tp4640023.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.



-- 

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.


Re: [R] stopping rule in hierarchical Clustering

2012-08-11 Thread Uwe Ligges



On 11.08.2012 06:19, eliza botto wrote:


Dear R users,

Is there a way to apply a “stopping
rule” in hierarchical Clustering? I have a data and I want to find the optimal
number of clusters while doing hierarchical clustering. I would be deeply 
obliged
if someone, whoever applied stopping rule, could send me the scripts. thanks in 
advance


There are hundreds of such rules to find a proper number of clusters for 
a given data situation. We do not know which one fits to your data, 
hence you will have to start reading some books and papers on the topic. 
A good keyword to start is probably "cluster index".


Best,
Uwe Ligges







Regards

Eliza botto 
[[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] Problem when creating matrix of values based on covariance matrix

2012-08-11 Thread Boel Brynedal
Hi,

I want to simulate a data set with similar covariance structure as my
observed data, and have calculated a covariance matrix (dimensions
8368*8368). So far I've tried two approaches to simulating data:
rmvnorm from the mvtnorm package, and by using the Cholesky
decomposition 
(http://www.cerebralmastication.com/2010/09/cholesk-post-on-correlated-random-normal-generation/).
The problem is that the resulting covariance structure in my simulated
data is very different from the original supplied covariance vector.
Lets just look at some of the values:

> cov8[1:4,1:4] # covariance of simulated data
X1  X2 X3 X4
X1 34515296.0099956.69   369538.1  1749086.6
X299956.69 34515296.00  2145289.9  -624961.1
X3   369538.08  2145289.93 34515296.0  -163716.5
X4  1749086.62  -624961.09  -163716.5 34515296.0
> CEUcovar[1:4,1:4]
 [,1] [,2]  [,3] [,4]
[1,] 0.1873402987  0.001837229  0.0009009272  0.010324521
[2,] 0.0018372286  0.188665853  0.0124216535 -0.001755035
[3,] 0.0009009272  0.012421654  0.1867835412 -0.000142395
[4,] 0.0103245214 -0.001755035 -0.0001423950  0.192883488

So the distribution of the observed covariance is very narrow compared
to the simulated data.

None of the eigenvalues of the observed covariance matrix are
negative, and it appears to be a positive definite matrix. Here is
what I did to create the simulated data:

Chol <- chol(CEUcovar)
Z <- matrix(rnorm(20351 * 8368), 8368)
X <- t(Chol) %*% Z
sample8 <- data.frame(as.matrix(t(X)))
> dim(sample8)
[1] 20351  8368
cov8=cov(sample8,method='spearman')

[earlier I've also tried sample8 <- rmvnorm(1000,
mean=rep(0,ncol(CEUcovar)), sigma=CEUcovar, method="eigen") with as
'bad' results, much larger covariance values in the simulated data ]

Any ideas of WHY the simulated data have such a different covariance?
Any experience with similar issues? Would be happy to supply the
covariance matrix if anyone wants to give it a try.
Any suggestions? Anything apparent that I left our or neglected?

Any advice would be highly appreciated.
Best,
Bo

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 do I find the apparent magnitude of a galaxy from a FITS file?

2012-08-11 Thread andrej
[1] Oh, that kind of duplicate... I thought you meant duplicate in that
someone else had already asked how to use R to analyze FITS images. Well
every time I post, I get the "Mailing List Subscription Reminder." I suppose
you want me to just click on "I'm already a subscriber" and just post here
then.

[2] I obtained R (actually R64) from the following website:
http://cran.cnr.berkeley.edu/bin/macosx/

I guess it didn't come with an 'sos' package. I assume it's here:
http://cran.r-project.org/web/packages/sos/index.html

and when I download/expand the package, I get a bunch of files, but I didn't
see anything in them or the sos.pdf manual that tells me where the files go.


[3] Anyway, does anyone know of how to do FITS magnitudes in R, or at least
know of a community that uses R to look at and analyze FITS images?



--
View this message in context: 
http://r.789695.n4.nabble.com/How-do-I-find-the-apparent-magnitude-of-a-galaxy-from-a-FITS-file-tp4639907p4640032.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] Stopping all code execution when ANY error occurs (OR error handling without try/tryCatch)

2012-08-11 Thread enocko
Hi all,

I often run a bunch of code with Run Selection, and, after it's done
running, I find there have been like 20 errors, all due to an error that
occurred early in my code, which caused problems from there on. (I must then
scroll up through lots of code to find it.)

What I would like is for R to stop executing when an error occurs.

I am aware of a few solutions:
1. Put all the code in a function
2. Put all the code in a tryCatch statement with error handling
3. *partial solution only* Replace stop() with my own function, so at least
if the errors are coming from a call to stop, I can catch them and halt all
code execution. (I do this halting with a hack involving quit() and .Last(),
so also please let me know if there's a better way)

However, I don't want to put all the code in braces while I'm just
developing/playing around with code. I run various snippets of code all the
time, and it's time consuming to always make a tryCatch or function
surrounding whatever I'm executing.

Is there any way to do a kind of global error handling, so I could source()
some file once and then have it set for the rest of my session that day?

To see multiple errors that R doesn't stop, you can put these 2 lines into a
script and do Run Selection:
5[[2]] <- 1
list() <- 1

You'll notice that 2 errors occur, whereas what I want is for execution to
just stop after the first error, so that the second line never gets run.

Thanks very much,

Phil



--
View this message in context: 
http://r.789695.n4.nabble.com/Stopping-all-code-execution-when-ANY-error-occurs-OR-error-handling-without-try-tryCatch-tp4640023.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] Trouble with Spatial Data Example Script

2012-08-11 Thread John Kane
As David Carlson mentioned earlier your script is working well for me. 

sessionInfo()
R version 2.15.1 (2012-06-22)
Platform: i686-pc-linux-gnu (32-bit)

locale:
 [1] LC_CTYPE=en_US.UTF-8   LC_NUMERIC=C  
 [3] LC_TIME=en_CA.UTF-8LC_COLLATE=en_US.UTF-8
 [5] LC_MONETARY=en_CA.UTF-8LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=C LC_NAME=C 
 [9] LC_ADDRESS=C   LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_CA.UTF-8 LC_IDENTIFICATION=C   

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

other attached packages:
[1] sp_0.9-99

loaded via a namespace (and not attached):
[1] fortunes_1.5-0 grid_2.15.1lattice_0.20-6


John Kane
Kingston ON Canada


> -Original Message-
> From: lorenzo.ise...@gmail.com
> Sent: Fri, 10 Aug 2012 22:20:56 +0200
> To: r-h...@stat.math.ethz.ch
> Subject: [R] Trouble with Spatial Data Example Script
> 
> Dear All,
> I need to do something relatively simple: generate a map of Europe and
> paint the various states with different colors (only 3-4 are needed)
> according to a rule.
> I would like to keep it as simple as possible and the script resorting to
> the sp package that I found at
> 
> http://bit.ly/Oc71ub
> 
> is exactly what I am looking for (I need to repeat the exercise with
> Europe instead of Switzerland and to have a legend).
> However, when I try to run the script (which I also paste at the end of
> the email), well, nothing happens and I certainly do not see a map of
> Switzerland.
> I am not familiar with the sp package, but am I missing the obvious?
> Any help is appreciated.
> Best Regards
> 
> Lorenzo
> 
> à
> 
> library(sp)
> con <- url("http://gadm.org/data/rda/CHE_adm1.RData";)
> print(load(con))
> close(con)
> 
> 
> 
> language <- c("german", "german", "german","german",
>   "german","german","french", "french",
>   "german","german","french", "french",
>   "german", "french","german","german",
>   "german","german","german", "german",
>   "german","italian","german","french",
>   "french","german","german")
> gadm$language <- as.factor(language)
> col = rainbow(length(levels(gadm$language)))
> spplot(gadm, "language", col.regions=col, main="Swiss Language Regions")
> 
> ###
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.


GET FREE SMILEYS FOR YOUR IM & EMAIL - Learn more at 
http://www.inbox.com/smileys
Works with AIM®, MSN® Messenger, Yahoo!® Messenger, ICQ®, Google Talk™ and most 
webmails

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] choosing multiple columns

2012-08-11 Thread Ista Zahn
On Sat, Aug 11, 2012 at 8:51 AM, Sachinthaka Abeywardana
 wrote:
> I should have mentioned that I do not know the number index of the columns,
> but regardless, thanks for the responses

Right, so use my first method. This does not depend on the position of
the columns.

Best,
Ista

>
>
> On Sat, Aug 11, 2012 at 10:46 PM, Ista Zahn  wrote:
>>
>> Hi Sachin,
>>
>> There are at least two ways. The safer way is to use a regular
>> expression to find the matching columns, like this:
>>
>> a <- initial_data[grep("^OFB[0-9]+", names(initial_data))]
>>
>> Alternatively, if you know that the columns you want are the first 8
>> you can select them by position, like this:
>>
>> a <- initial_data[1:8]
>>
>> Best,
>> Ista
>>
>> On Sat, Aug 11, 2012 at 7:59 AM, Sachinthaka Abeywardana
>>  wrote:
>> > Hi all,
>> >
>> > I have a data frame that has the columns OFB1, OFB2, OFB3,... OFB10.
>> >
>> > How do I select the first 8 columns efficiently without typing each and
>> > every one of them. i.e. I want something like:
>> >
>> > a<-data.frame(initial_data$OFB1-10) #i know this is wrong, what would be
>> > the correct syntax?
>> >
>> > Thanks,
>> > Sachin
>> >
>> > [[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] choosing multiple columns

2012-08-11 Thread Sachinthaka Abeywardana
I should have mentioned that I do not know the number index of the columns,
but regardless, thanks for the responses

On Sat, Aug 11, 2012 at 10:46 PM, Ista Zahn  wrote:

> Hi Sachin,
>
> There are at least two ways. The safer way is to use a regular
> expression to find the matching columns, like this:
>
> a <- initial_data[grep("^OFB[0-9]+", names(initial_data))]
>
> Alternatively, if you know that the columns you want are the first 8
> you can select them by position, like this:
>
> a <- initial_data[1:8]
>
> Best,
> Ista
>
> On Sat, Aug 11, 2012 at 7:59 AM, Sachinthaka Abeywardana
>  wrote:
> > Hi all,
> >
> > I have a data frame that has the columns OFB1, OFB2, OFB3,... OFB10.
> >
> > How do I select the first 8 columns efficiently without typing each and
> > every one of them. i.e. I want something like:
> >
> > a<-data.frame(initial_data$OFB1-10) #i know this is wrong, what would be
> > the correct syntax?
> >
> > Thanks,
> > Sachin
> >
> > [[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] choosing multiple columns

2012-08-11 Thread Ista Zahn
Hi Sachin,

There are at least two ways. The safer way is to use a regular
expression to find the matching columns, like this:

a <- initial_data[grep("^OFB[0-9]+", names(initial_data))]

Alternatively, if you know that the columns you want are the first 8
you can select them by position, like this:

a <- initial_data[1:8]

Best,
Ista

On Sat, Aug 11, 2012 at 7:59 AM, Sachinthaka Abeywardana
 wrote:
> Hi all,
>
> I have a data frame that has the columns OFB1, OFB2, OFB3,... OFB10.
>
> How do I select the first 8 columns efficiently without typing each and
> every one of them. i.e. I want something like:
>
> a<-data.frame(initial_data$OFB1-10) #i know this is wrong, what would be
> the correct syntax?
>
> Thanks,
> Sachin
>
> [[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] choosing multiple columns

2012-08-11 Thread John Kane
mydata[ , 1:8]


Or let's say you only one the 4th, 6th and 8th columns

mydata[ , c(4,6,8)]

and so on.  

There are several good intro's available on the R website that will walk you 
through this type of thing.

If you're a recovering SAS or SPSS user this paper may be of real help 
www.et.bs.ehu.es/~etptupaf/pub/R/RforSAS&SPSSusers.pdf


John Kane
Kingston ON Canada


> -Original Message-
> From: sachin.abeyward...@gmail.com
> Sent: Sat, 11 Aug 2012 21:59:59 +1000
> To: r-help@r-project.org
> Subject: [R] choosing multiple columns
> 
> Hi all,
> 
> I have a data frame that has the columns OFB1, OFB2, OFB3,... OFB10.
> 
> How do I select the first 8 columns efficiently without typing each and
> every one of them. i.e. I want something like:
> 
> a<-data.frame(initial_data$OFB1-10) #i know this is wrong, what would be
> the correct syntax?
> 
> Thanks,
> Sachin
> 
>   [[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.


FREE 3D EARTH SCREENSAVER - Watch the Earth right on your desktop!

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Batch Mode for Windows

2012-08-11 Thread Uwe Ligges



On 10.08.2012 22:59, sharx wrote:

Hi, I have researched batch mode for windows and could not find anything that
worked.
I know the code should be

$ R CMD BATCH inputfile.R outputfile.Rout
or
R  outputfile.Rout


Almost right, see below.



I tried these without success. I need detailed, step by step instructions on
how to do this. I have tried typing  C:\R\bin\x64\Rgui.exe before it, but
this just opens R.

When I tried to do this, it said that $


$ indicates you shoudl thpy in the OS shell. Do not repeat that one when 
typing commands.



, R, etc. are not recognizable


In that case, you have not added the directory where R.exe lives to the 
PATH environment variable.


Uwe Ligges



commands. In other instances it said that the arguments R, CMD, and BATCH
were ignored. What specifically should I do to make this work?  I thought I
was supposed to change the directory to the folder where my input file was
stored, but this did not work either.



--
View this message in context: 
http://r.789695.n4.nabble.com/Batch-Mode-for-Windows-tp4639977.html
Sent from the R help mailing list archive at Nabble.com.

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



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


[R] choosing multiple columns

2012-08-11 Thread Sachinthaka Abeywardana
Hi all,

I have a data frame that has the columns OFB1, OFB2, OFB3,... OFB10.

How do I select the first 8 columns efficiently without typing each and
every one of them. i.e. I want something like:

a<-data.frame(initial_data$OFB1-10) #i know this is wrong, what would be
the correct syntax?

Thanks,
Sachin

[[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] device "mismatch", coordinates trouble with X11 and pdf devices

2012-08-11 Thread peter dalgaard

On Aug 11, 2012, at 07:53 , Paul Johnson wrote:

> Greetings.
> 
> I'm trying to understand a problem on a Dell Laptop.  Details below,
> also uploaded the R working example that I pasted below.

The difference is not in locator() but in the circles, which in turn is due to 
different aspect ratios in the two devices. Notice that in the X11 plot, the 
circles are truncated top and bottom, whereas in PDF you see the entire 
perimeter. The axes are roughly the same. I.e. the circles on the X11 device 
would map onto ellipses on the PDF by vertical stretching. 

If you look carefully, you can see that the X11 plot is "less square" than the 
PDF. The distance between x ticks is bigger than that between y ticks. Notice 
that both _devices_ are square, but the plotting regions are not. This is 
because the margins remove 9.2 lines of text vertically but 6.2 lines 
horizontally. Consequentially, a difference in font size causes a difference in 
aspect ratio.

plot() has an asp= parameter   

-pd

> 
> http://pj.freefaculty.org/scraps/testSymbols.R
> 
>> sessionInfo()
> R version 2.15.1 (2012-06-22)
> Platform: x86_64-pc-linux-gnu (64-bit)
> 
> locale:
> [1] LC_CTYPE=en_US.UTF-8   LC_NUMERIC=C
> [3] LC_TIME=en_US.UTF-8LC_COLLATE=en_US.UTF-8
> [5] LC_MONETARY=en_US.UTF-8LC_MESSAGES=en_US.UTF-8
> [7] LC_PAPER=C LC_NAME=C
> [9] LC_ADDRESS=C   LC_TELEPHONE=C
> [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
> 
> attached base packages:
> [1] stats graphics  grDevices utils datasets  methods   base
> 
> 
> ## Paul Johnson 
> ## 2012-08-10
> ##
> ## I've got trouble with a mis-match between screen and pdf devices.
> ## Please run this and tell me if the point z's "marker" is on the
> ## intersection of the 2 circles for you.
> 
> ## Why do I ask? On my Dell M4600 laptop, the marker (the pch=12) is
> ## on the intersection in the x11 device. See the screenshot:
> ##
> ## http://pj.freefaculty.org/scraps/testSymbol-01.png
> ##
> ## But the pdf output of same is not
> ##
> ## http://pj.freefaculty.org/scraps/testSymbol.pdf
> ##
> ## Notice one other weird thing. The circle sizes change. Maybe
> ## that's just the same weird thing.
> 
> ## The X11 device is 7in x 7in. Right? Same as pdf.
> ## Why would coordinates from locator work in one display, but not the
> ## other?  I've abused the symbols function somehow? locator is device
> ## dependant?
> 
> ## Maybe its the video driver & LCD.
> ## This is a Dell Precision M4600. The LCD display is 13.6 inches x
> ## 7.6 inches (345.4mm x 193mm). By my reckoning, it is not precisely
> ## 16:9.  The Nvidia card says the native resolution is 1920x1080,
> ## which is exactly 16:9.
> 
> 
> 
> 
> saveFile <- FALSE
> if(saveFile){
> pdf(file="testSymbol.pdf", onefile=FALSE, paper="special", height = 7,
> width = 7)
> }
> 
> plot(c(0,1), c(0,1), type = "n", xlab = "", ylab = "")
> 
> 
> x <- c(0.3, 0.3)
> y <- c(0.7, 0.7)
> points(x[1], x[2])
> points(y[1], y[2])
> 
> symbols(x[1], x[2], circles=c(0.3), lty=2, inches = FALSE, add=TRUE)
> 
> symbols(y[1], y[2], circles=c(0.3), lty=2, inches = FALSE, add=TRUE)
> 
> ##Here's what I get from locator(1) on the intersection
> z <- list(x=0.4028, y=0.6485)
> if (is.null(z)) z <- locator(1) ## click on intersection of lines
> 
> 
> points(z, pch=12)
> text(x =0.96*z[[1]], y = 1.05*z[[2]], label="z")
> 
> dev.off()
> 
> 
> 
> 
> -- 
> Paul E. Johnson
> Professor, Political ScienceAssoc. Director
> 1541 Lilac Lane, Room 504 Center for Research Methods
> University of Kansas   University of Kansas
> http://pj.freefaculty.orghttp://quant.ku.edu
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

-- 
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Email: pd@cbs.dk  Priv: pda...@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.