[R] drawing hmms

2009-07-09 Thread rajesh j
Hi,

I need to draw hmm's in R.I also need to include a small plot near each
state of the hmm.How can I do this?

-- 
Rajesh.J

[[alternative HTML version deleted]]

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


Re: [R] how to transpose a dataframe

2009-07-09 Thread milton ruser
Hi roachyang,

you need to be more precise on your email.
But believe that you tryed one of the funtions like reshape or transform and
the output has been printed on your R session. If your dataset are large, is
better you assign your output on a object - like myobj<-reshape(...) - and
then save your table using write.table()... our explore your dataset using
head() or tail().
Bests

milton

On Thu, Jul 9, 2009 at 11:21 PM, roachyang  wrote:

>
> Seems like this is the one. But I got this message
> "reached getOption("max.print") -- omitted 12259 rows",
> and there are some data missing. What happened?
>
>
> Bill.Venables wrote:
> >
> > Look at the 'reshape' package, with functions melt() and cast()
> >
> > (I'm not sure how the remark about the virtues of SAS is relevant, but if
> > you really want SAS, I presume you know where to find it.)
> > 
> > From: r-help-boun...@r-project.org [r-help-boun...@r-project.org] On
> > Behalf Of roachyang [roachy...@gmail.com]
> > Sent: 10 July 2009 11:31
> > To: r-help@r-project.org
> > Subject: [R]  how to transpose a dataframe
> >
> > I want to transpose a dataframe like
> >   level   2006   2007   2008
> > A   
> > B  .
> > C
> > into
> >   levelyear
> > A  2006
> > A  2007
> > A  2008
> > B  2006
> > B  2007
> >..
> > There is a procedure in SAS can do this, is there any function in R can
> do
> > this?
> >
> > --
> > View this message in context:
> >
> http://www.nabble.com/how-to-transpose-a-dataframe-tp24420450p24420450.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.
> >
> >
>
> --
> View this message in context:
> http://www.nabble.com/how-to-transpose-a-dataframe-tp24420450p24421173.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.


[R] Problem loading ReadImages package (and RGooglemaps)

2009-07-09 Thread Paul.Rustomji
Hello All

I have just tried to install the ReadImages packge in R but am getting an error 
message stating:

"This application has failedt to start because jpeg62.dll was not found.  
Re-installing the application may fix this problem"

and at the R prompt this error message gets returned:

> local({pkg <- select.list(sort(.packages(all.available = TRUE)))
+ if(nchar(pkg)) library(pkg, character.only=TRUE)})
Error in inDL(x, as.logical(local), as.logical(now), ...) : 
  unable to load shared library 
'C:/PROGRA~1/R/R-29~1.1/library/ReadImages/libs/ReadImages.dll':
  LoadLibrary failure:  The specified module could not be found. 
Error in library(pkg, character.only = TRUE) : 
  .First.lib failed for 'ReadImages'

The .dll file that it is trying to find (in this case ReadImages.dll) does seem 
to be in the indicated directory (though I am not sure the abbreviated path 
isn't causing problems here...)


#R session info is here:
> sessionInfo()
R version 2.9.1 (2009-06-26) 
i386-pc-mingw32 

locale:
LC_COLLATE=English_Australia.1252;LC_CTYPE=English_Australia.1252;LC_MONETARY=English_Australia.1252;LC_NUMERIC=C;LC_TIME=English_Australia.1252

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

loaded via a namespace (and not attached):
[1] tools_2.9.1

Any ideas?

Paul Rustomji

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


[R] how to create 3d graph w/ spherical coordinates?

2009-07-09 Thread Buzz Buzzerr
Are there any R-routines/packages that will do 3d graphics for data in 
spherical coordinates?  I have had no luck with Google searches.  Thanks in 
advance for your reply.   Buz

[[alternative HTML version deleted]]

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


Re: [R] how to transpose a dataframe

2009-07-09 Thread roachyang

Seems like this is the one, though I'm not sure how to use it.


Bill.Venables wrote:
> 
> Look at the 'reshape' package, with functions melt() and cast()
> 
> (I'm not sure how the remark about the virtues of SAS is relevant, but if
> you really want SAS, I presume you know where to find it.)
> 
> From: r-help-boun...@r-project.org [r-help-boun...@r-project.org] On
> Behalf Of roachyang [roachy...@gmail.com]
> Sent: 10 July 2009 11:31
> To: r-help@r-project.org
> Subject: [R]  how to transpose a dataframe
> 
> I want to transpose a dataframe like
>   level   2006   2007   2008
> A   
> B  .
> C
> into
>   levelyear
> A  2006
> A  2007
> A  2008
> B  2006
> B  2007
>..
> There is a procedure in SAS can do this, is there any function in R can do
> this?
> 
> --
> View this message in context:
> http://www.nabble.com/how-to-transpose-a-dataframe-tp24420450p24420450.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.
> 
> 

-- 
View this message in context: 
http://www.nabble.com/how-to-transpose-a-dataframe-tp24420450p24421173.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] pcaNNet confusion

2009-07-09 Thread matsumotoN

Hi. Can anyone suggest how to use the output of pcaNNet() to construct a
confusion matrix possibly using 
confusionMatrix()?
Thank you.
-- 
View this message in context: 
http://www.nabble.com/pcaNNet-confusion-tp24422000p24422000.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] How to Populate List

2009-07-09 Thread Gaurav Kumar
Hi Rolf,

My apologies for the inconvenience caused  due to  my reply @ "R-help diges".
Thanks for providing me a clue to solve the problem .

I modify a bit to  populate a list. This is throwing an error
# Error in `*tmp*`[[j]] : subscript out of bounds" 

myData <- read.table("table.data",
 header=T,
 sep="\t",
 comment.char = "#"
 );
 inp <- scan("table.data", what=list(comp=" ", A="", B="", C=""));
 n <- c(0:length(inp$comp));
 myList=list();
 for(i in n-1)
 {
    if(i < length(inp$comp))
    {
        j=i+1;
        myList[[j]][1] <-c(as.numeric(myData$A[i]));
        myList[[j]][2] <-c(as.numeric(myData$B[i]));
        myList[[j]][2] <-c(as.numeric(myData$C[i]));
    }

 }
 print(myList);

Any idea where i'm doing a mistake which is causing this error.

Thanks in advance.
 
 regards
Gaurav Kumar

--- On Fri, 10/7/09, Rolf Turner  wrote:

From: Rolf Turner 
Subject: Re: [R] How to Populate List
To: "gau...@gauravkumar.org" 
Cc: "r-help@r-project.org" 
Date: Friday, 10 July, 2009, 1:39 AM


On 10/07/2009, at 2:55 AM, Gaurav Kumar wrote:

> Hi,
> 
> I'm new to R and would like to know, how one can populate the list with array 
> data.
> I'm reading a tab separated table in R. The data in the table looks something 
> like this.
> 
> #Table Data
> Comp    A    B    C
> Extracellular    103    268    535759
> Nucleus    45603    47783    442744
> 
> #R code
> myData <- read.table("table.data",
>                 header=T,
>                 sep="\t",
>                 comment.char = "#"
>                 );
> inp <- scan("table.data", what=list(comp=" ", A="", B="", C=""));
> n <- c(0:length(inp$comp));
> myList=list();
> for(i in n-1)
> {
>     obj 
><-c(as.numeric(myData$A[i]),as.numeric(myData$B[i]),as.numeric(myData$C[i]));
> 
> }
> 
> Need help to know if there is any function in R to push obj to myList

(a) You apparently ``replied'' to an R-help digest, and included megabytes
of totally irrelevant material in your post.  It took me several minutes to 
delete it.

STEP ONE:  LEARN HOW TO USE EMAIL!!!

(b) Do the following:

myList <- list();
for(i in n-1)
{
    myList[[i]] 
<-c(as.numeric(myData$A[i]),as.numeric(myData$B[i]),as.numeric(myData$C[i]));

}

    cheers,

        Rolf Turner

##
Attention:This e-mail message is privileged and confidential. If you are not 
theintended recipient please delete the message and notify the sender.Any views 
or opinions presented are solely those of the author.

This e-mail has been scanned and cleared by MailMarshalwww.marshalsoftware.com
##

[[alternative HTML version deleted]]

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


Re: [R] 'scan' in a script?

2009-07-09 Thread Daniel Nordlund
> -Original Message-
> From: r-help-boun...@r-project.org 
> [mailto:r-help-boun...@r-project.org] On Behalf Of Mark Knecht
> Sent: Thursday, July 09, 2009 9:35 PM
> To: jim holtman
> Cc: r-help
> Subject: Re: [R] 'scan' in a script?
> 
> On Thu, Jul 9, 2009 at 6:05 PM, jim holtman wrote:
> > If you want the value printed in the script, then use the 
> 'print' function:
> >
> > print(MyNames)
> >
> > There is an implicit 'print' when you type an object's name at the
> > command line, but with you have it within a script, you have to
> > explicitly print it.
> >
> 
> 
> That's good to know in terms of reliably getting the data out but my
> bigger problem right now is it doesn't wait for me to type any input
> and therefore my program (running as a script) doesn't know what to
> do.
> 
> I guess this must be me doing somethign jsut plain wrong. I figured
> I'd ask and get an answer in 30 seconds. Strange I'm that far off. If
> I need to run it in the interpreter instead of source it then for now
> I can do that until I learn what I'm doing wrong.
> 
> I've got more interesting questions of which the answers are far more
> important to me than this one!
> 
> Thanks,
> Mark

Mark,

Take a look at the readline() function.

Hope this is helpful,

Dan

Daniel Nordlund
Bothell, WA USA

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


Re: [R] naming of columns in R dataframe consisting of mixed data (alphanumeric and numeric)

2009-07-09 Thread Moshe Olshansky

Hi Mary,

Your data.frame has just one column (not 2)! You can check this by 
dim(tresult2).
What appears to you to be the first column (names) are indeed rownames.
If you really want to have two columns do something like 
tresult2 <- cbind(colnames(tresult),data.frame(t(tresult),row.names=NULL))
Now tresult2 contains 2 columns and you can proceed with  
names(tresults2)<-c("Statistic ", "Value")

--- On Fri, 10/7/09, Mary A. Marion  wrote:

> From: Mary A. Marion 
> Subject: [R] naming of columns in R dataframe consisting of mixed data 
> (alphanumeric and numeric)
> To: r-help@r-project.org
> Received: Friday, 10 July, 2009, 3:50 AM
> Hello,
> 
> I have an r function that creates the following dataframe
> tresults2.
> Notice that column 1 does not have a column heading.
> 
> Tresults2:
>              
>    [,1]
> estparam     18.0
> nullval      20.0
> . . .
> ciWidth       2.04622
> HalfInterval  1.02311
> 
> pertinent code:
> results<-cbind( estparam, nullval, t, pv_left, pv_right,
> pv_two_t, 
> estse, df,  cc, tbox, llim, ulim, ciWidth,
> HalfInterval)
> tresults<-round((results),5)
> tresults2<-data.frame(t(tresults))
> names(tresults2)<-c("Statistic ", "Value")
> tresults2
> 
> ===
> After transposing my dataframe tresults2 consists of 2
> columns.  
> Col1=alphanumeric data (this really is a variable name)
> and
> col2=numeric data (this is value of varaiable).
> 
> how do I name columns when columns are different
> (alphanumeric and numeric)
> to avoid the following error:
> 
> Error in names(tresults2) <- c("Statistic ", "Value") :
>   'names' attribute [2] must be the same length as the
> vector [1]
> 
> Am I to use c( , ) or list( , ) with a dataframe?
> 
> Thank you for your help.
> Sincerely,
> Mary A. Marion
> 
> 
> 
> 
> 
>     [[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] 'scan' in a script?

2009-07-09 Thread Mark Knecht
On Thu, Jul 9, 2009 at 6:05 PM, jim holtman wrote:
> If you want the value printed in the script, then use the 'print' function:
>
> print(MyNames)
>
> There is an implicit 'print' when you type an object's name at the
> command line, but with you have it within a script, you have to
> explicitly print it.
>


That's good to know in terms of reliably getting the data out but my
bigger problem right now is it doesn't wait for me to type any input
and therefore my program (running as a script) doesn't know what to
do.

I guess this must be me doing somethign jsut plain wrong. I figured
I'd ask and get an answer in 30 seconds. Strange I'm that far off. If
I need to run it in the interpreter instead of source it then for now
I can do that until I learn what I'm doing wrong.

I've got more interesting questions of which the answers are far more
important to me than this one!

Thanks,
Mark

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

2009-07-09 Thread Victor Manuel Garcia Guerrero
Wonderful!!! It works!!! Thank you very much Daniel. I owe you one.
 
Cheers
 
Victor



De: Daniel Malter [mailto:dan...@umd.edu]
Enviado el: jue 09/07/2009 10:44
Para: Victor Manuel Garcia Guerrero; r-help@r-project.org
Asunto: AW: [R] Population pyramids




Victor, use the axes=FALSE option, as you do. Then use the "labels" and "at"
options in the "axis" argument to place the tickmark labels in the negative
plot manually


par(mfrow=c(1,2),bty="n",mai=c(0.5, 0.25, 0.25, 0.25))

x=rgamma(1000,10,0.3)

barplot(height=t(-x), width = 0.825, space = NULL,
names.arg = NULL, legend.text = c("Inf 95%","Mediana","Sup 95%"),
beside = FALSE,
horiz = TRUE, density = NULL, angle = 0,
axes = FALSE,
col = c("yellow","Blue","orange"), border = par("fg"),
main = "Mujeres",
xlim =NULL, ylim = NULL, xpd = TRUE, log = "",
axisnames = FALSE,

axis(1,hadj=NA,padj=NA,cex.axis=0.75,labels=c("0","10","20","30","40","50","
60","70"),at=c(0,-10,-20,-30,-40,-50,-60,-70)))


barplot(height=t(x), width = 0.825, space = NULL,
names.arg = NULL, legend.text = c("Inf 95%","Mediana","Sup 95%"),
beside = FALSE,
axes=FALSE,
horiz = TRUE, density = NULL, angle = 0,
col = c("yellow","Blue","orange"), border = par("fg"),
main = "Mujeres",
xlim =NULL, ylim = NULL, xpd = TRUE, log = "",
axisnames = FALSE,
axis(1,cex.axis=0.75))

That should do. Best,
Daniel   


-
cuncta stricte discussurus
-

-Ursprüngliche Nachricht-
Von: Victor Manuel Garcia Guerrero [mailto:vmgar...@colmex.mx]
Gesendet: Thursday, July 09, 2009 1:44 AM
An: Daniel Malter; r-help@r-project.org
Betreff: RE: [R] Population pyramids

Yes the code is the next:

par(mfrow=c(1,2),bty="n",mai=c(0.5, 0.25, 0.25, 0.25))

barplot(height=t(icNM2005.dat), width = 0.825, space = NULL,
names.arg = NULL, legend.text = NULL, beside = FALSE,
horiz = TRUE, density = NULL, angle = 0,
col = c("yellow","Blue","orange"), border = par("fg"),
main = "Hombres",
xlim =NULL, ylim = NULL, xpd = TRUE, log = "",
axes = FALSE, axisnames = FALSE,cex.axis=0.75)
axis(1,pretty(c(-1200,0),n=12),
hadj=NA,padj=NA,cex.axis=0.75,las=2)


barplot(height=t(icNF2005.dat), width = 0.825, space = NULL,
names.arg = NULL, legend.text = c("Inf 95%","Mediana","Sup 95%"),
beside = FALSE,
horiz = TRUE, density = NULL, angle = 0,
col = c("yellow","Blue","orange"), border = par("fg"),
main = "Mujeres",
xlim =NULL, ylim = NULL, xpd = TRUE, log = "",
axes = FALSE, axisnames = FALSE,cex.axis=0.75)
axis(2,pretty(c(0:105),n=21),hadj=0.5,padj=0.5,cex.axis=0.75,
las=2)
axis(1,pretty(c(0:1200),n=5),
hadj=NA,padj=NA,cex.axis=0.5,las=1)
   

Víctor Manuel García Guerrero
Doctorado en Estudios de Población,
CEDUA, COLMEX
Camino al Ajusco N° 20, Pedregal de Sta. Teresa C.P.10740, Tlalpan, México,
D.F.
* : vmgar...@colmex.mx
( : 5617-9016



-Mensaje original-
De: Daniel Malter [mailto:dan...@umd.edu] Enviado el: jue 09/07/2009 12:15
Para: Victor Manuel Garcia Guerrero; r-help@r-project.org
Asunto: AW: [R] Population pyramids

Can you provide a self-contained example of what you did so far (i.e. code
for simulating some data and code for the plot)? That would greatly help to
help you find a solution.

Daniel


-
cuncta stricte discussurus
-

-Ursprüngliche Nachricht-
Von: Victor Manuel Garcia Guerrero [mailto:vmgar...@colmex.mx]
Gesendet: Thursday, July 09, 2009 12:48 AM
An: Daniel Malter; r-help@r-project.org
Betreff: RE: [R] Population pyramids

Yes, but my issue is because I need to plot a pop pyramid with confidence
intervals, and the pyramid function does not work in that way. Thanks
Daniel.


-Mensaje original-
De: Daniel Malter [mailto:dan...@umd.edu] Enviado el: mié 08/07/2009 11:36
Para: Victor Manuel Garcia Guerrero; r-help@r-project.org
Asunto: AW: [R] Population pyramids

have you tried the pyramid function in the epicalc package?

best,
daniel


-
cuncta stricte discussurus
-

-Ursprüngliche Nachricht-
Von: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] Im
Auftrag von Victor Manuel Garcia Guerrero
Gesendet: Thursday, July 09, 2009 12:25 AM
An: r-help@r-project.org
Betreff: [R] Population pyramids

Hi, I hope somebody can help me with this issue: I am doing population
pyramids using the barplot command, so in the left side I have male age
structure and in the right side the female age structure. To plot the male
age structure I put the data in negative numbers. Now, I want to change the
sign in the bar plot in such way that I have no-sign numbers, both in left
and right side of the graph. I have been trying

Re: [R] Population pyramids

2009-07-09 Thread Victor Manuel Garcia Guerrero
Thanks Jim, I'll try it and I'll keep you informed.
 
All the best,
 
Victor
 


De: Jim Lemon [mailto:j...@bitwrit.com.au]
Enviado el: jue 09/07/2009 05:54
Para: Victor Manuel Garcia Guerrero
CC: r-help@r-project.org
Asunto: Re: [R] Population pyramids



Victor Manuel Garcia Guerrero wrote:
> Hi, I hope somebody can help me with this issue: I am doing population 
> pyramids using the barplot command, so in the left side I have male age 
> structure and in the right side the female age structure. To plot the male 
> age structure I put the data in negative numbers. Now, I want to change the 
> sign in the bar plot in such way that I have no-sign numbers, both in left 
> and right side of the graph. I have been trying all day long and I could not 
> succed.
>
>  
Hi Victor,
I can get part of the way there with pyramid.plot and plotCI, but it
would take some concentrated hacking to do it properly. If you can't
find another solution, let me know.

Jim

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


[R] error: optim(rho, n2ll.rho, method = method, control = control, beta = parm$beta, : initial value in 'vmmin' is not finite

2009-07-09 Thread Brandy Lee Aven
I am trying to use the lnam autocorrelation model from the SNA package. I have 
it running for smaller adjacency matrices (<1,500) it works just fine but when 
my matrices are bigger 4000+. I get the error: 

> lnam1_01.adj<- lnam(data01$adopt,x01,ec2001.csr)
Error in optim(rho, n2ll.rho, method = method, control = control, beta = 
parm$beta,  : 
  initial value in 'vmmin' is not finite


I have looked at the lnam code and cant even figure out what vmmin is. 
Is there anyway around this? Am I doing something wrong? What makes me think 
that its about the size of the adjacency matrix is that I can run the same 
command on similar objects that are just smaller and it works fine. 

please help!

>sessionInfo()
R version 2.9.1 (2009-06-26) 
x86_64-pc-linux-gnu 

locale:
C

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

other attached packages:
[1] numDeriv_2009.2-1 sna_2.0-1

loaded via a namespace (and not attached):
[1] tools_2.9.1

> class(data01$adopt) #This is the response vector y
[1] "integer"

>data01$adopt[1:10] # Its just a binary outcome for all vertices
[1] 0 0 0 0 0 0 0 0 0 0 ..until 4,003

> class(x01) #X01 is a matrix of my six covariates for all vertices 
>  
[1] "matrix"

#here is the an example of the data
>x01[1:10,1:6]
on01 indegree outdegree between eigen numalters01
1   1   0   0   0   1   1
19  1   0   1   0   0   1
123 1   0   1   0   0   1
140 1   0   1   0   0   1
169 1   0   1   0   0   1
189 1   0   1   0   0   1
195 1   0   1   0   0   2
204 1   0   1   0   0   1
231 1   0   2   0   0   1
252 1   0   3   0   0   4

# this is the adjacency matrix (in Sparse matrix format) that causes the error. 
I have another that is 10,500 and does the same thing.
>dim(ec2001.csr) 
[1] 4003 4003

>class(ec2001.csr)
[1] "matrix.csr"
attr(,"package")
[1] "SparseM"

>ec2001.csr[1:10,1:10] #here is what it looks like
1 19 123 140 169 189 195 204 231 252
1   1  0   0   0   0   0   0   0   0   0
19  0  0   0   1   0   0   0   0   0   0
123 0  0   0   0   0   0   0   0   0   0
140 0  0   0   0   0   0   0   0   0   0
169 0  0   0   0   0   0   0   0   0   0
189 0  0   1   0   0   0   0   0   0   0
195 0  0   0   0   0   0   0   0   0   0
204 0  0   0   0   0   0   0   0   0   0
231 0  0   0   0   0   0   0   0   0   0
252 0  0   0   0   0   0   0   0   0   0


#There are also no infinite values in the objects. 
>is.infinite(x01)
[1] FALSE . N

>is.infinite(data01$adopt)
[1] FALSE .N

>is.infinite(ec2001.csr)
[1] FALSE

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 get function from lm object?

2009-07-09 Thread Marc Schwartz

On Jul 9, 2009, at 8:20 PM, Alexander V Stolpovsky wrote:

Thank you much for the useful pointers. Turns out, I can get what I  
want with predict(fit, newdata = newdata). But for the record, there  
is no way to get the fit function, from lm object, is there?

 Alex


Alex,

There is no function returned within the model object.

You can review the structure of the returned model object by using:

  str(fit)

HTH,

Marc Schwartz

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 transpose a dataframe

2009-07-09 Thread Bill.Venables
Look at the 'reshape' package, with functions melt() and cast()

(I'm not sure how the remark about the virtues of SAS is relevant, but if you 
really want SAS, I presume you know where to find it.)

From: r-help-boun...@r-project.org [r-help-boun...@r-project.org] On Behalf Of 
roachyang [roachy...@gmail.com]
Sent: 10 July 2009 11:31
To: r-help@r-project.org
Subject: [R]  how to transpose a dataframe

I want to transpose a dataframe like
  level   2006   2007   2008
A   
B  .
C
into
  levelyear
A  2006
A  2007
A  2008
B  2006
B  2007
   ..
There is a procedure in SAS can do this, is there any function in R can do
this?

--
View this message in context: 
http://www.nabble.com/how-to-transpose-a-dataframe-tp24420450p24420450.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] how to transpose a dataframe

2009-07-09 Thread Henrique Dallazuanna
try this:

transform(stack(DF, select = -level), values = DF$level)

On Thu, Jul 9, 2009 at 10:30 PM, roachyang  wrote:

>
> I want to transpose a dataframe like
>  level   2006   2007   2008
>A   
>B  .
>C
> into
>  levelyear
>A  2006
>A  2007
>A  2008
>B  2006
>..
> There is a procedure in SAS can do this, is there any function in R can do
> this?
>
> --
> View this message in context:
> http://www.nabble.com/how-to-transpose-a-dataframe-tp24420450p24420450.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.
>



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

[[alternative HTML version deleted]]

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


Re: [R] how to transpose a dataframe

2009-07-09 Thread milton ruser
Hi there,

?reshape do the job.

bests
milton

On Thu, Jul 9, 2009 at 9:31 PM, roachyang  wrote:

>
> I want to transpose a dataframe like
>  level   2006   2007   2008
>A   
>B  .
>C
> into
>  levelyear
>A  2006
>A  2007
>A  2008
>B  2006
>B  2007
>   ..
> There is a procedure in SAS can do this, is there any function in R can do
> this?
>
> --
> View this message in context:
> http://www.nabble.com/how-to-transpose-a-dataframe-tp24420450p24420450.html
> Sent from the R help mailing list archive at Nabble.com.
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

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


Re: [R] how to transpose a dataframe

2009-07-09 Thread Rolf Turner


On 10/07/2009, at 1:31 PM, roachyang wrote:



I want to transpose a dataframe like
  level   2006   2007   2008
A   
B  .
C
into
  levelyear
A  2006
A  2007
A  2008
B  2006
B  2007
   ..
There is a procedure in SAS can do this, is there any function in R  
can do

this?


(a) ***Anything*** can be done in R; if there isn't a function to do it,
you can write one.

(b) ``Transpose'' is ***NOT*** the right word.  You probably mean  
``transform''.


(c) See ?reshape.

cheers,

Rolf Turner

##
Attention:\ This e-mail message is privileged and confid...{{dropped:9}}

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] file.copy returning "FALSE"?

2009-07-09 Thread Duncan Murdoch

On 09/07/2009 9:53 PM, Jonathan Greenberg wrote:

I'm running the command:

file.copy(fnhdr,outdir,overwrite=TRUE)

Which successfully copies the file I want to the directory I want, but 
each time it prints "FALSE" -- what does this mean, and how do I 
suppress this output?


It means the operation failed.  Suppressing the output is easy, but it 
probably makes more sense to try to figure out why R thinks it failed 
and you think it didn't.  R will report that if it can't open the source 
or destination file, or if the file size of the destination file after 
copying is different than the size of the source file.


Duncan Murdoch

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


Re: [R] corspatial

2009-07-09 Thread Kingsford Jones
On Thu, Jul 9, 2009 at 6:12 PM, Kitty Lee wrote:
>
> Hi. I have a dataset of unique coordinates (no missing coordinates). When I 
> did the following:
>
> lonlat<-mydata[, c("lon, "lat")]
> sp1<-corSpatial(1,form=~lon+lat,type="g")
> scor<-Initialize(sp1, lonlat , nugget=FALSE)
>
> I got a value for sp1 (2.67). But got an error message for scor--Error in 
> getCovariate.corSpatial(object, data = data) :
>  Cannot have zero distances in "corSpatial"
>
> I find that puzzling since I have unique coordinates and there should not be 
> any zero distances. Any idea?

The error does suggest the function thinks there are duplicates in
lonlat.  Have you tried, for example, sum(duplicated(lonlat))?  Or you
could add a small amount of random noise to one of the coordinates and
then see if Initialize will run...


hth,
Kingsford Jones

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

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


Re: [R] How to get function from lm object?

2009-07-09 Thread Alexander V Stolpovsky
Thank you much for the useful pointers. Turns out, I can get what I want with 
predict(fit, newdata = newdata). But for the record, there is no way to get the 
fit function, from lm object, is there?
  Alex


-
This transmission may contain information that is privileged,
confidential, legally privileged, and/or exempt from disclosure
under applicable law.  If you are not the intended recipient, you
are hereby notified that any disclosure, copying, distribution, or
use of the information contained herein (including any reliance
thereon) is STRICTLY PROHIBITED.  Although this transmission and
any attachments are believed to be free of any virus or other
defect that might affect any computer system into which it is
received and opened, it is the responsibility of the recipient to
ensure that it is virus free and no responsibility is accepted by
JPMorgan Chase & Co., its subsidiaries and affiliates, as
applicable, for any loss or damage arising in any way from its use.
 If you received this transmission in error, please immediately
contact the sender and destroy the material in its entirety,
whether in electronic or hard copy format. Thank you.

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


[R] how to transpose a dataframe

2009-07-09 Thread roachyang

I want to transpose a dataframe like
  level   2006   2007   2008
A   
B  .
C
into 
  levelyear
A  2006
A  2007
A  2008
B  2006
B  2007
   ..
There is a procedure in SAS can do this, is there any function in R can do
this?  

-- 
View this message in context: 
http://www.nabble.com/how-to-transpose-a-dataframe-tp24420450p24420450.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] file.copy returning "FALSE"?

2009-07-09 Thread Jonathan Greenberg

I'm running the command:

   file.copy(fnhdr,outdir,overwrite=TRUE)

Which successfully copies the file I want to the directory I want, but 
each time it prints "FALSE" -- what does this mean, and how do I 
suppress this output?


--j

--

Jonathan A. Greenberg, PhD
Postdoctoral Scholar
Center for Spatial Technologies and Remote Sensing (CSTARS)
University of California, Davis
One Shields Avenue
The Barn, Room 250N
Davis, CA 95616
Cell: 415-794-5043
AIM: jgrn307, MSN: jgrn...@hotmail.com, Gchat: jgrn307

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Clustering within part of a cluster result

2009-07-09 Thread Albert Vernon Smith
How can I cluster and order within part of a previous clustering result?

For example, I am clustering and ordering results as follows:

> rows <- 30
> cols <- 3
> x <- matrix(sample(-1:1,rows*cols,replace=T), nrow=rows, 
> ncol=cols,dimnames=list(c(paste("R",1:rows,sep="")),c(paste("C",1:cols,sep=""
> x
C1 C2 C3
R1   0  1  1
R2   0 -1  1
R3  -1  1  0
R4  -1  0  1
R5   0 -1  0
R6  -1 -1  1
R7  -1 -1 -1
R8  -1 -1  0
...
> hc <- hclust(dist(x, method = "binary"),method="single")
> hc <- as.dendrogram(hc)
> ord.hc <- order.dendrogram(hc)
> xc <- x[rev(ord.hc),]
> xc
C1 C2 C3
R7  -1 -1 -1
R6  -1 -1  1
R9   1 -1  1
R11  1  1 -1
R12 -1 -1 -1
R16 -1 -1  1
R18 -1 -1 -1
R24  1 -1 -1
R27 -1 -1  1
R2   0 -1  1
R1   0  1  1
R10  0 -1 -1
...
>

Given the binary distance I am using, the first nine rows all have a
distance of 0 to one another.  How can I sort again within certain
nodes to bring those which are closer together.  In the example above,
I'd like some sort of cluster within the first 9 rows so that "R7",
"R12", and "R18" are together, as they are all -1,-1,-1, and
R6/R16/R27, etc.

How might I go about that?

Thanks,
-albert

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

2009-07-09 Thread Fabio Luciani

Hello

I am having problems with the function
rateratio in epitools

I getthe following error

Error in ratetable(x, rev = rev) :
  All arguments to ratetable() must be the same length

I checked that x is a 2x2 matrix. any idea?

thanks


Fabio
Fabio Luciani
Postdoctoral NHMRC research fellow
Centre for Infection and Inflammation Research (CIIR),
School of Medical Sciences,
University of New South Wales,
Sydney, NSW 2052 Australia
Tel +61 2 93853838

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] 'scan' in a script?

2009-07-09 Thread jim holtman
If you want the value printed in the script, then use the 'print' function:

print(MyNames)

There is an implicit 'print' when you type an object's name at the
command line, but with you have it within a script, you have to
explicitly print it.

On Thu, Jul 9, 2009 at 5:08 PM, Mark Knecht wrote:
> Jim,
>   In Rgui there is a feature to create a new script so I open that
> and get a blank editor. I put these commands in the script
>
> MyNames = scan(what="")
> MyNames
>
>   Whether I ask Rgui to run the whole script as a script - not
> sourced - it runs the first command, doesn't wait for input and then
> runs the second command. I see
>
>> MyNames
> character(0)
>>
>
>   If I right click the first line and ask it to run the selection or
> line then R waits for the input.
>
>   If I source the file then the opposite happens. It does the scan
> correctly, waiting for me to make entries. When I finish it doesn't
> print what's in MyNames, as shown here where I typed in happy sad test
> go and hit enter.
>
>> source("C:\\Users\\Mark\\Documents\\R\\Test Cases\\scan from script.R")
> 1: happy sad test go
> 5:
> Read 4 items
>>
>
>   Possibly (probably!) this is a misunderstanding on my part, but
> it's something I need to start looking at as the reason for me
> checking out R at all was as a potential way to develop a complete
> program, as opposed to writing it in C, so I need to start looking at
> how to give it input (file names, directory paths, user requests)
> other than changing source code.
>
>   I hope this is clear enough and I appreciate your inputs.
>
> Cheers,
> Mark
>
> On Thu, Jul 9, 2009 at 1:02 PM, jim holtman wrote:
>> Exactly how are you using it?  How you executing your script?  Are you
>> using cut/paste or source?  Have you tried 'readline'?
>>
>> More details on what you mean by it does not work as expected.
>>
>> On Thu, Jul 9, 2009 at 2:24 PM, Mark Knecht wrote:
>>> When I use the scan function in the Rgui console it works as expected.
>>> However it seems that when I put the same command in a script file it
>>> doesn't wait for input.
>>>
>>> Is there an option to scan to make it wait for input when used in a
>>> script? Or is there possibly a different function that will do in a
>>> script the same sort of thing as scan does in the console?
>>>
>>> Thanks,
>>> Mark
>>>
>>> __
>>> R-help@r-project.org mailing list
>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>>> and provide commented, minimal, self-contained, reproducible code.
>>>
>>
>>
>>
>> --
>> Jim Holtman
>> Cincinnati, OH
>> +1 513 646 9390
>>
>> What is the problem that you are trying to solve?
>>
>



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

What is the problem that you are trying to solve?

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


[R] class export in package creation / setClass / namespace?

2009-07-09 Thread L L
Dear all,

I have been trying to create an R package. This has been successfull until I
tried to define classes.

Currently, my procedure is the following:

Start R, load the function and class definition
>tmp <- function (x) {x}
>setClass("rpa", contains = "list", where=topenv(parent.frame()))

Use package skeleton to create directory structure:
>package.skeleton(name = "test",list=c("tmp"))

Edit man files, add test/NAMESPACE file with the following contents:
>export(tmp)
>exportClasses("rpa")

Use R CMD check and R CMD build to create tarball.
-> No error messages.

Start R, install the created package:
>install.packages("test_1.0.tar.gz",repos=NULL)

Test the new package:
>require(test)
>my.object = new("rpa")

This gives the error message
>Error in getClass(Class, where = topenv(parent.frame())) :
> "rpa" is not a defined class

Any tips on how to define and export global classes in package creation?

I also tried
- to replace the 'topenv(parent.frame())' with '.GlobalEnv' in setClass.
- place the setClass within function 'tmp'
- exportClasses(rpa) in the namespace (without suffixes "")

I paged through the related mailing list discussions but could not find a
solution. Any tips and tricks would be worthwhile now; I guess this should
be a standard issue but it seems a bit tricky to come up with a quick
solution with the little programming experience that I have.

kind regards
Leo Lahti

[[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] Stratified data summaries

2009-07-09 Thread Dylan Beaudette
Hi, the plyr package is your friend.

Here is a tutorial on a related subject:

http://casoilresource.lawr.ucdavis.edu/drupal/node/836

cheers,
Dylan

On Thursday 09 July 2009, Hayes, Rachel M wrote:
> Hi All,
>
>
>
> I'm trying to automate a data summary using summary or describe from the
> HMisc package.  I want to stratify my data set by patient_type.  I was
> hoping to do something like:
>
>
>
> Describe(myDataFrame ~ patient_type)
>
>
>
> I can create data subsets and run the describe function one at a time,
> but there's got to be a better way.  Any suggestions?
>
>
>
> Rachel
>
>
>   [[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.



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

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


Re: [R] Substituting numerical values using `apply'

2009-07-09 Thread Moshe Olshansky

Let M be your matrix.

Do the following:

B <- t(matrix(colnames(a),nrow=ncol(M),ncol=nrow(M)))
B[M==0] <- NA

--- On Thu, 9/7/09, Olivella  wrote:

> From: Olivella 
> Subject: [R]  Substituting numerical values using `apply'
> To: r-help@r-project.org
> Received: Thursday, 9 July, 2009, 6:25 AM
> 
> Hello,
> 
> I wish to perform a substitution of certain numerical
> values in a data
> matrix with the corresponding column name. For instance, if
> I have a data
> matrix
> V1  V2  V3
> 2    0    1
> 0    1    2 
> 1    5    0
> 5    0    0 
> 
> I want to substitute the `1' and the `2' for the
> corresponding column name,
> and make everything else `NA' like this
> V1    V2    V3
> V1    NA    V3
> NA    V2    V3 
> V1    NA    NA
> NA    NA    NA 
> 
> I have done this using an explicit `for' loop, but it takes
> a really long
> time to finish. Is there any way I can do this using
> `apply' or some form of
> implicit looping?
> 
> Thank you for your help,
> 
> SO
> -- 
> View this message in context: 
> http://www.nabble.com/Substituting-numerical-values-using-%60apply%27-tp24398687p24398687.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] corspatial

2009-07-09 Thread Kitty Lee

Hi. I have a dataset of unique coordinates (no missing coordinates). When I did 
the following:

lonlat<-mydata[, c("lon, "lat")]
sp1<-corSpatial(1,form=~lon+lat,type="g")
scor<-Initialize(sp1, lonlat , nugget=FALSE) 

I got a value for sp1 (2.67). But got an error message for scor--Error in 
getCovariate.corSpatial(object, data = data) : 
  Cannot have zero distances in "corSpatial"

I find that puzzling since I have unique coordinates and there should not be 
any zero distances. Any idea?

Thanks!

K.

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


Re: [R] Strange t-test error: "grouping factor must have exactly 2 levels" while it does...

2009-07-09 Thread Marc Schwartz

On Jul 9, 2009, at 5:04 PM, Tymek W wrote:


Hi,

Could anyone tell me what is wrong:


length(unique(mydata$myvariable))

[1] 2




and in t-test:

(...)
Error in t.test.formula(othervariable ~ myvariable, mydata) :
 grouping factor must have exactly 2 levels




I re-checked the code and still don't get what is wrong.

Moreover, there is some strange behavior:

/1 It seems that the error is vulnerable to NA'a, because it affects
some variables in data set with NA's and doesn't affect same ones in
dataset with NA's removed.

/2 It seems it works differently with different ways of using
variables in t.test:

eg. it hapends here: t.test(x~y, dataset) and does not here:
t.test(dataset[['x']]~dataset[['y']])

Does anyone have any ideas?

Greetz,
Timo



Check the output of:

  na.omit(cbind(mydata$othervariable, mydata$myvariable))

which will give you some insight into what data is actually available  
to be used in the t test. This will remove any rows that have missing  
data. Your first test above, checking the number of levels, is before  
missing data is removed.


The likelihood is that once missing values have been removed, you are  
only left with one unique grouping value in mydata$myvariable.


For your note number 2, it should be the same for both examples, as in  
both cases, the same basic approach is used. For example:


DF <- data.frame(x = c(1:3, NA, NA, NA), y = rep(1:2, each = 3))

> DF
   x y
1  1 1
2  2 1
3  3 1
4 NA 2
5 NA 2
6 NA 2

# Remove missing data
> na.omit(DF)
  x y
1 1 1
2 2 1
3 3 1

> t.test(x ~ y, data = DF)
Error in t.test.formula(x ~ y, data = DF) :
  grouping factor must have exactly 2 levels

> t.test(DF$x ~ DF$y)
Error in t.test.formula(DF$x ~ DF$y) :
  grouping factor must have exactly 2 levels


If you have a small reproducible example where the two function calls  
behave differently, please post back with it.


HTH,

Marc Schwartz

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 get function from lm object?

2009-07-09 Thread Marc Schwartz

On Jul 9, 2009, at 6:18 PM, Alexander V Stolpovsky wrote:


Dear experts,

I am trying to obtain a function from a model, so that I could  
further manipulate it, plot it, etc. I can get model estimates and   
manually construct a function, but this gets tedious when trying out  
different functions to fit the data. There must be a better way of  
doing it, no?


x <- c(1:10)
y <- c(1:10)

fit <- lm(y ~ x)
f <- function(x){fit$coef[1] + fit$coef[2]*x}  # Manually  
constructing function
  # Would be nice to do  
something like this:

  # f<-getFunction(fit)
plot(f, 0, 10)

Thanks,
 Alex Stolpovsky


If you want to get the model fitted y values, just use:

  fitted(fit)

As an aside, to get the model coefficients, there is also:

  coef(fit)

and

  coef(summary(fit))

which like fitted(), is one of several 'extractor' functions that can  
be used on model object to get specific components.


If you want to generate model predicted y values based upon 'new' x  
values, use:


  newdata <- data.frame(x = YourNewValues)
  predict(fit, newdata = newdata)

Note that the 'newdata' data frame must contain columns with the SAME  
names as the independent variables in your original model.


See ?predict.lm for more information, which can also generate various  
intervals, etc.


If you want to plot your original data in a scatterplot and then add  
the model fitted line, use:


  plot(x, y)
  abline(fit)

See ?abline for more information there.

BTW, much of this is covered in An Introduction to R, which is  
included in your R installation and on the main R web site under  
Manuals link.


HTH,

Marc Schwartz

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 combine two rows (in a dataframe) into a third row?

2009-07-09 Thread Henrique Dallazuanna
Try this:

aggregate(x["VALUE"], list(substr(x[,"ID"], 1, 1)), sum)

On Thu, Jul 9, 2009 at 7:27 PM, Mark Na  wrote:

> Dear R-helpers,
>
> I have two rows in my dataframe:
>
> IDVALUE
> 1A10
> 1B15
>
> and I would like to combine these two rows into a single (new) row in my
> dataframe:
>
> IDVALUE
> 125
>
> ...simply by specifying a new value for ID and summing the two VALUES.
>
> I have been trying to do this with with rbind, but it's not working.
>
> I'd appreciate any pointers.
>
> Thanks, Mark Na
>
>[[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



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

[[alternative HTML version deleted]]

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


[R] How to get function from lm object?

2009-07-09 Thread Alexander V Stolpovsky
Dear experts,

I am trying to obtain a function from a model, so that I could further 
manipulate it, plot it, etc. I can get model estimates and  manually construct 
a function, but this gets tedious when trying out different functions to fit 
the data. There must be a better way of doing it, no?

x <- c(1:10)
y <- c(1:10)

fit <- lm(y ~ x)
f <- function(x){fit$coef[1] + fit$coef[2]*x}  # Manually constructing function
   # Would be nice to do something 
like this:
   # f<-getFunction(fit)
plot(f, 0, 10)

Thanks,
  Alex Stolpovsky



-
This transmission may contain information that is privileged,
confidential, legally privileged, and/or exempt from disclosure
under applicable law.  If you are not the intended recipient, you
are hereby notified that any disclosure, copying, distribution, or
use of the information contained herein (including any reliance
thereon) is STRICTLY PROHIBITED.  Although this transmission and
any attachments are believed to be free of any virus or other
defect that might affect any computer system into which it is
received and opened, it is the responsibility of the recipient to
ensure that it is virus free and no responsibility is accepted by
JPMorgan Chase & Co., its subsidiaries and affiliates, as
applicable, for any loss or damage arising in any way from its use.
 If you received this transmission in error, please immediately
contact the sender and destroy the material in its entirety,
whether in electronic or hard copy format. Thank you.
[[alternative HTML version deleted]]

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


[R] nls, reach limit bounds

2009-07-09 Thread UyenThao Nguyen
Hi,

I am trying to fit a 4p logistic to this data, using nls function. The function 
didn't freely converge; however, it converged if I put a lower and an upper 
bound (in algorithm port). Also, the b1.A parameter always takes value of the 
upper bound, which is very strange. Has anyone experienced about non-convergent 
of nls and how to deal with this kind of problem?

Thank you very much.



3
   y   x
1  0.8924619 -0.31875876
2  1.1814749 -0.21467016
3  1.6148266  0.06069784
4  2.2091363  0.54032947
5  2.7019079  1.04921802
6  3.0679585  1.60745502
9  0.9436973 -0.31875876
10 1.2201133 -0.21467016
11 1.6470043  0.06069784
12 2.2090048  0.54032947
13 2.6864857  1.04921802
14 3.0673523  1.60745502

new.cont=nls.control(maxiter = 1, tol = 1e-05, minFactor = 1e-08,
printEval = FALSE, warnOnly = FALSE)


b0.A=.9*min(DAT$y)
b1.A=1.1*max(DAT$y)-b0.A
b2.A=-1*mean(DAT$x)
b3.A=1


b0.A
b1.A
b2.A
b3.A

nls.mdl.A=nls(y~b0 + b1/(1+exp(-b2-b3*x)),data=DAT,start = list(b0=b0.A, 
b1=b1.A, b2=b2.A, b3=b3.A), lower=-10, upper=10, 
algorithm="port",trace=T,control=new.cont)

##



[[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] Comparing Probit and Logit Coefficients Across Groups

2009-07-09 Thread OSTERFELD Marius
Hi,

I want to compare probit coefficients across groups with the method proposed by 
Allison (1999). The method corrects for unobserved heterogeneity in binary 
regression models. I can find only a SAS macro on the author's homepage 
(http://www.ssc.upenn.edu/~allison/glogit.sas). Has anyone of you ever 
implemented this method in R or knows how to integrate the macro?

Thank you very very much for your kind help and any tips!

Marius

__
Marius Osterfeld
Rue Francois Guillimann 5
CH-1700 Fribourg

Lehrstuhl für Makroökonomie,
Industrie- und Wachstumspolitik
Boulevard de Pérolles 90
CH-1700 Fribourg

Tel. (Büro): 0041 26 300 93 81
Natel: 0041 79 269 19 26
Tel. (CH): 0041 26 321 15 59
Tel. (D): 0049 2461 1859



[[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] Converting indices of a matrix subset

2009-07-09 Thread Nathan S. Watson-Haigh
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Hi Steven,

This looks great. Thanks!

Nathan


Steve Lianoglou wrote:
> Hi Nathan,
> 
> On Jul 8, 2009, at 10:20 PM, Nathan S. Watson-Haigh wrote:
> 
>> I have two matrices:
>>
>>> m1 <- matrix(1,4,4)
>>> m1
>> [,1] [,2] [,3] [,4]
>> [1,]1111
>> [2,]1111
>> [3,]1111
>> [4,]1111
>>
>>> m2 <- matrix(0,3,3)
>>> diag(m2) <- 1
>>> m2
>> [,1] [,2] [,3]
>> [1,]100
>> [2,]010
>> [3,]001
>>
>> I want to get indicies from m2 such that they match indicies as  
>> though they came
>> from the lower right of m1. Here's how things work:
>>
>>> ind1 <- which(m1 == 1)
>>> ind1
>> [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16
>>> ind2 <- which(m2 == 1)
>>> ind2
>> [1] 1 5 9
>>
>>
>> I would like ind2 to be offset so they look like indicies from the  
>> lower right
>> of m1:
>>> ind2
>> [1] 6 11 16
> 
> 
> I have written some utility functions I use often[1], and have  
> "sub2ind" function that works in a similar fashion to the MATLAB  
> function of the same name. It's somehow long and convoluted because  
> you can send in your arguments 12 different ways from sunday, so:
> 
> sub2ind <- function(x, y, nrow, ncol=NULL) {
>## Returns a linear index for the (x,y) coordinates passed in.
>if (is.matrix(x) || is.data.frame(x)) {
>  stopifnot(ncol(x) == 2)
>  if (!missing(y)) {
>if (missing(nrow)) {
>  nrow <- y
>} else {
>  ncol <- nrow
>  nrow <- y
>}
>  }
>  y <- x[,2]
>  x <- x[,1]
>}
> 
>if (is.matrix(nrow)) {
>  d <- dim(nrow)
>  nrow <- d[1]
>  ncol <- d[2]
>} else if (is.null(ncol)) {
>  stop("Dimensions of matrix under-specified")
>}
> 
># Sanity check to ensure we got each var doing what it should be  
> doing
>if (length(x) != length(y) || length(nrow) != 1 || length(ncol) !=  
> 1) {
>  stop("I'm confused")
>}
> 
>((x - 1) + ((y - 1) * nrow)) + 1
> 
> }
> 
> R> m1 <- matrix(1,4,4)
> R> m2 <- matrix(0,3,3)
> R> ind2 <- which(m2 == 1, arr.ind=T) + 1
> R> ind2
>   row col
> [1,]   2   2
> [2,]   3   3
> [3,]   4   4
> 
> R> my.ind2 <- sub2ind(ind2, nrow=4, ncol=4)
> # my.ind2 <- sub2ind(ind2[,1], ind2[,2], 4, 4)
> # my.ind2 <- sub2ind(ind2[,1], ind2[,2], m1)
> # my.ind2 <- sub2ind(ind2, m1)
> R> my.ind2
> [1]  6 11 16
> 
> I think that gets you to where you want to be :-)
> 
> -steve
> 
> [1] They can be found here if your intersted, there isn't much  
> documentation there, but I'll fix that some time later :-)
> http://github.com/lianos/ARE.utils/tree/master
> 
> --
> Steve Lianoglou
> Graduate Student: Physiology, Biophysics and Systems Biology
> Weill Medical College of Cornell University
> 
> Contact Info: http://cbio.mskcc.org/~lianos
> 
> 
> 


- --
- 
Dr. Nathan S. Watson-Haigh
OCE Post Doctoral Fellow
CSIRO Livestock Industries
Queensland Bioscience Precinct
St Lucia, QLD 4067
Australia

Tel: +61 (0)7 3214 2922
Fax: +61 (0)7 3214 2900
Web: http://www.csiro.au/people/Nathan.Watson-Haigh.html
- 

-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.9 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkpWfCQACgkQ9gTv6QYzVL5zQQCffRi6SUNhtrfbMdBKadYSHGVe
00YAni90MgPiUOlBmcEq90FB/Zj/50Hz
=rZ4B
-END PGP SIGNATURE-

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


Re: [R] Compiling R-2.9.1 on Mac OS X 10.4

2009-07-09 Thread Sinha, Raktim, DFCI
Matt & Don -- Thanks a lot for the comments. I think I need to figure out why
JRI is not recognizing the R installation as shared library build first, and go
from there.

I will try post back on r-sig-mac if I need too.
Best,
Raktim


-Original Message-
From: Marc Schwartz [mailto:marc_schwa...@me.com] 
Sent: Thursday, July 09, 2009 3:36 PM
To: Sinha, Raktim, DFCI
Subject: Re: [R] Compiling R-2.9.1 on Mac OS X 10.4


On Jul 9, 2009, at 2:08 PM, Sinha, Raktim, DFCI wrote:

> Hi Matt,

Marc

and please post follow ups back to the list. That way, you get a wider  
audience of folks who can reply to your query and you don't impose on  
specific individuals. To your own benefit, you are not waiting for one  
specific individual, who may not be available to respond to you. Keep  
in mind, we are all volunteers and most of us have full time jobs  
which will keep us busy.

As Don noted, there is also a specific R list for OSX related queries.  
More information here:

   https://stat.ethz.ch/mailman/listinfo/r-sig-mac

If the comments below are not helpful, please post follow ups there  
after subscribing.

> I am trying to compile JRI(http://www.rforge.net/JRI/) for Mac, Win  
> & Linux
> which loads R dynamic library into Java.
>
> I had no problems doing it with Windows as the binary is built using
> --enable-R-shlib but for Linux and Mac its giving me errors.
>
> The specific errors of Mac:
>
> /Library/Frameworks/R.framework/Resources/bin/config: line 1: make:  
> command not
> found
> /Library/Frameworks/R.framework/Resources/bin/config: line 1: make:  
> command not
> found
> R was not built as a library
> configure: error: R was not compiled with --enable-R-shlib
>

If you are going to compile from source, the first thing that you need  
to do is to install the XCode Tools package, which is from Apple and  
available on the OSX install DVD or from Apple, all of which is noted  
in the OSX FAQ I pointed you to. XCode Tools provides the basic  
compiling environment and tools, with the exception of a FORTRAN  
compiler, which is available from the CRAN OSX Tools page as a binary.

I don't use JRI, but would suggest that you review the guidance in  
their FAQ, which points to certain system configuration things that  
you need to do to get it to work with R.

> *** You must have libR.so or equivalent in order to use JRI ***
>
> I Installed R-2.9.1 from the same location you pointed me too. Also  
> I was
> following the instructions from the same site you referred to, to  
> compile on
> Mac.

As noted, you should not have to compile R from source, as the result  
of your compilation will be essentially identical to the binary  
available from CRAN. If you are not comfortable with low level system  
operations, I would urge you to steer away from building R from  
source. Even for most Linux distributions, there are pre-compiled R  
binaries available via the normal package management tools and they  
too are typically built with R as a shared library.

You should be able to install JRI using the command noted on the JRI  
web site, after installing the R binary:

   install.packages("rJava")

There is an OSX binary available on the CRAN mirrors.

>
> Is there a way I get the log file across?

You can try to rename the file with a .txt extension or better, upload  
it someplace and post the URL to it, which would be a better option,  
so as not to send a large attachment to the list.

HTH,

Marc


> Thanks
> Raktim
>
>
>
> -Original Message-
> From: Marc Schwartz [mailto:marc_schwa...@me.com]
> Sent: Thursday, July 09, 2009 2:03 PM
> To: Sinha, Raktim, DFCI
> Cc: r-help@r-project.org
> Subject: Re: [R] Compiling R-2.9.1 on Mac OS X 10.4
>
> On Jul 9, 2009, at 12:12 PM, Sinha, Raktim, DFCI wrote:
>
>> Hello,
>>
>>
>>
>> I am trying to compile R-2.9.1 on Mac OS-X 10.4 using --enable-R-
>> shlib.
>>
>>
>>
>> I am not comfortable with Mac/Linux environments and trying to
>> follow the
>> instructions from CRAN site to every detail.
>>
>> The Mac OS did not have a gcc (gcc -version did not work). So I did
>> the
>> following:
>>
>>
>>
>> ## For gcc 4.2 and Fortran 4.2.4 Compilers
>>
>> Download gcc-4.2-5566-darwin8-all.tar.gz from
>> http://r.research.att.com/tools/#gcc42
>>
>> unpacked using: sudo tar fvxz gcc-4.2-5566-darwin8-all.tar.gz -C /
>>
>> Made gcc-4.2 default: sudo link gcc-4.2 gcc
>>
>> Made g++-4.2 default: sudo link g++-4.2 g++
>>
>>
>>
>> I downloaded the source and tried compiling using:
>>
>> ./configure --with-blas='-framework vecLib' --with-lapack --with- 
>> ICU \
>>
>>  --with-aqua --enable-R-framework --enable-R-shlib
>>
>>
>>
>> Got the following error:
>>
>> Configure: error: C compiler cannot create executables
>>
>>
>>
>> I have attached the compile.log file.
>>
>> I would really appreciate some help.
>
>
> The log file did not survive the list spam filters, but is there a
> particular reason that you are compiling from source?
>
> A universal binary installation 

Re: [R] 'scan' in a script?

2009-07-09 Thread Gabor Grothendieck
Check out:

http://tolstoy.newcastle.edu.au/R/help/03a/6855.html

On Thu, Jul 9, 2009 at 2:24 PM, Mark Knecht wrote:
> When I use the scan function in the Rgui console it works as expected.
> However it seems that when I put the same command in a script file it
> doesn't wait for input.
>
> Is there an option to scan to make it wait for input when used in a
> script? Or is there possibly a different function that will do in a
> script the same sort of thing as scan does in the console?
>
> Thanks,
> Mark
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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] datadist() in Design library

2009-07-09 Thread array chip

Dear Jorge, Yes, with "data=beta.final" in the lrm(), it worked. But I thought 
one of the reasons for datadist() is to make it unnecessary to specify the data 
frame in the lrm(). Maybe I am completely wrong here.

Thanks

John

--- On Thu, 7/9/09, Jorge Ivan Velez  wrote:

> From: Jorge Ivan Velez 
> Subject: Re: [R] datadist() in Design library
> To: "array chip" 
> Cc: "R mailing list" 
> Date: Thursday, July 9, 2009, 6:55 PM
> Dear John,
> Have you tried it specifying the 'data'
> argument as suggested in lrm help?
> Try this:
>  lrm(Disease ~ gsct +
> apcct + rarct,  data = beta.final, x
> = TRUE,  y = TRUE)
> 
> 
> HTH,
> Jorge
> 
> On Thu, Jul 9, 2009 at 6:46 PM,
> array chip 
> wrote:
> 
> 
> 
> 
> Hi I got an error message using datadist() from Design
> package:
> 
> 
> 
> > library(Design,T)
> 
> > dd <- datadist(beta.final)
> 
> > options(datadist="dd")
> 
> > lrm(Disease ~ gsct+apcct+rarct, x=TRUE, y=TRUE)
> 
> Error in eval(expr, envir, enclos) : object
> "Disease" not found
> 
> 
> 
> All variables inclduing response variable
> "Disease" are in the data frame
> "beta.final", why then "Disease" can not
> be found? I thought with datadist(), all variables are
> presented to the model fitting functions. maybe I am wrong?
> 
> 
> 
> 
> 
> thanks
> 
> 
> 
> John
> 
> 
> 
> __
> 
> R-help@r-project.org
> mailing list
> 
> https://stat.ethz.ch/mailman/listinfo/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] validate() in Design library

2009-07-09 Thread array chip

Hi, another question about validate() in Design library. The arugment "B" of 
this function is number of repetition for method="bootstrap", which is easy to 
understand; but for method="crossvalidation", B is the number of groups of 
omitted observations. This is confusing, I don't understand what it means. 
Let's say 5-fold cross validation, all samples are divided into 5 groups of 
equal number of samples, 4 groups will be used as training and the model 
developed there will be tested in the 1 group left-over. And the process 
circulate for all 5 groups. What does the "B" argument mean in this example? 
B=5? or B=1 because 1 group of samples omitted from model development?

Thanks

Yi

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 combine two rows (in a dataframe) into a third row?

2009-07-09 Thread Peter Alspach
Tena koe Mark

?tapply

with the index argument some suitable substring of your ID column.

HTH 

Peter Alspach 

> -Original Message-
> From: r-help-boun...@r-project.org 
> [mailto:r-help-boun...@r-project.org] On Behalf Of Mark Na
> Sent: Friday, 10 July 2009 10:28 a.m.
> To: r-help@r-project.org
> Subject: [R] How to combine two rows (in a dataframe) into a 
> third row?
> 
> Dear R-helpers,
> 
> I have two rows in my dataframe:
> 
> IDVALUE
> 1A10
> 1B15
> 
> and I would like to combine these two rows into a single 
> (new) row in my
> dataframe:
> 
> IDVALUE
> 125
> 
> ...simply by specifying a new value for ID and summing the two VALUES.
> 
> I have been trying to do this with with rbind, but it's not working.
> 
> I'd appreciate any pointers.
> 
> Thanks, Mark Na
> 
>   [[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.
> 

The contents of this e-mail are confidential and may be subject to legal 
privilege.
 If you are not the intended recipient you must not use, disseminate, 
distribute or
 reproduce all or any part of this e-mail or attachments.  If you have received 
this
 e-mail in error, please notify the sender and delete all material pertaining 
to this
 e-mail.  Any opinion or views expressed in this e-mail are those of the 
individual
 sender and may not represent those of The New Zealand Institute for Plant and
 Food Research Limited.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] datadist() in Design library

2009-07-09 Thread Jorge Ivan Velez
Dear John,
Have you tried it specifying the 'data' argument as suggested in lrm help?

Try this:

 lrm(Disease ~ gsct + apcct + rarct,  data = beta.final, x = TRUE,  y = TRUE
)

HTH,

Jorge


On Thu, Jul 9, 2009 at 6:46 PM, array chip  wrote:

>
> Hi I got an error message using datadist() from Design package:
>
> > library(Design,T)
> > dd <- datadist(beta.final)
> > options(datadist="dd")
> > lrm(Disease ~ gsct+apcct+rarct, x=TRUE, y=TRUE)
> Error in eval(expr, envir, enclos) : object "Disease" not found
>
> All variables inclduing response variable "Disease" are in the data frame
> "beta.final", why then "Disease" can not be found? I thought with
> datadist(), all variables are presented to the model fitting functions.
> maybe I am wrong?
>
> thanks
>
> John
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

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


[R] Stratified data summaries

2009-07-09 Thread Hayes, Rachel M
Hi All,

 

I'm trying to automate a data summary using summary or describe from the
HMisc package.  I want to stratify my data set by patient_type.  I was
hoping to do something like:

 

Describe(myDataFrame ~ patient_type)

 

I can create data subsets and run the describe function one at a time,
but there's got to be a better way.  Any suggestions?

 

Rachel


[[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] Executing an error prone function without stopping a script

2009-07-09 Thread Duncan Murdoch

Tolga I Uzuner wrote:

Dear R Users,

I've used this a long time ago but have forgotten. Trawling aroung the various 
sources somehow does not lead me to it. How can I execute an error prone 
function without stopping a script if it goes wrong ?

  


See ?try.

Duncan Murdoch

Thanks in advance,
Tolga


This email is confidential and subject to important disclaimers and
conditions including on offers for the purchase or sale of
securities, accuracy and completeness of information, viruses,
confidentiality, legal privilege, and legal entity disclaimers,
available at http://www.jpmorgan.com/pages/disclosures/email.  
	[[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] datadist() in Design library

2009-07-09 Thread array chip

Hi I got an error message using datadist() from Design package:

> library(Design,T)
> dd <- datadist(beta.final)  
> options(datadist="dd") 
> lrm(Disease ~ gsct+apcct+rarct, x=TRUE, y=TRUE)
Error in eval(expr, envir, enclos) : object "Disease" not found

All variables inclduing response variable "Disease" are in the data frame 
"beta.final", why then "Disease" can not be found? I thought with datadist(), 
all variables are presented to the model fitting functions. maybe I am wrong?

thanks

John

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

2009-07-09 Thread nermin sarlak

Hi,

 I’m using R package SSOAP to retrieve data from web services. I’m using the 
code below to
 
> >> >> # R code ###
library(SSOAP)
 then I call the nwis.R which exists in SSOAP example folder. However system 
gives me following errors:

 
Error in parse (text=paste(text, collapse=”\n”)):
Unexpected input in “function (x’…,obj=new(‘”
 
I could not understand why I get this error. I am very appreciate anybody help 
me. 
nermin

 

_


[[alternative HTML version deleted]]

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


[R] How to combine two rows (in a dataframe) into a third row?

2009-07-09 Thread Mark Na
Dear R-helpers,

I have two rows in my dataframe:

IDVALUE
1A10
1B15

and I would like to combine these two rows into a single (new) row in my
dataframe:

IDVALUE
125

...simply by specifying a new value for ID and summing the two VALUES.

I have been trying to do this with with rbind, but it's not working.

I'd appreciate any pointers.

Thanks, Mark Na

[[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] Strange t-test error: "grouping factor must have exactly 2 levels" while it does...

2009-07-09 Thread Tymek W
Hi,

Could anyone tell me what is wrong:

> length(unique(mydata$myvariable))
[1] 2
>

and in t-test:

(...)
Error in t.test.formula(othervariable ~ myvariable, mydata) :
  grouping factor must have exactly 2 levels
>

I re-checked the code and still don't get what is wrong.

Moreover, there is some strange behavior:

/1 It seems that the error is vulnerable to NA'a, because it affects
some variables in data set with NA's and doesn't affect same ones in
dataset with NA's removed.

/2 It seems it works differently with different ways of using
variables in t.test:

eg. it hapends here: t.test(x~y, dataset) and does not here:
t.test(dataset[['x']]~dataset[['y']])

Does anyone have any ideas?

Greetz,
Timo

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] 'scan' in a script?

2009-07-09 Thread Mark Knecht
Jim,
   In Rgui there is a feature to create a new script so I open that
and get a blank editor. I put these commands in the script

MyNames = scan(what="")
MyNames

   Whether I ask Rgui to run the whole script as a script - not
sourced - it runs the first command, doesn't wait for input and then
runs the second command. I see

> MyNames
character(0)
>

   If I right click the first line and ask it to run the selection or
line then R waits for the input.

   If I source the file then the opposite happens. It does the scan
correctly, waiting for me to make entries. When I finish it doesn't
print what's in MyNames, as shown here where I typed in happy sad test
go and hit enter.

> source("C:\\Users\\Mark\\Documents\\R\\Test Cases\\scan from script.R")
1: happy sad test go
5:
Read 4 items
>

   Possibly (probably!) this is a misunderstanding on my part, but
it's something I need to start looking at as the reason for me
checking out R at all was as a potential way to develop a complete
program, as opposed to writing it in C, so I need to start looking at
how to give it input (file names, directory paths, user requests)
other than changing source code.

   I hope this is clear enough and I appreciate your inputs.

Cheers,
Mark

On Thu, Jul 9, 2009 at 1:02 PM, jim holtman wrote:
> Exactly how are you using it?  How you executing your script?  Are you
> using cut/paste or source?  Have you tried 'readline'?
>
> More details on what you mean by it does not work as expected.
>
> On Thu, Jul 9, 2009 at 2:24 PM, Mark Knecht wrote:
>> When I use the scan function in the Rgui console it works as expected.
>> However it seems that when I put the same command in a script file it
>> doesn't wait for input.
>>
>> Is there an option to scan to make it wait for input when used in a
>> script? Or is there possibly a different function that will do in a
>> script the same sort of thing as scan does in the console?
>>
>> Thanks,
>> Mark
>>
>> __
>> R-help@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>
>
>
> --
> Jim Holtman
> Cincinnati, OH
> +1 513 646 9390
>
> What is the problem that you are trying to solve?
>

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


Re: [R] X-axis labels not displayed when changing ylim

2009-07-09 Thread Patrick Connolly
On Thu, 09-Jul-2009 at 05:36PM +0200, Sarah Bonnin wrote:

> Dear R users,
>
> I am encountering a x axis labeling problem on quite basic plots...
> I use the following code which displays the labels on the x-axis with a  
> 45 degrees angle:
>
> p <- plot(myobject1, type="b", col="red",cex=1, lwd=2, axes=FALSE,  
> ann=FALSE, ylim=c(0,70))
> title(main="title", font.main=4)
> axis(side=1, lab=F)
> text(axTicks(1), par("usr")[3] - 2, srt=45, adj=1,labels=mylabels,xpd=T,  

I think this part is what's not transferable to a smaller range of
y-values.

par("usr")[3] will be much smaller when ylim goes to only 2 instead of
70.  Subtract 2 from that, and you have a very different kettle of
fish.

Without knowing anything about myobject1 and myobject2 I could be
completely ooff the mark, of cours.

HTH





> cex=0.8, font=2)
> axis(side=2, las=1, cex.axis=0.8, font=2)
>
> I set up the ylim from 0 to 70 for plotting that object "myobject1" ->  
> works well.
> However, when i try to use the same script with another set of data  
> "myobject2" (same number of points, same labels, but different  
> values...) that ranges from 0 to 2 (ylim changed to "c(0,2)"), the  
> labels on the x axis disappear...
> When i try to run the same lines for "myobject2" but putting the ylim  
> higher "c(0,50)", the labels on the x axis are displayed.
>
> I picked up some pieces of code here and there so i may do an obvious  
> mistake but cannot figure out what it is! I tried to modify the text  
> parameters "adj" or "par("usr")...", unsuccessfully...
> I hope i made it clear, there must be a scaling problem that i really  
> don't get...
> I run R 2.8.0 under Windows XP Pro.
>
> Thank you for your help!
>
> Sarah
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

-- 
~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.   
   ___Patrick Connolly   
 {~._.~}   Great minds discuss ideas
 _( Y )_ Average minds discuss events 
(:_~*~_:)  Small minds discuss people  
 (_)-(_)  . Eleanor Roosevelt
  
~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.

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


[R] Lattice xyplot: same scales within one factor

2009-07-09 Thread OB
I am using R 2.8.1 and lattice to produce xyplots conditioned on
two factors. What I would like is to have the scales be free between values
of one factor, but some within. Thus, in this example,

xyplot(mpg ~ disp | factor(gear) + factor(cyl), mtcars,
    scales=list(x=list(relation="free")))

rather than having the x scales be free within a gear as well, I want it to
be the same for the gear, but free between cyl (and thus only have x scales
below the bottom panels with no scales or white space in the middle between
panels).

Any help would be greatly appreciated!

-Orion

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Issues with file.info?

2009-07-09 Thread Rolf Turner


On 10/07/2009, at 6:02 AM, Jason Rupert wrote:



Are there any tricks associated with file.info?

I just tried it on a directory folder and it returned NA for all  
fields for all files.  I tried it on a different folder with  
different files and it still returned NA.


I tried it on a specific file and it returned all the proper info  
correctly.


Just wondering if there are any tricks I've overlooked.


Yes.  You've overlooked the trick of telling us about the specifics of
your operating system, version of R, etc., and of showing exactly what
commands you ``tried'', i.e. of reading the Posting Guide.

cheers,

Rolf Turner



##
Attention:\ This e-mail message is privileged and confid...{{dropped:9}}

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Issues with file.info?

2009-07-09 Thread Jason Rupert

Issue was with an entire directory/folder or list of files in a directory.  It 
seemed to work fine for a single file or being sent a single file/folder.  

I will try to generate some example code to demonstrate the problem. 

Thanks again for all the replies. 



--- On Thu, 7/9/09, jim holtman  wrote:

> From: jim holtman 
> Subject: Re: [R] Issues with file.info?
> To: "Jason Rupert" 
> Cc: R-help@r-project.org
> Date: Thursday, July 9, 2009, 3:04 PM
> Works fine for me on 2.9.1:
> 
> > file.info('/jph')
>      size isdir mode   
>            mtime 
>              ctime
>     atime exe
> /jph    0  TRUE  777 2009-06-29
> 15:15:13 2008-02-14 09:31:26
> 2009-07-09 15:57:04  no
> >
> 
> 
> 
> On Thu, Jul 9, 2009 at 2:02 PM, Jason Rupert
> wrote:
> >
> > Are there any tricks associated with file.info?
> >
> > I just tried it on a directory folder and it returned
> NA for all fields for all files.  I tried it on a different
> folder with different files and it still returned NA.
> >
> > I tried it on a specific file and it returned all the
> proper info correctly.
> >
> > Just wondering if there are any tricks I've
> overlooked.
> >
> > __
> > R-help@r-project.org
> mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained,
> reproducible code.
> >
> 
> 
> 
> -- 
> Jim Holtman
> Cincinnati, OH
> +1 513 646 9390
> 
> What is the problem that you are trying to solve?
> 




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


Re: [R] How to Populate List

2009-07-09 Thread Rolf Turner


On 10/07/2009, at 2:55 AM, Gaurav Kumar wrote:


Hi,

I'm new to R and would like to know, how one can populate the list  
with array data.
I'm reading a tab separated table in R. The data in the table looks  
something like this.


#Table Data
CompABC
Extracellular103268535759
Nucleus4560347783442744

#R code
myData <- read.table("table.data",
header=T,
sep="\t",
comment.char = "#"
);
inp <- scan("table.data", what=list(comp=" ", A="", B="", C=""));
n <- c(0:length(inp$comp));
myList=list();
for(i in n-1)
{
obj <-c(as.numeric(myData$A[i]),as.numeric(myData$B 
[i]),as.numeric(myData$C[i]));


}

Need help to know if there is any function in R to push obj to myList


(a) You apparently ``replied'' to an R-help digest, and included  
megabytes
of totally irrelevant material in your post.  It took me several  
minutes to delete it.


STEP ONE:  LEARN HOW TO USE EMAIL!!!

(b) Do the following:

myList <- list();
for(i in n-1)
{
myList[[i]] <-c(as.numeric(myData$A[i]),as.numeric(myData$B 
[i]),as.numeric(myData$C[i]));


}

cheers,

Rolf Turner

##
Attention:\ This e-mail message is privileged and confid...{{dropped:9}}

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Issues with file.info?

2009-07-09 Thread jim holtman
Works fine for me on 2.9.1:

> file.info('/jph')
 size isdir mode   mtime   ctime
atime exe
/jph0  TRUE  777 2009-06-29 15:15:13 2008-02-14 09:31:26
2009-07-09 15:57:04  no
>



On Thu, Jul 9, 2009 at 2:02 PM, Jason Rupert wrote:
>
> Are there any tricks associated with file.info?
>
> I just tried it on a directory folder and it returned NA for all fields for 
> all files.  I tried it on a different folder with different files and it 
> still returned NA.
>
> I tried it on a specific file and it returned all the proper info correctly.
>
> Just wondering if there are any tricks I've overlooked.
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



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

What is the problem that you are trying to solve?

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


Re: [R] 'scan' in a script?

2009-07-09 Thread jim holtman
Exactly how are you using it?  How you executing your script?  Are you
using cut/paste or source?  Have you tried 'readline'?

More details on what you mean by it does not work as expected.

On Thu, Jul 9, 2009 at 2:24 PM, Mark Knecht wrote:
> When I use the scan function in the Rgui console it works as expected.
> However it seems that when I put the same command in a script file it
> doesn't wait for input.
>
> Is there an option to scan to make it wait for input when used in a
> script? Or is there possibly a different function that will do in a
> script the same sort of thing as scan does in the console?
>
> Thanks,
> Mark
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



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

What is the problem that you are trying to solve?

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


Re: [R] naming of columns in R dataframe consisting of mixed data (alphanumeric and numeric)

2009-07-09 Thread Etienne B. Racine



Mary A. Marion-2 wrote:
> 
> Hello,
> 
> I have an r function that creates the following dataframe tresults2.
> Notice that column 1 does not have a column heading.
> 
> Tresults2:
>  [,1]
> estparam 18.0
> nullval  20.0
> . . .
> ciWidth   2.04622
> HalfInterval  1.02311
> 
> pertinent code:
> results<-cbind( estparam, nullval, t, pv_left, pv_right, pv_two_t, 
> estse, df,  cc, tbox, llim, ulim, ciWidth, HalfInterval)
> tresults<-round((results),5)
> tresults2<-data.frame(t(tresults))
> names(tresults2)<-c("Statistic ", "Value")
> tresults2
> 
> ===
> After transposing my dataframe tresults2 consists of 2 columns.  
> Col1=alphanumeric data (this really is a variable name) and
> col2=numeric data (this is value of varaiable).
> 
> how do I name columns when columns are different (alphanumeric and
> numeric)
> to avoid the following error:
> 
> Error in names(tresults2) <- c("Statistic ", "Value") :
>   'names' attribute [2] must be the same length as the vector [1]
> 
You tried to give a name to a column that do not exist (the second one you
called "value"). You can check that using str(tresults2).
The name of the columns should not (well, I don't see how) interfere with
the type (or class) they contain.

You can create a Value column by using tresults2$Value <- your_value



> 
> Am I to use c( , ) or list( , ) with a dataframe?
> 
You picked the right one ( c() )... to give the names, I guess this is what
you were asking.

Cheers,
Etienne


> Thank you for your help.
> Sincerely,
> Mary A. Marion
> 

-- 
View this message in context: 
http://www.nabble.com/naming-of-columns-in-R-dataframe-consisting-of-mixed-data-%28alphanumeric-and-numeric%29-tp24411614p24416676.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] Reading from Google Docs

2009-07-09 Thread Johannes Huesing
Gabor Grothendieck  [Wed, Jul 08, 2009 at 10:31:30PM 
CEST]:
[...]
> >>>
> >>>    [[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.
> >>
>      [[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.
> >
> >
> 
>  __
>  R-help@r-project.org mailing list
>  https://stat.ethz.ch/mailman/listinfo/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.

Do you think more people will pay attention when you repeat this
over and over?

-- 
Johannes Hüsing   There is something fascinating about science. 
  One gets such wholesale returns of conjecture 
mailto:johan...@huesing.name  from such a trifling investment of fact.  
  
http://derwisch.wikidot.com (Mark Twain, "Life on the Mississippi")

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Compiling R-2.9.1 on Mac OS X 10.4

2009-07-09 Thread Don MacQueen
I used to build from source on Mac OS X, but I stopped when I found I 
could do everything I needed to do from the binary on CRAN. That 
includes building my own packages that use fortran, or building the 
one or two CRAN packages that use C code and do not have Mac binaries 
on CRAN.


In addition to which, if you were to install the Mac binary from 
CRAN, there's an optional install of gcc, and that might even be an 
easier way to get a gcc on your machine. You can still build R from 
sources separately, even if you've already installed the binary.


For further help on building from source, I'd suggest asking again on 
R-sig-Mac.


-Don

At 1:12 PM -0400 7/9/09, Sinha, Raktim, DFCI wrote:

Hello,



I am trying to compile R-2.9.1 on Mac OS-X 10.4 using --enable-R-shlib.



I am not comfortable with Mac/Linux environments and trying to follow the
instructions from CRAN site to every detail.

The Mac OS did not have a gcc (gcc -version did not work). So I did the
following:



## For gcc 4.2 and Fortran 4.2.4 Compilers

Download gcc-4.2-5566-darwin8-all.tar.gz from
http://*r.research.att.com/tools/#gcc42

unpacked using: sudo tar fvxz gcc-4.2-5566-darwin8-all.tar.gz -C /

Made gcc-4.2 default: sudo link gcc-4.2 gcc

Made g++-4.2 default: sudo link g++-4.2 g++



I downloaded the source and tried compiling using:

./configure --with-blas='-framework vecLib' --with-lapack --with-ICU \

   --with-aqua --enable-R-framework --enable-R-shlib



Got the following error:

Configure: error: C compiler cannot create executables



I have attached the compile.log file.

I would really appreciate some help.



Raktim

Bioinformatics Engineer

DFCI, Harvard Med School

Boston





The information in this e-mail is intended only for the...{{dropped:26}}


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


[R] Lattice xyplot: same scales within one factor

2009-07-09 Thread Orion Buske
I am using R 2.8.1 and lattice to produce xyplots conditioned on
two factors. What I would like is to have the scales be free between values
of one factor, but some within. Thus, in the example:

xyplot(mpg ~ disp | factor(gear) + factor(cyl), mtcars,
scales=list(x=list(relation="free")))

rather than having the x scales be free within a gear as well, I want it to
be the same for the gear, but free between cyl (and thus only have x scales
below the bottom panels with no scales or white space in the middle between
panels).

Any help would be greatly appreciated

-Orion

[[alternative HTML version deleted]]

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


Re: [R] Substituting numerical values using `apply'

2009-07-09 Thread Santiago Olivella
Thank you all for your help.

SO.

Henrique Dallazuanna wrote:
> Try this:
>
> sapply(names(DF), function(n)ifelse(DF[,n] %in% c(1, 2), n, NA))
>
> Where DF is your data.frame
>
> On Wed, Jul 8, 2009 at 5:25 PM, Olivella  > wrote:
>
>
> Hello,
>
> I wish to perform a substitution of certain numerical values in a data
> matrix with the corresponding column name. For instance, if I have
> a data
> matrix
> V1  V2  V3
> 201
> 012
> 150
> 500
>
> I want to substitute the `1' and the `2' for the corresponding
> column name,
> and make everything else `NA' like this
> V1V2V3
> V1NAV3
> NAV2V3
> V1NANA
> NANANA
>
> I have done this using an explicit `for' loop, but it takes a
> really long
> time to finish. Is there any way I can do this using `apply' or
> some form of
> implicit looping?
>
> Thank you for your help,
>
> SO
> --
> View this message in context:
> 
> http://www.nabble.com/Substituting-numerical-values-using-%60apply%27-tp24398687p24398687.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.
>
>
>
>
> -- 
> Henrique Dallazuanna
> Curitiba-Paraná-Brasil
> 25° 25' 40" S 49° 16' 22" O

-- 
-
Santiago Olivella
Ph.D. Program in Political Science
Washington University in St. Louis
solivella.wustl.edu


[[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] 'scan' in a script?

2009-07-09 Thread Mark Knecht
When I use the scan function in the Rgui console it works as expected.
However it seems that when I put the same command in a script file it
doesn't wait for input.

Is there an option to scan to make it wait for input when used in a
script? Or is there possibly a different function that will do in a
script the same sort of thing as scan does in the console?

Thanks,
Mark

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Compiling R-2.9.1 on Mac OS X 10.4

2009-07-09 Thread Marc Schwartz

On Jul 9, 2009, at 12:12 PM, Sinha, Raktim, DFCI wrote:


Hello,



I am trying to compile R-2.9.1 on Mac OS-X 10.4 using --enable-R- 
shlib.




I am not comfortable with Mac/Linux environments and trying to  
follow the

instructions from CRAN site to every detail.

The Mac OS did not have a gcc (gcc -version did not work). So I did  
the

following:



## For gcc 4.2 and Fortran 4.2.4 Compilers

Download gcc-4.2-5566-darwin8-all.tar.gz from
http://r.research.att.com/tools/#gcc42

unpacked using: sudo tar fvxz gcc-4.2-5566-darwin8-all.tar.gz -C /

Made gcc-4.2 default: sudo link gcc-4.2 gcc

Made g++-4.2 default: sudo link g++-4.2 g++



I downloaded the source and tried compiling using:

./configure --with-blas='-framework vecLib' --with-lapack --with-ICU \

  --with-aqua --enable-R-framework --enable-R-shlib



Got the following error:

Configure: error: C compiler cannot create executables



I have attached the compile.log file.

I would really appreciate some help.



The log file did not survive the list spam filters, but is there a  
particular reason that you are compiling from source?


A universal binary installation package (which is built using --enable- 
R-shlib) is available from a CRAN mirror such as:


  http://cran.us.r-project.org/

You might want to review the OSX FAQ as well:

  http://cran.us.r-project.org/bin/macosx/RMacOSX-FAQ.html

If you really need to build from source, which is not for the feint of  
heart, begin by reviewing section 2 of the FAQ.


HTH,

Marc Schwartz

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Issues with file.info?

2009-07-09 Thread Jason Rupert

Are there any tricks associated with file.info? 

I just tried it on a directory folder and it returned NA for all fields for all 
files.  I tried it on a different folder with different files and it still 
returned NA.  

I tried it on a specific file and it returned all the proper info correctly. 

Just wondering if there are any tricks I've overlooked.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Compiling R-2.9.1 on Mac OS X 10.4

2009-07-09 Thread Sinha, Raktim, DFCI
Hello,

 

I am trying to compile R-2.9.1 on Mac OS-X 10.4 using --enable-R-shlib.

 

I am not comfortable with Mac/Linux environments and trying to follow the
instructions from CRAN site to every detail.

The Mac OS did not have a gcc (gcc -version did not work). So I did the
following:

 

## For gcc 4.2 and Fortran 4.2.4 Compilers

Download gcc-4.2-5566-darwin8-all.tar.gz from
http://r.research.att.com/tools/#gcc42

unpacked using: sudo tar fvxz gcc-4.2-5566-darwin8-all.tar.gz -C /

Made gcc-4.2 default: sudo link gcc-4.2 gcc

Made g++-4.2 default: sudo link g++-4.2 g++ 

 

I downloaded the source and tried compiling using:

./configure --with-blas='-framework vecLib' --with-lapack --with-ICU \

   --with-aqua --enable-R-framework --enable-R-shlib

 

Got the following error:

Configure: error: C compiler cannot create executables

 

I have attached the compile.log file.

I would really appreciate some help.

 

Raktim

Bioinformatics Engineer

DFCI, Harvard Med School

Boston

 



The information in this e-mail is intended only for the person to whom it is
addressed. If you believe this e-mail was sent to you in error and the e-mail
contains patient information, please contact the Partners Compliance HelpLine at
http://www.partners.org/complianceline . If the e-mail was sent to you in error
but does not contain patient information, please contact the sender and properly
dispose of the e-mail.
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] more than one mathematical annotation into a legend

2009-07-09 Thread Zhiliang Ma
On Thu, Jul 9, 2009 at 9:39 AM, Thomas Roth (geb.
Kaliwe) wrote:
try this:

legend(4,4, expression(t[m] == x, t[n] == x))

cheers,
Zhiliang

> Dear members,
>
> Is there a way to put more than one mathematical annotation into a legend
> together with a calculated value?
>
> x = 2
> plot(1:10)
>
> #Works
> legend(8, 8,  substitute(t[m] == x))
>
> #does not work
> legend(4,4, c(substitute(t[m] == x), substitute(t[n] == x)))
>
> Thanks
>
>
> Thomas Roth
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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] X-axis labels not displayed when changing ylim

2009-07-09 Thread Sarah Bonnin

Dear R users,

I am encountering a x axis labeling problem on quite basic plots...
I use the following code which displays the labels on the x-axis with a 
45 degrees angle:


p <- plot(myobject1, type="b", col="red",cex=1, lwd=2, axes=FALSE, 
ann=FALSE, ylim=c(0,70))

title(main="title", font.main=4)
axis(side=1, lab=F)
text(axTicks(1), par("usr")[3] - 2, srt=45, adj=1,labels=mylabels,xpd=T, 
cex=0.8, font=2)

axis(side=2, las=1, cex.axis=0.8, font=2)

I set up the ylim from 0 to 70 for plotting that object "myobject1" -> 
works well.
However, when i try to use the same script with another set of data 
"myobject2" (same number of points, same labels, but different 
values...) that ranges from 0 to 2 (ylim changed to "c(0,2)"), the 
labels on the x axis disappear...
When i try to run the same lines for "myobject2" but putting the ylim 
higher "c(0,50)", the labels on the x axis are displayed.


I picked up some pieces of code here and there so i may do an obvious 
mistake but cannot figure out what it is! I tried to modify the text 
parameters "adj" or "par("usr")...", unsuccessfully...
I hope i made it clear, there must be a scaling problem that i really 
don't get...

I run R 2.8.0 under Windows XP Pro.

Thank you for your help!

Sarah

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] executing an error prone function without stopping a script

2009-07-09 Thread cls59



TU wrote:
> 
> Dear R Users,
> 
> I've used this a long time ago but have forgotten. Trawling aroung the
> various sources somehow does not lead me to it. How can I execute an error
> prone function without stopping a script if it goes wrong ?
> 
> Thanks in advance,
> Tolga
> 
> 


See ?try

Basically, wrapping the function call in the try() function will make it so
that errors do not halt your script:

result <- try( function( args ) )

You can then handle errors in your own way:

if( class(result) == 'try-error' ){
  # Error handling stuff.
}

-
Charlie Sharpsteen
Undergraduate
Environmental Resources Engineering
Humboldt State University
-- 
View this message in context: 
http://www.nabble.com/executing-an-error-prone-function-without-stopping-a-script-tp24413760p24414337.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] Tex fonts in R plots

2009-07-09 Thread cls59


KARAVASILIS GEORGE wrote:
> 
> Hello, R users.
> I would like to display the font of Math Mode of MikTex 2.3, WinEdt 5.4 
> in R plots, e.g. in xlab, ylab or legend.
> How can I do that?
> Thank you in advance.
> 
> 

A colleague and I have developed a package called pgfSweave that turns R
plots created inside a Sweave document into code that can be interpreted by
PGF/TikZ package for LaTeX. The end result of this process is that the text
in your figures are typeset with the same fonts used in the rest of your TeX
document.

The package can be found at: 

http://r-forge.r-project.org/projects/pgfsweave/
 
It has been used by the authors to typeset academic papers on windows and
produces good results. However we are still classifying it as an alpha
product because it has not been tested extensively.

Currently the underlying utility that translates R graphics into PGF form is
the java utility eps2pgf which may be found at:

http://sourceforge.net/projects/eps2pgf/

You may be interested in using this utility by it's self if you just want to
prep graphics for LaTeX and don't want to use Sweave. Simply create your
graphs in R using the eps() driver and process them using eps2pgf. 

eps2pgf has some drawbacks- it takes a few seconds to translate a graph and
certain R graphics commands, such as setting text size using cex, are not
respected.

Good luck!

-Charlie


-
Charlie Sharpsteen
Undergraduate
Environmental Resources Engineering
Humboldt State University
-- 
View this message in context: 
http://www.nabble.com/Tex-fonts-in-R-plots-tp24382492p24414007.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] Creating and Using Objects in R

2009-07-09 Thread Gabor Grothendieck
Here it is done without S3.  Note that UseMethod
is basically just an alternative to an if statement.
Perhaps this makes it more understandable.

x1 <- list(x = 1, y = 2)
class(x1) <- "xypoint"
x2 <- list(r = 1, theta = pi/2)
class(x2) <- "rthetapoint"

XPOS <- function(x) {
if (inherits(x, "xypoint")) xpos.xypoint(x)
else if (inherits(x, "rthetapoint")) xpos.rthetapoint(x)
else stop("Cannot find appropriate class")
}

XPOS(x1) # without S3
xpos(x1) # using S3

XPOS(x2) # without S3
xpos(x2) # using S3


On Thu, Jul 9, 2009 at 12:24 PM, Lorenzo Isella wrote:
> Dear All,
> I am not very into object-oriented programming, but I would like to learn
> the ropes for some R applications.
> Quoting from the online R language definition (paragraph 5.1)
>
>> Consider the following simple example. A point in two-dimensional
>> Euclidean space can be specified by its Cartesian (x-y) or polar (r-theta)
>> coordinates. Hence, to store information about the location of the point, we
>> could define two classes, |"xypoint"| and |"rthetapoint"|. All the `xypoint'
>> data structures are lists with an x-component and a y-component. All
>> `rthetapoint' objects are lists with an r-component and a theta-component.
>>
>> Now, suppose we want to get the x-position from either type of object.
>> This can easily be achieved through generic functions. We define the generic
>> function |xpos| as follows.
>>
>>     xpos <- function(x, ...)
>>         UseMethod("xpos")
>>
>> Now we can define methods:
>>
>>     xpos.xypoint <- function(x) x$x
>>     xpos.rthetapoint <- function(x) x$r * cos(x$theta)
>>
>> The user simply calls the function |xpos| with either representation as
>> the argument. The internal dispatching method finds the class of the object
>> and calls the appropriate methods.
>>
> I am a bit confused: when calling e.g. xpos.rthetapoint, I understand that x
> contains the polar representation of a point, so x=(r,theta), but  how do I
> exactly  write it to pass it to xpos.rthetapoint? I have made several
> attempts, but so far none of them works, so I may have misunderstood
> something.
> Many thanks
>
> Lorenzo
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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] executing an error prone function without stopping a script

2009-07-09 Thread Tolga I Uzuner
Dear R Users,

I've used this a long time ago but have forgotten. Trawling aroung the various 
sources somehow does not lead me to it. How can I execute an error prone 
function without stopping a script if it goes wrong ?

Thanks in advance,
Tolga


This email is confidential and subject to important disclaimers and
conditions including on offers for the purchase or sale of
securities, accuracy and completeness of information, viruses,
confidentiality, legal privilege, and legal entity disclaimers,
available at http://www.jpmorgan.com/pages/disclosures/email.  
[[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] more than one mathematical annotation into a legend

2009-07-09 Thread Thomas Roth (geb. Kaliwe)

Dear members,

Is there a way to put more than one mathematical annotation into a 
legend together with a calculated value?


x = 2
plot(1:10)

#Works
legend(8, 8,  substitute(t[m] == x))

#does not work
legend(4,4, c(substitute(t[m] == x), substitute(t[n] == x)))

Thanks


Thomas Roth

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


Re: [R] R-help Digest, Vol 77, Issue 9

2009-07-09 Thread Lauri Nikkinen
Thanks, this worked!!!

nBooks <- xl[["Workbooks"]]$Count();
for (i in seq_len(nBooks))
xl[["Workbooks"]]$item(i)$Close(SaveChanges=FALSE);

-L

2009/7/9 Bengoechea Bartolomé Enrique (SIES 73)
:
> Hi,
>
> This may be due to several reasons. That I can think about:
>
> 1) Ensure you close *all* possibly open workbooks:
>
>        nBooks <- xl[["Workbooks"]]$Count();
>        for (i in seq_len(nBooks))
>                xl[["Workbooks"]]$item(i)$Close(SaveChanges=FALSE);
>
> 2) The excel application reference does not seem to be really released until 
> the garbage collector runs. So this may help:
>
>        xl$Quit();
>        xl <- NULL;
>        gc();
>
> 3) Ensure you don't have any "hanging" reference to the excel application 
> (sometimes from previous runs of your code that failed). If your code is 
> inside a function, wrap the code in point 1 and 2 on an on.exit() call to 
> ensure that excel is properly closed each time.
>
>
> Hope this helps.
>
> Enrique
>
> --
>
> Date: Wed, 8 Jul 2009 16:06:57 +0300
> From: Lauri Nikkinen 
> Subject: [R] RDCOMClient: how to close Excel process?
> To: r-h...@stat.math.ethz.ch
> Message-ID:
>        
> Content-Type: text/plain; charset=windows-1252
>
> Hi,
>
> I?m using R package RDCOMClient (http://www.omegahat.org/RDCOMClient/)
> to retrieve data from MS Excel workbook. I?m using the code below to
> count the number of sheets in the workbook and then loop the data from
> sheets in to a list.
>
> # R code ###
> library(gdata)
> library(RDCOMClient)
>
> xl <- COMCreate("Excel.Application")
> sh <- xl$Workbooks()$Open(normalizePath("sample_file.xls"))$Sheets()$Count()
>
> DF.list <- list()
> for (i in 1:sh) {
>   DF.list[[i]] <- read.xls("sample_file.xls", sheet=i,
> stringsAsFactors = FALSE)
>   }
> ##
>
> COMCreate opens Excel process and it can be seen from Windows Task
> Manager. When I try to open sample_file.xls in Excel, it just flashes
> in the screen and shuts down. When I kill (via task manager) the Excel
> process COMCreate started, sample_file.xls will open normally.
>
> The question is, how can I close the Excel process COMCreate started.
> xl$Close() doesn?t seem to work. The same problem have been presented
> in this post to R-help:
> http://tolstoy.newcastle.edu.au/R/help/06/04/25990.html
>
> -L
>
>
>
> --
>

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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: initialize, setValidity, copy-constructor

2009-07-09 Thread Martin Morgan
Hi Renaud --

Renaud Gaujoux  writes:

> Hello list,
>
> I'm having troubles setting up a basic calss hierarchy with S4.
> Here is a simplified schema of what I'd like to do:
>
> - Two classes: A and B that extends A
> - Ensure that the slots added by B are consistent with the slots of A
> - Let A initialize itself (I'm not supposed to know the internal
>   cooking of A)
> - By default set the slots of B based on the slots that A initialized
>
> Another question is: what is the recommended way of implementing a
> copy-constructor in R?
>
> I know that all of this is easily done in C++. The constructor of each
> class is called recursively back-up to the root class. Validity checks
> can be performed after/during associated
> initialization. Copy-constructor are basics in C++.
>
> Here below is a piece of code that I thought would work (but it does
> not... therefore my post), what's wrong with it?
> I think the main issue is when is the validity check performed: why is
> it performed before the end of the initialize method?

loosely, new("B", ...) calls initialize(prototypeOfB, ...).
initialize,B-method uses callNextMethod(), so initialize,A-method sees
as .Object the value prototypeOfB.  If initialize,A-method is
well-behaved, it'll call initialize,ANY-method, which also sees
prototypeOfB. You'll see that, when the ... argument is not empty

  getMethod(initialize, "ANY")

eventually calls validObject, in this case on prototypeOfB. Hence what
you are seeing, an 'early' check on the validity of B.

There are many creative ways around this in initialize,B-method, e.g.,
assigning B slots before callNextMethod(), or explicitly creating a
new instance of A from appropriate supplied arguments (in
initialize,B-method, name arguments meant to initialize B slots and
pass ... to the A constructor) and using that to initialize B, etc.

The approach I find most palatable (not meant to be real code) is to
have a constructor

  B <- function(x, y, z, ...) {
 # do all the work to map x, y, z into slots of A, B (or an
 # instance of A and slots of B), then...
 new("B", a=, b=, ...) # or new("B", instanceOfA, b=, ...)
  }

and avoid writing explicit initialize methods. 

Oddly enough, this solution leads to a copy constructor, viz.,

  initialize(instanceOfB, b=)

I'm not sure that this really does anything more than move the
'pattern' from the initialize method to the constructor.

Martin

> Thank you for your help.
> Renaud
>
> # define class A with a single numeric slot
> setClass('A', representation(a='numeric'))
>
> # define class B that extends class A, adding another numeric slot
> setClass('B', representation('A', b='numeric'))
> # we want for example to ensure that slots a and b have the same length
> setValidity('B',
> function(object){
> cat("*** B::validate ***\n")
> print(object)
> cat("*\n")
> if( length(obj...@a) != length(obj...@b) ) return('Inconsistent lengths')
> TRUE
> }
> )
> # As a default behaviour if b is not provided, we want slot b to be
>   equal to slot a
> setMethod('initialize', 'B',
> function(.Object, b, ...){
> cat("*** B::initialize ***\n")
> print(.Object)
>
> # Let the superclass (A) initialize itself via callNextMethod
> # I thought it would only do that: initialize and optionnaly validate
>   the class A part of the object
> #But it generates an ERROR: apparently it calls the validation method of B,
> # before leaving me a chance to set slot b to a valid value
> .Object <- callNextMethod(.Object, ...)
>
> # now deal with the class B part of the object
> cat("*** Test missing b ***\n")
> if( missing(b) ){
> cat("*** b is MISSING ***\n")
> b <- .obj...@a
> }
>
> # set slot b
> .obj...@b <- b
>
> .Object
> }
> )
>
> ### Testing
>
> # empty A: OK
> aObj <- new('A')
> aObj
>
> # class A with some data: OK
> aObj <- new('A', a=c(1,2) )
> aObj
>
> # empty B: OK
> bObj <- new('B')
> bObj
>
> # initialize B setting the slot of class A: ERROR
> bObj <- new('B', a=c(1,2))
>
> # initialize B setting only the slot class B: OK!! Whereas it produces
>   a non valid object.
> bObj <- new('B', b=c(1,2))
> bObj
>
> # RESULTS:
>
>  > # empty A: OK
>  > aObj <- new('A')
>  > aObj
> An object of class “A”
> Slot "a":
> numeric(0)
>
>  >
>  > # class A with some data: OK
>  > aObj <- new('A', a=c(1,2) )
>  > aObj
> An object of class “A”
> Slot "a":
> [1] 1 2
>
>  >
>  > # empty B: OK
>  > bObj <- new('B')
> *** B::initialize ***
> An object of class “B”
> Slot "b":
> numeric(0)
>
> Slot "a":
> numeric(0)
>
> *** Test missing b ***
> *** b is MISSING ***
>  > bObj
> An object of class “B”
> Slot "b":
> numeric(0)
>
> Slot "a":
> numeric(0)
>
>  >
>  > # initialize B setting the slot of class A: ERROR
>  > bObj <- new('B', a=c(1,2))
> *** B::initialize ***
> An object of class “B”
> Slot "b":
> numeric(0)
>
> Slot "a":
> numeric(0)
>
> *** B::validate ***
> An object of class “B”
> Slot "b":
> numeric(0)
>
> Slot "a":
> [1] 1 2
>
> *
> Error in validObject

[R] Executing an error prone function without stopping a script

2009-07-09 Thread Tolga I Uzuner

Dear R Users,

I've used this a long time ago but have forgotten. Trawling aroung the various 
sources somehow does not lead me to it. How can I execute an error prone 
function without stopping a script if it goes wrong ?

Thanks in advance,
Tolga


This email is confidential and subject to important disclaimers and
conditions including on offers for the purchase or sale of
securities, accuracy and completeness of information, viruses,
confidentiality, legal privilege, and legal entity disclaimers,
available at http://www.jpmorgan.com/pages/disclosures/email.  
[[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] Extracting a column name in loop?

2009-07-09 Thread mister_bluesman

Thank you both for that. Much appreciated.


mister_bluesman wrote:
> 
> Hi,
> 
> I am writing a script that will address columns using syntax like: 
> 
> data_set[,1] 
> 
> to extract the data from the first column of my data set, for example.
> This code will be placed in a loop (where the column reference will be
> placed by a variable). 
> 
> What I also need to do is extract the column NAME for a given column being
> processed in the loop. The dataframe has been set so that R knows that the
> top line refers to column headers. 
> 
> Can anyone help me understand how to do this?
> 
> Thanks.
> 

-- 
View this message in context: 
http://www.nabble.com/Extracting-a-column-name-in-loop--tp24393160p24407422.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] assigning vector name by increasing index in loop

2009-07-09 Thread cbc123

Hello

I have a large data table that I wish to divide in to vectors, as in 
 v1 v2 v3 v4 v5
id11   2  34   5
id26  7   8   9  10

newv1 <- c(table[1,1], table[3,1], table [5,1])
newv2<-c(table[1,2], table[3,2]. table[5,2])

...and so forth.  How do I do this using a loop?
-- 
View this message in context: 
http://www.nabble.com/assigning-vector-name-by-increasing-index-in-loop-tp24410532p24410532.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] math symbols in R

2009-07-09 Thread Bert Gunter
?plotmath

Bert Gunter
Genentech Nonclinical Biostatistics


-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On
Behalf Of Mary A. Marion
Sent: Thursday, July 09, 2009 12:04 PM
To: r-help@r-project.org
Subject: [R] math symbols in R

Hello,

I would like R software to printout a sentence including a statement such as
Ho: mu=5 vs Ha: mu ne 5 where ne stands for the math symbol notequal
and mu is greek letter for u.  How to do?  Most of the help questions I have
seen  have been those involving graphs.

Thank you.
Sincerely,
Mary A. Marion

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Creating and Using Objects in R

2009-07-09 Thread Lorenzo Isella

Dear All,
I am not very into object-oriented programming, but I would like to 
learn the ropes for some R applications.

Quoting from the online R language definition (paragraph 5.1)

Consider the following simple example. A point in two-dimensional 
Euclidean space can be specified by its Cartesian (x-y) or polar 
(r-theta) coordinates. Hence, to store information about the location 
of the point, we could define two classes, |"xypoint"| and 
|"rthetapoint"|. All the `xypoint' data structures are lists with an 
x-component and a y-component. All `rthetapoint' objects are lists 
with an r-component and a theta-component.


Now, suppose we want to get the x-position from either type of object. 
This can easily be achieved through generic functions. We define the 
generic function |xpos| as follows.


 xpos <- function(x, ...)
 UseMethod("xpos")
  


Now we can define methods:

 xpos.xypoint <- function(x) x$x
 xpos.rthetapoint <- function(x) x$r * cos(x$theta)
  

The user simply calls the function |xpos| with either representation 
as the argument. The internal dispatching method finds the class of 
the object and calls the appropriate methods.


I am a bit confused: when calling e.g. xpos.rthetapoint, I understand 
that x contains the polar representation of a point, so x=(r,theta), 
but  how do I exactly  write it to pass it to xpos.rthetapoint? I have 
made several attempts, but so far none of them works, so I may have 
misunderstood something.

Many thanks

Lorenzo

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] correct way to subset a vector

2009-07-09 Thread Marc Schwartz

On Jul 9, 2009, at 10:40 AM, Juliet Hannah wrote:


Hi,

#make example data
dat <- data.frame(matrix(rnorm(15),ncol=5))
colnames(dat) <- c("ab","cd","ef","gh","ij")

If I want to get a subset of the data for the middle 3 columns, and I
know the names of the start column and the end column, I can do this:

mysub <- subset(dat,select=c(cd:gh))

If I wanted to do this just on the column names, without subsetting
the data, how could I do this?

mynames <- colnames(dat);

#mynames
#[1] "ab" "cd" "ef" "gh" "ij"

Is there an easy way to create the vector c("cd","ef","gh") as I did
above using something similar to cd:gh?

Thanks,

Juliet




Using the same presumption that the desired values are consecutive in  
the vector:


# Use which() to get the indices for the start and end of the subset
> mynames[which(mynames == "cd"):which(mynames == "gh")]
[1] "cd" "ef" "gh"


You can encapsulate that in a function:

subset.vector <- function(x, start, end)
{
  x[which(x == start):which(x == end)]
}

> subset.vector(mynames, "cd", "gh")
[1] "cd" "ef" "gh"



Note that you can also do this:

> names(subset(dat, select = cd:gh))
[1] "cd" "ef" "gh"

but that actually goes through the process of subsetting the data  
frame first, which potentially introduces a lot of overhead and memory  
use if the data frame is large. It also presumes that the desired  
vector is a subset of the column names of the initial data frame.



To use the same sequence based approach as is used in  
subset.data.frame(), you can do what is used internally within that  
function:


subset.vector <- function(x, select)
{
  nl <- as.list(1L:length(x))
  names(nl) <- x
  vars <- eval(substitute(select), nl)
  x[vars]
}


> subset.vector(mynames, select = cd:gh)
[1] "cd" "ef" "gh"



BTW, well done on recognizing that you can use the sequence of column  
names for the 'select' argument. A lot of folks, even experienced  
useRs, don't realize that you can do that...  :-)


HTH,

Marc Schwartz

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Logistic Regression: Likelihoo-Ratio Based Confidence Intervals

2009-07-09 Thread alex the lipenator
Hello!

I hope this email finds you all well.  I have a rather elementary question.  I 
am interested in obtaining likelihood ratio-based confidence intervals of 
logistic regression parameter estimates (i.e., the MLE).  How do I specify 
likelihood ratio CIs in the "confint()" function, or do I need to use some 
other function?

Thank you for your time,

Alex

 



  
[[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] math symbols in R

2009-07-09 Thread Mary A. Marion

Hello,

I would like R software to printout a sentence including a statement such as
Ho: mu=5 vs Ha: mu ne 5 where ne stands for the math symbol notequal
and mu is greek letter for u.  How to do?  Most of the help questions I have
seen  have been those involving graphs.

Thank you.
Sincerely,
Mary A. Marion

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

2009-07-09 Thread Uwe Ligges



Daniel Malter wrote:

put another condition in your loop

if(all.equal(x,y)=TRUE) i=i+1 else t.test...

something in that direction.



Sorry, but that's neither valid R code nor sensible in this case.
See my suggestions below.





best,
daniel 



-
cuncta stricte discussurus
-

-Ursprüngliche Nachricht-
Von: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] Im
Auftrag von Amit Patel
Gesendet: Thursday, July 09, 2009 9:20 AM
An: r-help@r-project.org
Betreff: [R] T.test error help


Hi I am implementing the t.test in a loop and where the data is the same i
get an error message. 

Error in t.test.default(Samp3, Samp1, na.rm = TRUE, var.equal = FALSE,  : 
  data are essentially constant


The script i am using is 


for (i in 1:length(zz[,1])) {



for(i in seq_along(zz[,1])){

should be safer.



Samp1 <- zz[i,2:17]
Samp2 <- zz[i,18:33]
Samp3 <- zz[i,34:47]
Samp4 <- zz[i,48:63] 


TTestResult[i,2] <- t.test(Samp2, Samp1, na.rm=TRUE, var.equal = FALSE,
paired=FALSE, conf.level=0.95)$p.value


TTestResult[i,3] <- t.test(Samp3, Samp1, na.rm=TRUE, var.equal = FALSE,
paired=FALSE, conf.level=0.95)$p.value

TTestResult[i,4] <- t.test(Samp4, Samp1, na.rm=TRUE, var.equal = FALSE,
paired=FALSE, conf.level=0.95)$p.value

}

Is there a way to make my loop ignore this problem and go onto the next
iteration



yes, you can wrap it in try() and check the object with
if(inherits(object, "try-error")) later on in order to do something 
different (e.g. assign an NA) in case of an error.


Uwe Ligges







__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] wordStem problems in R 2.9, Fedora 11; Linux Kernel 2.6.29.5-191.fc11.i586

2009-07-09 Thread Reitsma, Rene - COB
Duncan,

Thanks for helping. I reinstalled Rstem from source (using the omegahat
URL) and this time things are working. :-)

RR

 

-Original Message-
From: Duncan Temple Lang [mailto:dun...@wald.ucdavis.edu] 
Sent: Tuesday, July 07, 2009 5:33 PM
To: Reitsma, Rene - COB
Cc: r-help@r-project.org
Subject: Re: [R] wordStem problems in R 2.9, Fedora 11; Linux Kernel
2.6.29.5-191.fc11.i586

Hi Rene

   Can you tell us the version of the Rstem package you installed.
Rstem_0.3-1 from
  http://www.omegahat.org/Rstem/

or

 install.packages("Rstem", repos = "http://www.omegahat.org/R";)

work fine for me.

I seem to recall this being a problem with an older version of Rstem.

   D.

Reitsma, Rene - COB wrote:
> Dear All,
> 
> I just updated from Fedora 9 to Fedora 11, kernel version
> 2.6.29.5-191.fc11.i586. I'm running R 2.9.
> 
> I successfully installed package Rstem from source (it always ran fine
> for me in F9). However:
> 
>> wordStem(c("This","is","a","test"))
> Error in wordStem(c("This", "is", "a", "test")) : 
>   VECTOR_ELT() can only be applied to a 'list', not a 'character'
> 
> Any idea what causes this / how I can fix this?
> 
> RR
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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] correct way to subset a vector

2009-07-09 Thread Steve Lianoglou

Hi,

On Jul 9, 2009, at 11:40 AM, Juliet Hannah wrote:


Hi,

#make example data
dat <- data.frame(matrix(rnorm(15),ncol=5))
colnames(dat) <- c("ab","cd","ef","gh","ij")

If I want to get a subset of the data for the middle 3 columns, and I
know the names of the start column and the end column, I can do this:

mysub <- subset(dat,select=c(cd:gh))

If I wanted to do this just on the column names, without subsetting
the data, how could I do this?

mynames <- colnames(dat);

#mynames
#[1] "ab" "cd" "ef" "gh" "ij"

Is there an easy way to create the vector c("cd","ef","gh") as I did
above using something similar to cd:gh?


How about just taking your mynames vector? eg:

R> mynames[2:4]
[1] "cd" "ef" "gh"

R> dat[, mynames[2:4]]
  cd ef  gh
1  1.7745386  1.0958930 -0.07213304
2  0.7480372 -0.1364458 -0.62848211
3 -0.5477843  1.5811382 -0.74404103

-steve

--
Steve Lianoglou
Graduate Student: Physiology, Biophysics and Systems Biology
Weill Medical College of Cornell University

Contact Info: http://cbio.mskcc.org/~lianos

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

2009-07-09 Thread Daniel Malter
put another condition in your loop

if(all.equal(x,y)=TRUE) i=i+1 else t.test...

something in that direction.

best,
daniel 


-
cuncta stricte discussurus
-

-Ursprüngliche Nachricht-
Von: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] Im
Auftrag von Amit Patel
Gesendet: Thursday, July 09, 2009 9:20 AM
An: r-help@r-project.org
Betreff: [R] T.test error help


Hi I am implementing the t.test in a loop and where the data is the same i
get an error message. 

Error in t.test.default(Samp3, Samp1, na.rm = TRUE, var.equal = FALSE,  : 
  data are essentially constant

The script i am using is 

for (i in 1:length(zz[,1])) {

Samp1 <- zz[i,2:17]
Samp2 <- zz[i,18:33]
Samp3 <- zz[i,34:47]
Samp4 <- zz[i,48:63] 

TTestResult[i,2] <- t.test(Samp2, Samp1, na.rm=TRUE, var.equal = FALSE,
paired=FALSE, conf.level=0.95)$p.value


TTestResult[i,3] <- t.test(Samp3, Samp1, na.rm=TRUE, var.equal = FALSE,
paired=FALSE, conf.level=0.95)$p.value

TTestResult[i,4] <- t.test(Samp4, Samp1, na.rm=TRUE, var.equal = FALSE,
paired=FALSE, conf.level=0.95)$p.value

}

Is there a way to make my loop ignore this problem and go onto the next
iteration





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

2009-07-09 Thread Daniel Malter

Victor, use the axes=FALSE option, as you do. Then use the "labels" and "at"
options in the "axis" argument to place the tickmark labels in the negative
plot manually


par(mfrow=c(1,2),bty="n",mai=c(0.5, 0.25, 0.25, 0.25))

x=rgamma(1000,10,0.3)

barplot(height=t(-x), width = 0.825, space = NULL,
names.arg = NULL, legend.text = c("Inf 95%","Mediana","Sup 95%"),
beside = FALSE,
horiz = TRUE, density = NULL, angle = 0,
axes = FALSE,
col = c("yellow","Blue","orange"), border = par("fg"),
main = "Mujeres",
xlim =NULL, ylim = NULL, xpd = TRUE, log = "",
axisnames = FALSE,
 
axis(1,hadj=NA,padj=NA,cex.axis=0.75,labels=c("0","10","20","30","40","50","
60","70"),at=c(0,-10,-20,-30,-40,-50,-60,-70)))


barplot(height=t(x), width = 0.825, space = NULL,
names.arg = NULL, legend.text = c("Inf 95%","Mediana","Sup 95%"),
beside = FALSE,
axes=FALSE,
horiz = TRUE, density = NULL, angle = 0,
col = c("yellow","Blue","orange"), border = par("fg"),
main = "Mujeres",
xlim =NULL, ylim = NULL, xpd = TRUE, log = "",
axisnames = FALSE,
axis(1,cex.axis=0.75))

That should do. Best,
Daniel


-
cuncta stricte discussurus
-

-Ursprüngliche Nachricht-
Von: Victor Manuel Garcia Guerrero [mailto:vmgar...@colmex.mx] 
Gesendet: Thursday, July 09, 2009 1:44 AM
An: Daniel Malter; r-help@r-project.org
Betreff: RE: [R] Population pyramids

Yes the code is the next:

par(mfrow=c(1,2),bty="n",mai=c(0.5, 0.25, 0.25, 0.25))

barplot(height=t(icNM2005.dat), width = 0.825, space = NULL,
names.arg = NULL, legend.text = NULL, beside = FALSE,
horiz = TRUE, density = NULL, angle = 0,
col = c("yellow","Blue","orange"), border = par("fg"),
main = "Hombres",
xlim =NULL, ylim = NULL, xpd = TRUE, log = "",
axes = FALSE, axisnames = FALSE,cex.axis=0.75)
axis(1,pretty(c(-1200,0),n=12),
hadj=NA,padj=NA,cex.axis=0.75,las=2)


barplot(height=t(icNF2005.dat), width = 0.825, space = NULL,
names.arg = NULL, legend.text = c("Inf 95%","Mediana","Sup 95%"),
beside = FALSE,
horiz = TRUE, density = NULL, angle = 0,
col = c("yellow","Blue","orange"), border = par("fg"),
main = "Mujeres",
xlim =NULL, ylim = NULL, xpd = TRUE, log = "",
axes = FALSE, axisnames = FALSE,cex.axis=0.75)
axis(2,pretty(c(0:105),n=21),hadj=0.5,padj=0.5,cex.axis=0.75,
las=2)
axis(1,pretty(c(0:1200),n=5),
hadj=NA,padj=NA,cex.axis=0.5,las=1)


Víctor Manuel García Guerrero
Doctorado en Estudios de Población,
CEDUA, COLMEX
Camino al Ajusco N° 20, Pedregal de Sta. Teresa C.P.10740, Tlalpan, México,
D.F.
* : vmgar...@colmex.mx
( : 5617-9016



-Mensaje original-
De: Daniel Malter [mailto:dan...@umd.edu] Enviado el: jue 09/07/2009 12:15
Para: Victor Manuel Garcia Guerrero; r-help@r-project.org
Asunto: AW: [R] Population pyramids
 
Can you provide a self-contained example of what you did so far (i.e. code
for simulating some data and code for the plot)? That would greatly help to
help you find a solution.

Daniel 


-
cuncta stricte discussurus
-

-Ursprüngliche Nachricht-
Von: Victor Manuel Garcia Guerrero [mailto:vmgar...@colmex.mx]
Gesendet: Thursday, July 09, 2009 12:48 AM
An: Daniel Malter; r-help@r-project.org
Betreff: RE: [R] Population pyramids

Yes, but my issue is because I need to plot a pop pyramid with confidence
intervals, and the pyramid function does not work in that way. Thanks
Daniel.


-Mensaje original-
De: Daniel Malter [mailto:dan...@umd.edu] Enviado el: mié 08/07/2009 11:36
Para: Victor Manuel Garcia Guerrero; r-help@r-project.org
Asunto: AW: [R] Population pyramids
 
have you tried the pyramid function in the epicalc package?

best,
daniel 


-
cuncta stricte discussurus
-

-Ursprüngliche Nachricht-
Von: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] Im
Auftrag von Victor Manuel Garcia Guerrero
Gesendet: Thursday, July 09, 2009 12:25 AM
An: r-help@r-project.org
Betreff: [R] Population pyramids

Hi, I hope somebody can help me with this issue: I am doing population
pyramids using the barplot command, so in the left side I have male age
structure and in the right side the female age structure. To plot the male
age structure I put the data in negative numbers. Now, I want to change the
sign in the bar plot in such way that I have no-sign numbers, both in left
and right side of the graph. I have been trying all day long and I could not
succed.

Thanks...

Victor

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

[R] correct way to subset a vector

2009-07-09 Thread Juliet Hannah
Hi,

#make example data
dat <- data.frame(matrix(rnorm(15),ncol=5))
colnames(dat) <- c("ab","cd","ef","gh","ij")

If I want to get a subset of the data for the middle 3 columns, and I
know the names of the start column and the end column, I can do this:

mysub <- subset(dat,select=c(cd:gh))

If I wanted to do this just on the column names, without subsetting
the data, how could I do this?

mynames <- colnames(dat);

#mynames
#[1] "ab" "cd" "ef" "gh" "ij"

Is there an easy way to create the vector c("cd","ef","gh") as I did
above using something similar to cd:gh?

Thanks,

Juliet

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


[R] How to: initialize, setValidity, copy-constructor

2009-07-09 Thread Renaud Gaujoux

Hello list,

I'm having troubles setting up a basic calss hierarchy with S4.
Here is a simplified schema of what I'd like to do:

- Two classes: A and B that extends A
- Ensure that the slots added by B are consistent with the slots of A
- Let A initialize itself (I'm not supposed to know the internal cooking 
of A)

- By default set the slots of B based on the slots that A initialized

Another question is: what is the recommended way of implementing a 
copy-constructor in R?


I know that all of this is easily done in C++. The constructor of each 
class is called recursively back-up to the root class. Validity checks 
can be performed after/during associated initialization. 
Copy-constructor are basics in C++.


Here below is a piece of code that I thought would work (but it does 
not... therefore my post), what's wrong with it?
I think the main issue is when is the validity check performed: why is 
it performed before the end of the initialize method?


Thank you for your help.
Renaud

# define class A with a single numeric slot
setClass('A', representation(a='numeric'))

# define class B that extends class A, adding another numeric slot
setClass('B', representation('A', b='numeric'))
# we want for example to ensure that slots a and b have the same length
setValidity('B',
function(object){
cat("*** B::validate ***\n")
print(object)
cat("*\n")
if( length(obj...@a) != length(obj...@b) ) return('Inconsistent lengths')
TRUE
}
)
# As a default behaviour if b is not provided, we want slot b to be 
equal to slot a

setMethod('initialize', 'B',
function(.Object, b, ...){
cat("*** B::initialize ***\n")
print(.Object)

# Let the superclass (A) initialize itself via callNextMethod
# I thought it would only do that: initialize and optionnaly validate 
the class A part of the object

#But it generates an ERROR: apparently it calls the validation method of B,
# before leaving me a chance to set slot b to a valid value
.Object <- callNextMethod(.Object, ...)

# now deal with the class B part of the object
cat("*** Test missing b ***\n")
if( missing(b) ){
cat("*** b is MISSING ***\n")
b <- .obj...@a
}

# set slot b
.obj...@b <- b

.Object
}
)

### Testing

# empty A: OK
aObj <- new('A')
aObj

# class A with some data: OK
aObj <- new('A', a=c(1,2) )
aObj

# empty B: OK
bObj <- new('B')
bObj

# initialize B setting the slot of class A: ERROR
bObj <- new('B', a=c(1,2))

# initialize B setting only the slot class B: OK!! Whereas it produces a 
non valid object.

bObj <- new('B', b=c(1,2))
bObj

# RESULTS:

> # empty A: OK
> aObj <- new('A')
> aObj
An object of class “A”
Slot "a":
numeric(0)

>
> # class A with some data: OK
> aObj <- new('A', a=c(1,2) )
> aObj
An object of class “A”
Slot "a":
[1] 1 2

>
> # empty B: OK
> bObj <- new('B')
*** B::initialize ***
An object of class “B”
Slot "b":
numeric(0)

Slot "a":
numeric(0)

*** Test missing b ***
*** b is MISSING ***
> bObj
An object of class “B”
Slot "b":
numeric(0)

Slot "a":
numeric(0)

>
> # initialize B setting the slot of class A: ERROR
> bObj <- new('B', a=c(1,2))
*** B::initialize ***
An object of class “B”
Slot "b":
numeric(0)

Slot "a":
numeric(0)

*** B::validate ***
An object of class “B”
Slot "b":
numeric(0)

Slot "a":
[1] 1 2

*
Error in validObject(.Object) :
invalid class "B" object: Inconsistent lengths
>
> # initialize B setting only the slot class B: OK!! Whereas it creates 
a non valid object.

> bObj <- new('B', b=c(1,2))
*** B::initialize ***
An object of class “B”
Slot "b":
numeric(0)

Slot "a":
numeric(0)

*** Test missing b ***
> bObj
An object of class “B”
Slot "b":
[1] 1 2

Slot "a":
numeric(0)



-
> sessionInfo()
R version 2.9.1 (2009-06-26)
x86_64-pc-linux-gnu

locale:
LC_CTYPE=en_ZA.UTF-8;LC_NUMERIC=C;LC_TIME=en_ZA.UTF-8;LC_COLLATE=en_ZA.UTF-8;LC_MONETARY=C;LC_MESSAGES=en_ZA.UTF-8;LC_PAPER=en_ZA.UTF-8;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=en_ZA.UTF-8;LC_IDENTIFICATION=C

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

other attached packages:
[1] Biobase_2.4.1

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


Re: [R] treating a data symbol like a character

2009-07-09 Thread Andrew Yee
Great, that's a good starting point.
Andrew

On Thu, Jul 9, 2009 at 11:20 AM, Jorge Ivan Velez
wrote:

>
> Hi Andrew,
> If I understand correctly, then
>
> # Data
> x <- c(3,4,2)
>
> # Collection of text and symbols
> Text <- c('foo', 'abcd', 'John')
> PCH <- c('+','O','$')
>
> # Plotting
> plot(x, pch = PCH)
> legend('topright', pch = PCH, Text, ncol = 3)
>
> should be close to what you want. Note that the text() / points()
> combination could be avoided when using legend().
>
> Best,
>
> Jorge
>
>
> On Thu, Jul 9, 2009 at 11:08 AM, Andrew Yee <> wrote:
>
>>  Thanks for your help.
>> I should have been more clear in my initial e-mail.  I shouldn't have used
>> 'alpha' or 'beta,' to avoid confusion with them as Greek symbols.  I should
>> have stated something like:
>>
>> O foo O abcd O John
>>
>> While I'm familiar with using legend to make the filled boxes, I'm
>> interested in creating a one line "legend" of sorts, but manually using
>> text() with both data symbols defined by pch and text on the same line.  Or
>> is this not possible?  I guess at the end of the day, I could use both
>> points() and text().
>>
>> Thanks,
>> Andrew
>>
>> On Thu, Jul 9, 2009 at 11:03 AM, Jorge Ivan Velez <> wrote:
>>
>>> Hi Andrew,
>>> Do you want to put the symbols you described as a legend in a plot?  If
>>> so, here is one way:
>>>
>>> x <- rnorm(3)
>>> plot(x, pch = 16, cex = 1.1, col = 1:3)
>>> legend('topleft', ncol = 3,
>>> c(expression(alpha), expression(beta), expression(gamma)), pch =
>>> 16, cex = 1.1, col = 1:3)
>>>
>>> Is you do not want to use legend, but place the symbols in each plot,
>>> then:
>>>
>>> plot(x, pch = 16, cex = 1.1, col = 1:3)
>>> text(1.05,1.01*x[1], expression(alpha) )
>>> text(2.05,1.01*x[2], expression(beta) )
>>> text(2.95,1.01*x[3], expression(gamma) )
>>>
>>> should get you close.
>>>
>>> See ?text, ?expression and ?legend for more information.
>>>
>>> HTH,
>>>
>>> Jorge
>>>
>>>
>>>  On Thu, Jul 9, 2009 at 10:53 AM, Andrew Yee <> wrote:
>>>
  Hi, is there a way to treat a data symbol, e.g. one with pch = 16, as a
 character?
 Specifically, I'm interested in creating a line of text as follows using
 the
 text() function

 O alpha O beta O gamma

 where the "O" is pch 16 and filled with a specific color.

 Not sure if this is possible or not.

 Thanks,
 Andrew

[[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] treating a data symbol like a character

2009-07-09 Thread Jorge Ivan Velez
Hi Andrew,
If I understand correctly, then

# Data
x <- c(3,4,2)

# Collection of text and symbols
Text <- c('foo', 'abcd', 'John')
PCH <- c('+','O','$')

# Plotting
plot(x, pch = PCH)
legend('topright', pch = PCH, Text, ncol = 3)

should be close to what you want. Note that the text() / points()
combination could be avoided when using legend().

Best,

Jorge


On Thu, Jul 9, 2009 at 11:08 AM, Andrew Yee <> wrote:

> Thanks for your help.
> I should have been more clear in my initial e-mail.  I shouldn't have used
> 'alpha' or 'beta,' to avoid confusion with them as Greek symbols.  I should
> have stated something like:
>
> O foo O abcd O John
>
> While I'm familiar with using legend to make the filled boxes, I'm
> interested in creating a one line "legend" of sorts, but manually using
> text() with both data symbols defined by pch and text on the same line.  Or
> is this not possible?  I guess at the end of the day, I could use both
> points() and text().
>
> Thanks,
> Andrew
>
> On Thu, Jul 9, 2009 at 11:03 AM, Jorge Ivan Velez <> wrote:
>
>> Hi Andrew,
>> Do you want to put the symbols you described as a legend in a plot?  If
>> so, here is one way:
>>
>> x <- rnorm(3)
>> plot(x, pch = 16, cex = 1.1, col = 1:3)
>> legend('topleft', ncol = 3,
>> c(expression(alpha), expression(beta), expression(gamma)), pch =
>> 16, cex = 1.1, col = 1:3)
>>
>> Is you do not want to use legend, but place the symbols in each plot,
>> then:
>>
>> plot(x, pch = 16, cex = 1.1, col = 1:3)
>> text(1.05,1.01*x[1], expression(alpha) )
>> text(2.05,1.01*x[2], expression(beta) )
>> text(2.95,1.01*x[3], expression(gamma) )
>>
>> should get you close.
>>
>> See ?text, ?expression and ?legend for more information.
>>
>> HTH,
>>
>> Jorge
>>
>>
>>  On Thu, Jul 9, 2009 at 10:53 AM, Andrew Yee <> wrote:
>>
>>>  Hi, is there a way to treat a data symbol, e.g. one with pch = 16, as a
>>> character?
>>> Specifically, I'm interested in creating a line of text as follows using
>>> the
>>> text() function
>>>
>>> O alpha O beta O gamma
>>>
>>> where the "O" is pch 16 and filled with a specific color.
>>>
>>> Not sure if this is possible or not.
>>>
>>> Thanks,
>>> Andrew
>>>
>>>[[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] treating a data symbol like a character

2009-07-09 Thread Andrew Yee
Thanks for your help.
I should have been more clear in my initial e-mail.  I shouldn't have used
'alpha' or 'beta,' to avoid confusion with them as Greek symbols.  I should
have stated something like:

O foo O abcd O John

While I'm familiar with using legend to make the filled boxes, I'm
interested in creating a one line "legend" of sorts, but manually using
text() with both data symbols defined by pch and text on the same line.  Or
is this not possible?  I guess at the end of the day, I could use both
points() and text().

Thanks,
Andrew

On Thu, Jul 9, 2009 at 11:03 AM, Jorge Ivan Velez
wrote:

> Hi Andrew,
> Do you want to put the symbols you described as a legend in a plot?  If so,
> here is one way:
>
> x <- rnorm(3)
> plot(x, pch = 16, cex = 1.1, col = 1:3)
> legend('topleft', ncol = 3,
> c(expression(alpha), expression(beta), expression(gamma)), pch =
> 16, cex = 1.1, col = 1:3)
>
> Is you do not want to use legend, but place the symbols in each plot, then:
>
> plot(x, pch = 16, cex = 1.1, col = 1:3)
> text(1.05,1.01*x[1], expression(alpha) )
> text(2.05,1.01*x[2], expression(beta) )
> text(2.95,1.01*x[3], expression(gamma) )
>
> should get you close.
>
> See ?text, ?expression and ?legend for more information.
>
> HTH,
>
> Jorge
>
>
>  On Thu, Jul 9, 2009 at 10:53 AM, Andrew Yee  wrote:
>
>>  Hi, is there a way to treat a data symbol, e.g. one with pch = 16, as a
>> character?
>> Specifically, I'm interested in creating a line of text as follows using
>> the
>> text() function
>>
>> O alpha O beta O gamma
>>
>> where the "O" is pch 16 and filled with a specific color.
>>
>> Not sure if this is possible or not.
>>
>> Thanks,
>> Andrew
>>
>>[[alternative HTML version deleted]]
>>
>> __
>> R-help@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>
>

[[alternative HTML version deleted]]

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


[R] plm Issues

2009-07-09 Thread Damien Moore
Hi List

I'm having difficulty understanding how plm should work with dynamic
formulas. See the commands and output below on a standard data set. Notice
that the first summary(plm(...)) call returns the same result as the second
(it shouldn't if it actually uses the lagged variable requested). The third
call results in error (trying to use diff'ed variable in regression)

Other info: I'm running R 2.7.2 on WinXP

cheers



*>data("Gasoline",package="Ecdat")
>Gasoline_plm<-plm.data(Gasoline,c("country","year"))
>pdim(Gasoline_plm)
**Balanced Panel: n=18, T=19, N=342
*
*>summary(plm(lgaspcar~lincomep,data=Gasoline_plm**))
**Oneway (individual) effect Within Model

Call:
plm(formula = lgaspcar ~ lincomep, data = Gasoline_plm)

Balanced Panel: n=18, T=19, N=342

Residuals :
Min.  1st Qu.   Median  3rd Qu. Max.
-0.40100 -0.08410 -0.00858  0.08770  0.73400

Coefficients :
 Estimate Std. Error t-value  Pr(>|t|)
lincomep -0.761830.03535 -21.551 < 2.2e-16 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Total Sum of Squares: 17.061
Residual Sum of Squares: 6.9981
Multiple R-Squared: 0.58981
F-statistic: 464.442 on 323 and 1 DF, p-value: 0.036981

**> summary(plm(lgaspcar~lag(lincomep),data=Gasoline_plm))
**Oneway (individual) effect Within Model

Call:
plm(formula = lgaspcar ~ lag(lincomep), data = Gasoline_plm)

Balanced Panel: n=18, T=19, N=342

Residuals :
Min.  1st Qu.   Median  3rd Qu. Max.
-0.40100 -0.08410 -0.00858  0.08770  0.73400

Coefficients :
  Estimate Std. Error t-value  Pr(>|t|)
lag(lincomep) -0.761830.03535 -21.551 < 2.2e-16 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Total Sum of Squares: 17.061
Residual Sum of Squares: 6.9981
Multiple R-Squared: 0.58981
F-statistic: 464.442 on 323 and 1 DF, p-value: 0.036981

*
*>summary(plm(lgaspcar~diff(lincomep),data=Gasoline_plm))*
*Error in model.frame.default(formula = lgaspcar ~ diff(lincomep), data =
mydata,  :
  variable lengths differ (found for 'diff(lincomep)')
*

[[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] treating a data symbol like a character

2009-07-09 Thread Jorge Ivan Velez
Hi Andrew,
Do you want to put the symbols you described as a legend in a plot?  If so,
here is one way:

x <- rnorm(3)
plot(x, pch = 16, cex = 1.1, col = 1:3)
legend('topleft', ncol = 3,
c(expression(alpha), expression(beta), expression(gamma)), pch = 16,
cex = 1.1, col = 1:3)

Is you do not want to use legend, but place the symbols in each plot, then:

plot(x, pch = 16, cex = 1.1, col = 1:3)
text(1.05,1.01*x[1], expression(alpha) )
text(2.05,1.01*x[2], expression(beta) )
text(2.95,1.01*x[3], expression(gamma) )

should get you close.

See ?text, ?expression and ?legend for more information.

HTH,

Jorge


On Thu, Jul 9, 2009 at 10:53 AM, Andrew Yee  wrote:

> Hi, is there a way to treat a data symbol, e.g. one with pch = 16, as a
> character?
> Specifically, I'm interested in creating a line of text as follows using
> the
> text() function
>
> O alpha O beta O gamma
>
> where the "O" is pch 16 and filled with a specific color.
>
> Not sure if this is possible or not.
>
> Thanks,
> Andrew
>
>[[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

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


[R] treating a data symbol like a character

2009-07-09 Thread Andrew Yee
Hi, is there a way to treat a data symbol, e.g. one with pch = 16, as a
character?
Specifically, I'm interested in creating a line of text as follows using the
text() function

O alpha O beta O gamma

where the "O" is pch 16 and filled with a specific color.

Not sure if this is possible or not.

Thanks,
Andrew

[[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] naming of columns in R dataframe consisting of mixed data (alphanumeric and numeric)

2009-07-09 Thread Mary A. Marion
Hello,

I have an r function that creates the following dataframe tresults2.
Notice that column 1 does not have a column heading.

Tresults2:
 [,1]
estparam 18.0
nullval  20.0
. . .
ciWidth   2.04622
HalfInterval  1.02311

pertinent code:
results<-cbind( estparam, nullval, t, pv_left, pv_right, pv_two_t, 
estse, df,  cc, tbox, llim, ulim, ciWidth, HalfInterval)
tresults<-round((results),5)
tresults2<-data.frame(t(tresults))
names(tresults2)<-c("Statistic ", "Value")
tresults2

===
After transposing my dataframe tresults2 consists of 2 columns.  
Col1=alphanumeric data (this really is a variable name) and
col2=numeric data (this is value of varaiable).

how do I name columns when columns are different (alphanumeric and numeric)
to avoid the following error:

Error in names(tresults2) <- c("Statistic ", "Value") :
  'names' attribute [2] must be the same length as the vector [1]

Am I to use c( , ) or list( , ) with a dataframe?

Thank you for your help.
Sincerely,
Mary A. Marion





[[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] RDCOMClient: how to close Excel process?

2009-07-09 Thread Lauri Nikkinen
This solution worked:

nBooks <- xl[["Workbooks"]]$Count();
for (i in seq_len(nBooks))
xl[["Workbooks"]]$item(i)$Close(SaveChanges=FALSE);

from

http://www.mail-archive.com/r-help@r-project.org/msg61498.html

Thanks!

-L

2009/7/9 Lauri Nikkinen :
> Thanks again. That did not work either. I get
>
>> library(RDCOMClient)
>> xl <- COMCreate("Excel.Application")
>> wk  <- xl$Workbooks()
>> sh <- wk$Open(normalizePath("sample_file.xls"))$Sheets()$Count()
>>
>> wk$Close()
> [1] TRUE
>> xl$Quit()
> NULL
>>
>
> and there is still Excel process open in the Task manager (and
> sample_file.xls won't open).
>
> -L
>
> 2009/7/8 Henrique Dallazuanna :
>> Then, you can try this:
>>
>> xl <- COMCreate("Excel.Application")
>> wk  <- xl$Workbooks()
>> sh <- wk$Open(normalizePath("sample_file.xls"))$Sheets()$Count()
>>
>> wk$Close()
>> xl$Quit()
>>
>>
>>
>> On Wed, Jul 8, 2009 at 10:19 AM, Lauri Nikkinen 
>> wrote:
>>>
>>> Thanks but that did not work. xl$Quit() does not kill the Excel
>>> process and sample_file.xls will not open.
>>>
>>> I'm using Windows XP SP2 and R 2.8.1
>>>
>>> -L
>>>
>>> 2009/7/8 Henrique Dallazuanna :
>>> > Try this:
>>> >
>>> > xl$Quit()
>>> >
>>> > On Wed, Jul 8, 2009 at 10:06 AM, Lauri Nikkinen 
>>> > wrote:
>>> >>
>>> >> Hi,
>>> >>
>>> >> I’m using R package RDCOMClient (http://www.omegahat.org/RDCOMClient/)
>>> >> to retrieve data from MS Excel workbook. I’m using the code below to
>>> >> count the number of sheets in the workbook and then loop the data from
>>> >> sheets in to a list.
>>> >>
>>> >> # R code ###
>>> >> library(gdata)
>>> >> library(RDCOMClient)
>>> >>
>>> >> xl <- COMCreate("Excel.Application")
>>> >> sh <-
>>> >> xl$Workbooks()$Open(normalizePath("sample_file.xls"))$Sheets()$Count()
>>> >>
>>> >> DF.list <- list()
>>> >> for (i in 1:sh) {
>>> >>   DF.list[[i]] <- read.xls("sample_file.xls", sheet=i,
>>> >> stringsAsFactors = FALSE)
>>> >>   }
>>> >> ##
>>> >>
>>> >> COMCreate opens Excel process and it can be seen from Windows Task
>>> >> Manager. When I try to open sample_file.xls in Excel, it just flashes
>>> >> in the screen and shuts down. When I kill (via task manager) the Excel
>>> >> process COMCreate started, sample_file.xls will open normally.
>>> >>
>>> >> The question is, how can I close the Excel process COMCreate started.
>>> >> xl$Close() doesn’t seem to work. The same problem have been presented
>>> >> in this post to R-help:
>>> >> http://tolstoy.newcastle.edu.au/R/help/06/04/25990.html
>>> >>
>>> >> -L
>>> >>
>>> >> __
>>> >> R-help@r-project.org mailing list
>>> >> https://stat.ethz.ch/mailman/listinfo/r-help
>>> >> PLEASE do read the posting guide
>>> >> http://www.R-project.org/posting-guide.html
>>> >> and provide commented, minimal, self-contained, reproducible code.
>>> >
>>> >
>>> >
>>> > --
>>> > Henrique Dallazuanna
>>> > Curitiba-Paraná-Brasil
>>> > 25° 25' 40" S 49° 16' 22" O
>>> >
>>
>>
>>
>> --
>> Henrique Dallazuanna
>> Curitiba-Paraná-Brasil
>> 25° 25' 40" S 49° 16' 22" O
>>
>

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


Re: [R] Dantzig Selector

2009-07-09 Thread roger koenker

There is an experimental version available here:

http://www.econ.uiuc.edu/~roger/research/sparse/sfn.html

that uses the interior point code in the package quantreg.  There is
an option to exploit possible sparsity of the X matrix.

Comments would be welcome.


url:www.econ.uiuc.edu/~rogerRoger Koenker
email   rkoen...@uiuc.edu   Department of Economics
vox:217-333-4558University of Illinois
fax:217-244-6678Champaign, IL 61820


On Jul 8, 2009, at 6:35 PM, tzygmund mcfarlane wrote:


Hi,

I was wondering if there was an R package or routines for the Dantzig
Selector (Candes & Tao, 2007). I know Emmanuel Candes has Matlab
routines to do this but I was wondering if someone had ported those to
R.

Thanks,

T

---Reference---

@article{candes2007dantzig,
 title={{The Dantzig selector: statistical estimation when p is much
larger than n}},
 author={Candes, E. and Tao, T.},
 journal={Annals of Statistics},
 volume={35},
 number={6},
 pages={2313--2351},
 year={2007},
 publisher={Hayward, Calif.[etc] Institute of Mathematical  
Statistics [etc]}

}

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] heatmap.2: question regarding the "raw z-score"

2009-07-09 Thread James W. MacDonald

Hi Chrysanthi,

Chrysanthi A. wrote:


Thanks a lot..! What exactly the sweep function is doing? Also, is there 
a possibility instead of using the mean of the whole row to get only the 
mean of a group of the row values? So the values in the matrix (heat 
map) used in the comparison are z-scores and not the intensities of the 
gene expressions, right? 


I was trying to give a subtle hint below, but maybe I should be a bit 
more blunt. One of the coolest things about R is that it is free, and 
there are these sweet listservs where people give advice and help for 
free as well.


HOWEVER, there is still a price to pay, and that is with your time. All 
of these functions have help pages that the developers spent time 
writing, and the code is there for you to peruse. Because of this, there 
is some expectation that you would have done so prior to asking 
questions. Now I have read the help page for sweep, and quite frankly it 
is a bit confusing. The term 'sweep' is used without definition, so if 
one doesn't know what that means the help page is less than helpful. But 
it doesn't take much time or effort to empirically see what it does:


> a <- matrix(rnorm(25), ncol=5)
> a
   [,1]   [,2]   [,3][,4][,5]
[1,]  0.6841637 -1.0590185 -0.1719887 -0.01916011 -1.61936817
[2,]  0.5707217  1.4790968  1.6736991 -0.72158518  1.22467334
[3,]  0.4440499 -0.3382888 -0.1504191  0.32140022  1.83780859
[4,] -0.6659568  3.0573678 -1.5709904 -1.35618488 -0.01717017
[5,] -0.3182206  2.2777597 -0.2325356 -0.02001414  1.77440090
> rm <- rowMeans(a)
> rm
[1] -0.4370743  0.8453211  0.4229102 -0.1105869  0.6962780
> sweep(a, 1, rm, "-")
[,1]   [,2]   [,3]   [,4][,5]
[1,]  1.12123808 -0.6219441  0.2650857  0.4179142 -1.18229384
[2,] -0.27459943  0.6337756  0.8283779 -1.5669063  0.37935220
[3,]  0.02113977 -0.7611990 -0.5733293 -0.1015100  1.41489842
[4,] -0.55536988  3.1679546 -1.4604035 -1.2455980  0.09341672
[5,] -1.01449866  1.5814817 -0.9288137 -0.7162922  1.07812286

For your second question:

?heatmap.2




Also, as I can understand from the code, heatmap is using distfun 
function for the clusering. Can I use pearson correlation for the 
clustering? My main object of using the heatmap is to examine the 
expression levels of the marker genes and to confirm that the marker 
genes are clearly differentially expressed in the two subtypes of the 
disease that I examine.


No, heatmap.2() is not using distfun for the clustering. There isn't a 
function by that name in either gplots nor base R. If you look at the 
help page, you can see that distfun is an argument to the function, and 
the default is to use the dist() function.


You can use Pearson correlation, but in my experience it takes some 
work. Again, if you read the help page, you can see that the Rowv and 
Colv arguments can be one of TRUE, FALSE, NULL, or a dendrogram. So if 
you want to use Pearson correlation, you should supply heatmap.2() with 
dendrograms produced using that correlation. So an example:


a <- matrix(rnorm(50), ncol=5)
rowv <- as.dendrogram(hclust(as.dist(1-cor(t(a)
colv <- as.dendrogram(hclust(as.dist(1-cor(a
heatmap.2(a, scale="row", Rowv=rowv, Colv=colv)

Best,

Jim





Many thanks,

Chrysanthi.


2009/7/8 James W. MacDonald >


Hi Chrysanthi,


Chrysanthi A. wrote:

Hi,

I am analysing gene expression data using the heatmap.2 function
in R and I
was wondering what is the formula of the "raw z-score" bar which
shows the
colors for each pixel.
According to that post:

https://mailman.stat.ethz.ch/pipermail/r-help/2006-September/113598.html,
it
is the

(actual value - mean of the group) / standard deviation.

But, mean of which group? Mean of the gene vector? And actual
value of that
gene on a sample?  I would be grateful if you could give me some
more
details about it or even if there is a book/manual that I could
address
to..


How about looking at the code?

   if (scale == "row") {
   retval$rowMeans <- rm <- rowMeans(x, na.rm = na.rm)
   x <- sweep(x, 1, rm)
   retval$rowSDs <- sx <- apply(x, 1, sd, na.rm = na.rm)
   x <- sweep(x, 1, sx, "/")
   }
   else if (scale == "column") {
   retval$colMeans <- rm <- colMeans(x, na.rm = na.rm)
   x <- sweep(x, 2, rm)
   retval$colSDs <- sx <- apply(x, 2, sd, na.rm = na.rm)
   x <- sweep(x, 2, sx, "/")
   }

So the z-score is calculated on either the row or column (or the
default of "none").

I don't see how you can get something saying 'raw z-score'. I get
either 'Row Z-Score' or 'Column Z-Score'. So assuming you meant Row
Z-Score, then the rows are centered and scaled by subtracting the
mean of the row from every value and then dividing the resu

  1   2   >