[R] [R-pkgs] General mixed effects Cox models

2009-10-04 Thread Terry Therneau
After an extremely long gestation, a new version of the coxme package is
now available on CRAN.  This function fits very general mixed-effects
Cox models using an lmer-like syntax.  For instance here is a model that
fits a random treatment effect, using data from a multi-study
collaboration.

   fit <- coxme(Surv(pg.time, pg.stat) ~ stage + trt + (trt|site) +
 stata(site), data= multicolon)

The program allows for multiple random effects, and differing variance
structures for them.  It currently has a fairly simple vignette showing
how to use the package; I'll be improving this to include more examples
over the next few months.  

Terry Therneau
Mayo Clinic

___
R-packages mailing list
r-packa...@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-packages

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

2009-10-04 Thread RAVI KAPOOR
Hi

Can anyone please help me in understanding the utility of  "padj" and "outer
(logical)" values in the '*mtext function*'
given below are the output I generated on using the below code which is
different from the formula description on r help

> par(mfrow=c(2,1),xpd=NA)
> y1 <- rnorm(100)
> plot(y1,ann=F,axes=F,type="l")
> box(col="blue")
> mtext("aone",side=1,padj=0)
> mtext("aone",side=1,padj=1)
> mtext("aone",side=2,padj=1)
> mtext("aone",side=2,padj=0)

and the output is in the attached jpeg
This is different from the r help description
padj adjustment for each string perpendicular to the reading direction
(which is controlled by adj). For strings parallel to the axes, padj =
0means right or top alignment, and padj
= 1 means left or bottom alignment.
Also please explain the utility of setting outer = TRUE/FALSE # I know that
logical values permit/prohibit use of outer region but again I am unable to
see that happening

 plot(y1,ann=F,axes=F,type="l")
> box(col="blue")
> mtext("aone",side=1,adj=0,outer=F)
> mtext("aone",side=1,adj=0,outer=T)
> # nothing changes when I change the settings of outer from false to true-
why?
> mtext("aone",side=3,adj=0,outer=T)
> # again nothing happens why?
> mtext("aone",side=3,adj=0,outer=F)

(please see mtext2.jpg for the output that I am generating for different
logical values of Outer)

Thanks in advance for the help
Regards
Ravi



__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Saving each output of a loop into something that can be graphed

2009-10-04 Thread RRRRRR99

Hi, 

from the code below; whats happening is i want to plot how the [1,9] entry
changes as the matrx changes, print[] gives the values one after the other,
but only the last value is saved so my graph has only one point. does anyone
know how i can merge all the outputs into one dataframe or something?

Q<-matrix(c(-0.59,5.44,0,0,0,0,0,0,0,0.59,-8.16,2.51,0,0,0,0,0,0,0,2.72,-5.64,9.45,0,0,0,0,0,0,0,3.13,-13.23,6.91,0,0,0,0,0,0,0,3.15,-14.88,10.22,0,0,0,0,0,0,0.63,7.97,-19.81,30.19,0,96.77,0,0,0,0,0,7.67,-98.12,0,19.35,0,0,0,0,0,0,37.74,-315.79,0,0,0,0,0,0,1.92,30.19,315.79,-116.12),nrow=9,ncol=9)
T<-Q*.01
for (i in (1:10)){
R<-MatrixExp(i*T)
S<-print(R[1,9])
}


any help would be greatly appreciated.
-- 
View this message in context: 
http://www.nabble.com/Saving-each-output-of-a-loop-into-something-that-can-be-graphed-tp25745700p25745700.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] The nature of evidence (was Re: Urgently needed Exercise solutions related to PracticalData)

2009-10-04 Thread Patrick Connolly
On Sat, 03-Oct-2009 at 11:35PM -0400, Daniel Malter wrote:

|> This person has probably mistaken "expelsior" for "excelsior." 
|> 
|> However, be that as it may, I am personally annoyed by your
|> statement, David, in which you indicate that you believe this to be
|> an MBA/business school problem, especially since the delinquent
|> clearly indicates in his post - for which YOU have provided the
|> link - that he is a computer science student, and also because it
|> is presented without any evidence (which is particularly ironic
|> because this list is for helping with a program that analyzes
|> "evidence"). 

In fairness to David, what is the evidence that the OP really *is* a
computer science student?  Something tells me not to believe a word
coming from the "evidence" Daniel uses.  The idea of an MBA student
showing how diverse his skills are by getting enough credits to pass a
computer science qualification is not that far-fetched.  Being able to
wing an MBA-type job with such a qualification would be somewhat
easier than winging a computer science job.

On balance, I'd say the evidence for David's postulate is at least as
good as it is for the null.


|> I say that with the full consciousness and great respect that I
|> have for your numerous, very helpful contributions to this list
|> and, personally, to problems I had, but I don't think that this
|> uppity disciplinary attitude is appropriate.
|> 
|> Daniel
|> 
|> -
|> cuncta stricte discussurus
|> -
|> 
|> -Ursprüngliche Nachricht-
|> Von: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] Im
|> Auftrag von David Winsemius
|> Gesendet: Saturday, October 03, 2009 9:48 PM
|> An: Mahesh Krishnan
|> Cc: r-help@r-project.org
|> Betreff: Re: [R] Urgently needed Exercise solutions related to PracticalData
|> Analysis Using R Statisctial Software
|> 
|> 
|> On Oct 3, 2009, at 8:31 PM, Mahesh Krishnan wrote:
|> 
|> > Hello,
|> >
|> > Can anybody help me in solving these exercises on regular basis paid 
|> > or unpaid basis.
|> > If he/she want to pay by PayPal then it should be noticed that mention 
|> > at this email kindly your paypal email account where one can transfer 
|> > money in all cases.
|> >
|> > But please respect the deadline in al cases.. *Dealine for this 
|> > assignment is 07.10.09.* *If it is paid based then kindly let me know 
|> > a decent price for this ..*
|> >
|> > Regard,
|> > Mahesh
|> 
|> Mahesh has also posted this at:
|> http://www.odesk.com/jobs/Practical-Data-Analysis-Statistical-software-data-
|> analysis-needed_
|> ~~ee9e750d03fe4303?source=rss
|> 
|> And is offering payment for a longer term for "Solving Exercises for a
|> student on regular basis!
|> Estimated Workload:As needed - Less than 10 hrs/week Estimated
|> Duration:3 to 6 months Last Buyer Activity:September 15, 2009"
|> 
|> Who could resist with the average fee of $11.64?
|> 
|> It's probably a life strategy. Pay your way through your business school
|> homework exercises and then hire someone to do all your technical work once
|> you get a management position.
|> 
|> -- 
|> 
|> David Winsemius, MD
|> Heritage Laboratories
|> West Hartford, CT
|> 
|> __
|> R-help@r-project.org mailing list
|> https://stat.ethz.ch/mailman/listinfo/r-help
|> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
|> and provide commented, minimal, self-contained, reproducible code.
|> 
|> __
|> R-help@r-project.org mailing list
|> https://stat.ethz.ch/mailman/listinfo/r-help
|> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
|> and provide commented, minimal, self-contained, reproducible code.

-- 
~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.   
   ___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.


Re: [R] Parsing Files in R (USGS StreamFlow data)

2009-10-04 Thread stephen sefick
Thanks for the help - this was my goal sorry for not being straight
forward enough

#021973269 is the Waynesboro Gauge on the Savannah River Proper (SRS)
#02102908 is the Flat Creek Gauge (ftbrfcms)
#02133500 is the Drowning Creek (ftbrbmcm)
#02341800 is the Upatoi Creek Near Columbus (ftbn)
#02342500 is the Uchee Creek Near Fort Mitchell (ftbn)
#02203000 is the Canoochee River Near Claxton (ftst)

L <- 
readLines("http://waterdata.usgs.gov/nwis/uv?format=rdb&period=60&site_no=021973269,02102908,02133500,02341800,02342500,02203000";)

#look for the data with USGS in front of it (this take advantage of
the agency column)
L.USGS <- grep("^USGS", L, value = TRUE)
DF <- read.table(textConnection(L.USGS), fill = TRUE)
DF <- data.frame(DF)

DF[DF==21973269] <- "Waynesboro Gauge on the Savannah River Proper (SRS)"
DF[DF==2102908] <- "Flat Creek Gauge (ftbrfcms)"
DF[DF==2133500] <- "Drowning Creek (ftbrbmcm)"
DF[DF==2341800] <- "Upatoi Creek Near Columbus (ftbn)"
DF[DF==2342500] <- "Uchee Creek Near Fort Mitchell (ftbn)"
DF[DF==2203000] <- "Canoochee River Near Claxton (ftst)"

colnames(DF) <- c("agency", "gauge", "date", "time", "gauge_height",
"discharge", "precipitation")

dts <- as.character(DF[,"date"])
tms <- as.character(DF[,"time"])
date_time <- as.chron(paste(dts, tms), "%Y-%m-%d %H:%M")
DF <- data.frame(date_time, DF)
library(ggplot2)
qplot(as.POSIXct(date_time), discharge, data=DF,
geom="line")+facet_wrap(~gauge,
scales="free_y")+coord_trans(y="log10")

On Sun, Oct 4, 2009 at 9:20 PM, Rolf Turner  wrote:
>
> On 5/10/2009, at 2:49 PM, stephen sefick wrote:
>
>> http://waterdata.usgs.gov/nwis/uv?format=rdb&period=7&site_no=021973269
>>
>> I would like to be able to parse this file up:
>>
>> I can do this
>> x <-
>> read.table("http://waterdata.usgs.gov/nwis/uv?format=rdb&period=7&site_no=021973269";,
>> skip=26)
>>
>> but If I add another gauge to this
>>
>> x <-
>> read.table("http://waterdata.usgs.gov/nwis/uv?format=rdb&period=7&site_no=021973269,06018500";,
>> skip=26)
>> It does not work because there are two files appended to each other.
>>
>> It would be easy enough to write the code so that each individual
>> gauge would be read in as a different file, but is there a way to get
>> this information in using the commented part of the file to give the
>> headers?  This is probably a job for some other programing language
>> like perl, but I don't know perl.
>>
>> any help would be very helpful.
>
> I'm completely clear what's going on here --- (a) I'm not sure what you mean
> by
> ``using the commented part of the file to give the headers''; the headers
> are not ``commented'', and (b) I'm puzzled by the fact that there are 9
> column
> headers/field names, but only 7 columns/fields.
>
> Be that as it were, here's what I'd do:
>
> x <-
> read.table("http://waterdata.usgs.gov/nwis/uv?format=rdb&period=7&site_no=021973269";,
>                 skip=23,nrows=1,header=TRUE,check.names=FALSE)
> y <-
> read.table("http://waterdata.usgs.gov/nwis/uv?format=rdb&period=7&site_no=021973269",skip=26)
> names(y) <- names(x)[1:7]
>
> This ***appears*** to give a reasonably sensible data frame.
>
> Is this anything like what you want?
>
>        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
> ##
>



-- 
Stephen Sefick

Let's not spend our time and resources thinking about things that are
so little or so large that all they really do for us is puff us up and
make us feel like gods.  We are mammals, and have not exhausted the
annoying little problems of being mammals.

-K. Mullis

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Modify base R functions in Rprofile.site

2009-10-04 Thread Yihui Xie
Hi Charlie,

Thanks a lot! Your "dark voodoo" really helps!

And also, thanks so much to Duncan for your detailed explanation!
Finally I used Charlie's trick to modify makeRweaveLatexCoderunner(),
and has left parse() & deparse() untouched.

Regards,
Yihui
--
Yihui Xie 
Phone: 515-294-6609 Web: http://yihui.name
Department of Statistics, Iowa State University
3211 Snedecor Hall, Ames, IA



On Sun, Oct 4, 2009 at 5:51 PM, cls59  wrote:
>
>
> Yihui Xie wrote:
>>
>>
>> Thanks a lot, Charlie. What a coincidence -- I'm also working on
>> Sweave functions. parse() and deparse() can make the code more tidy
>> (they are used in source() and RweaveLatexRuncode()),
>>
>>> RweaveLatex
>> function ()
>> {
>>     list(setup = RweaveLatexSetup, runcode = RweaveLatexRuncode,
>>         writedoc = RweaveLatexWritedoc, finish = RweaveLatexFinish,
>>         checkopts = RweaveLatexOptions)
>> }
>> 
>>
>> but we can either (1) let R automatically 'tidy up' our code and
>> remove all the comments or (2) keep the comments but leave the
>> original code untouched.
>>
>> I worked out a trick to preserve the comments while tidying up the R
>> code, and I want to replace parse() and deparse() with my customized
>> functions, in which case Sweave will keep the comments.
>>
>> However, my functions will need base::parse() and base::deparse() to
>> help me, therefore my real difficulty is, how to let Sweave use my
>> functions to parse and deparse R code without really modifying them in
>> the base enviroment? I'm using the command 'R CMD Sweave'.
>>
>>
>
> Well, if you want to alter the behavior of RweaveLatexRunCode(), it can be
> done from within a Sweave file. This happens to be what I did to Sweave-- I
> wanted a little more control over the specifics of how it formatted code
> chunk output in the .tex file. The steps involved are:
>
> 1. Make a copy of the Sweave function makeRweaveLatexCoderunner(). Patch it
> so that it generates a RweaveLatexRuncode() function of your liking.
>
> 2. Overwrite utils:::makeRweaveLatexCodeRunner using the method I described
> previously.
>
> 3. Generate a new code runner function using your patched version of
> makeRweaveLatexCodeRunner().
>
> 4. Search all environments for old versions of RweaveLatexRuncode() and
> replace them with your patched one.
>
> An example of this approach is used to build the tikzDevice vignette, you
> can view it at:
>
> http://github.com/Sharpie/RTikZDevice/blob/master/inst/doc/tikzDevice.Rnw
>
> Look for the line that says "Begin Mother of All R Hacks".
>
>
>
>
> Yihui Xie wrote:
>>
>>
>> If there is no neat approach, I'll change my question to: how to write a
>> package,
>> say, Sweave2, that can be run using command line 'R CMD Sweave2 file'?
>>
>>
>
> This is also doable, at least for Linux and OS X systems that are installing
> from source. You need to add a Make target that installs your script, named
> Sweave2, into R_HOME/bin/ when the package is installed. This is the
> approach we took in the pgfSweave package-- you can view an example at:
>
> http://github.com/cameronbracken/pgfSweave/blob/master/src/Makevars
>
> I hope this helps!
>
> -Charlie
>
> -
> Charlie Sharpsteen
> Undergraduate
> Environmental Resources Engineering
> Humboldt State University

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


Re: [R] split-apply question

2009-10-04 Thread Kavitha Venkatesan
Thanks to everyone for the different suggestions! Very useful.

PS: The "aggregate" function based solution didnt work as-is for me, perhaps
it needs some modification?

Thanks again,


On Fri, Oct 2, 2009 at 1:51 PM, William Dunlap  wrote:

>
> > -Original Message-
> > From: r-help-boun...@r-project.org
> > [mailto:r-help-boun...@r-project.org] On Behalf Of hadley wickham
> > Sent: Friday, October 02, 2009 6:07 AM
> > To: jim holtman
> > Cc: r-help@r-project.org; Kavitha Venkatesan
> > Subject: Re: [R] split-apply question
> >
> > On Fri, Oct 2, 2009 at 4:24 AM, jim holtman
> >  wrote:
> > > try this:
> > >
> > >> x <- read.table(textConnection("x1  x2  x3
> > > + A   11.5
> > > + B   20.9
> > > + B   32.7
> > > + C   71.8
> > > + D   71.3"), header=TRUE)
> > >> closeAllConnections()
> > >> do.call(rbind, lapply(split(seq(nrow(x)), x$x1), function(.row){
> > > + x[.row[which.min(x$x2[.row])],]
> > > + }))
> > >  x1 x2  x3
> > > A  A  1 1.5
> > > B  B  2 0.9
> > > C  C  7 1.8
> > > D  D  7 1.3
> > >>
> >
> > Or, using plyr and subset
> >
> > library(plyr)
> > ddply(x, "x1", subset, x2 == min(x2))
> >
> > Hadley
>
> Since we are using min() we can use sorting tricks
>
> f3 <- function(x) {
>   x <- x[with(x, order(x1,x2)),]
>   isFirstInRun <- function(z)c(TRUE, z[-1] != z[-length(z)])
>   x[isFirstInRun(x$x1),]
> }
>
> This has the advantage that it keeps the original row names intact.
> It is quick even when there are lots of unique values in x1.
>
> Bill Dunlap
> Spotfire, TIBCO Software
> wdunlap tibco.com
> > --
> > http://had.co.nz/
> >
> > __
> > R-help@r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide
> > http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
> >
>

[[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] Gaussian Maximum Likelihood Classification

2009-10-04 Thread Alexandre Serra Barreto

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

2009-10-04 Thread Alexandre Serra Barreto

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

2009-10-04 Thread Andrew Choens
For those who don't follow Ubuntu development carefully, the first Beta for the 
next Ubuntu was recently released, so I took my home system and upgraded to 
help out with filing bugs, etc. 

Just to be clear, I am not looking for help with the upgrade process. I've had 
R, and a few miscellaneous CRAN packages installed on this computer for years. 
Today, when I loaded an R session I had developed before the upgrade, I saw 
something new in my R "welcome message".
>
>R version 2.9.2 (2009-08-24)
>Copyright (C) 2009 The R Foundation for Statistical Computing
>ISBN 3-900051-07-0
>
>R is free software and comes with ABSOLUTELY NO WARRANTY.
>You are welcome to redistribute it under certain conditions.
>Type 'license()' or 'licence()' for distribution details.
>
>R is a collaborative project with many contributors.
>Type 'contributors()' for more information and
>'citation()' on how to cite R or R packages in publications.
>
>
>This is REvolution R version 3.0.0:
>the optimized distribution of R from REvolution Computing.
>REvolution R enhancements Copyright (C) REvolution Computing, Inc.
>
>Checking for REvolution MKL:
 >- REvolution R enhancements not installed.
>For improved performance and other extensions: apt-get install revolution-r

The last part, about this being the "enhanced" version of R was . . . 
unexpected.  I have heard of this company before and now I've spent some time 
on their website. Looking at my installation, Ubuntu did not install any of 
the REvolution Computing components, although R now basically thows a warning 
every time I start it.

My question(s) for the community is this (pick any question(s) you like to 
answer: 
Should I install the REvolution Computing packages? 
Do these packages really make R faster? 
Are these packages stable? 
What are your experiences with REvolution Computing software?

I am interested in hearing from members of the community, REvolution Computing 
employees/supporters (although please ID yourself as such) and most anyone 
else. I can see what they say on their website, but I'm interested in getting 
other opinions too.

Thanks!

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


Re: [R] Parsing Files in R (USGS StreamFlow data)

2009-10-04 Thread Rolf Turner


On 5/10/2009, at 2:49 PM, stephen sefick wrote:

http://waterdata.usgs.gov/nwis/uv? 
format=rdb&period=7&site_no=021973269


I would like to be able to parse this file up:

I can do this
x <- read.table("http://waterdata.usgs.gov/nwis/uv? 
format=rdb&period=7&site_no=021973269",

skip=26)

but If I add another gauge to this

x <- read.table("http://waterdata.usgs.gov/nwis/uv? 
format=rdb&period=7&site_no=021973269,06018500",

skip=26)
It does not work because there are two files appended to each other.

It would be easy enough to write the code so that each individual
gauge would be read in as a different file, but is there a way to get
this information in using the commented part of the file to give the
headers?  This is probably a job for some other programing language
like perl, but I don't know perl.

any help would be very helpful.


I'm completely clear what's going on here --- (a) I'm not sure what  
you mean by
``using the commented part of the file to give the headers''; the  
headers
are not ``commented'', and (b) I'm puzzled by the fact that there are  
9 column

headers/field names, but only 7 columns/fields.

Be that as it were, here's what I'd do:

x <- read.table("http://waterdata.usgs.gov/nwis/uv? 
format=rdb&period=7&site_no=021973269",

 skip=23,nrows=1,header=TRUE,check.names=FALSE)
y <- read.table("http://waterdata.usgs.gov/nwis/uv? 
format=rdb&period=7&site_no=021973269",skip=26)

names(y) <- names(x)[1:7]

This ***appears*** to give a reasonably sensible data frame.

Is this anything like what you want?

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] Parsing Files in R (USGS StreamFlow data)

2009-10-04 Thread Gabor Grothendieck
Its not completely clear what you want to preserve and what you want
to eliminate but try this:

> L <- 
> readLines("http://waterdata.usgs.gov/nwis/uv?format=rdb&period=7&site_no=021973269,06018500";)

> L.USGS <- grep("^USGS", L, value = TRUE)
> DF <- read.table(textConnection(L.USGS), fill = TRUE)
> head(DF)
V1   V2 V3V4   V5   V6   V7
1 USGS 21973269 2009-09-27 00:00 6.96 4990 0.00
2 USGS 21973269 2009-09-27 00:15 6.96 4990 0.00
3 USGS 21973269 2009-09-27 00:30 6.97 5000 0.01
4 USGS 21973269 2009-09-27 00:45 6.97 5000 0.00
5 USGS 21973269 2009-09-27 01:00 6.98 5010 0.00
6 USGS 21973269 2009-09-27 01:15 6.98 5010 0.00

> pat <- "^# +([0-9]+) +([0-9]+) +(.*)"
> L.DD <- grep(pat, L, value = TRUE)
> library(gsubfn)
> DD <- strapply(L.DD, pat, c, simplify = rbind)
> head(DD)
 [,1] [,2][,3]
[1,] "01" "00065" "Gage height, feet"
[2,] "02" "00060" "Discharge, cubic feet per second"
[3,] "03" "00045" "Precipitation, total, inches"
[4,] "02" "00065" "Gage height, feet"
[5,] "05" "00060" "Discharge, cubic feet per second"


On Sun, Oct 4, 2009 at 9:49 PM, stephen sefick  wrote:
> http://waterdata.usgs.gov/nwis/uv?format=rdb&period=7&site_no=021973269
>
> I would like to be able to parse this file up:
>
> I can do this
> x <- 
> read.table("http://waterdata.usgs.gov/nwis/uv?format=rdb&period=7&site_no=021973269";,
> skip=26)
>
> but If I add another gauge to this
>
> x <- 
> read.table("http://waterdata.usgs.gov/nwis/uv?format=rdb&period=7&site_no=021973269,06018500";,
> skip=26)
> It does not work because there are two files appended to each other.
>
> It would be easy enough to write the code so that each individual
> gauge would be read in as a different file, but is there a way to get
> this information in using the commented part of the file to give the
> headers?  This is probably a job for some other programing language
> like perl, but I don't know perl.
>
> any help would be very helpful.
> regards,
>
> --
> Stephen Sefick
>
> Let's not spend our time and resources thinking about things that are
> so little or so large that all they really do for us is puff us up and
> make us feel like gods.  We are mammals, and have not exhausted the
> annoying little problems of being mammals.
>
>                                                                -K. Mullis
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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] Parsing Files in R (USGS StreamFlow data)

2009-10-04 Thread stephen sefick
http://waterdata.usgs.gov/nwis/uv?format=rdb&period=7&site_no=021973269

I would like to be able to parse this file up:

I can do this
x <- 
read.table("http://waterdata.usgs.gov/nwis/uv?format=rdb&period=7&site_no=021973269";,
skip=26)

but If I add another gauge to this

x <- 
read.table("http://waterdata.usgs.gov/nwis/uv?format=rdb&period=7&site_no=021973269,06018500";,
skip=26)
It does not work because there are two files appended to each other.

It would be easy enough to write the code so that each individual
gauge would be read in as a different file, but is there a way to get
this information in using the commented part of the file to give the
headers?  This is probably a job for some other programing language
like perl, but I don't know perl.

any help would be very helpful.
regards,

-- 
Stephen Sefick

Let's not spend our time and resources thinking about things that are
so little or so large that all they really do for us is puff us up and
make us feel like gods.  We are mammals, and have not exhausted the
annoying little problems of being mammals.

-K. Mullis

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

2009-10-04 Thread David Winsemius


On Oct 4, 2009, at 9:22 PM, Yi Du wrote:


Hi there,

I run a loop program with R and need to save the variable in each  
step into

a vector.



Data? Code?


After I ran the code, R told me that Error: cannot allocate vector
of size 266.6 Mb. Is there any solution of this kind of problem?  
Thank you

for your attention.



More memory?

Get rid of other un-needed applications?

Read the appropriate FAQ? (  ... for the OS that you have not  
mentioned.)


--


David Winsemius, MD
Heritage Laboratories
West Hartford, CT

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


Re: [R] update'ing trellis object

2009-10-04 Thread David Winsemius


On Oct 4, 2009, at 7:23 PM, David Winsemius wrote:

I wonder if you noticed that you had managed to create a "fig"  
object that has two "inside" lists by specifying first a key "list"  
which required a legend list, and then specifying a "legend" list  
that also had a key function? The solution to your specific request  
by Kortschak "nulled-out" the second of those.


A rather confused reply, I am afraid. I misattributed Lugue's posting  
to Kortschak. Lugeue obviously was aware of the structure of the fig  
object, since he correctly addressed the problem he originally posed.


--
David.



--
David

On Oct 3, 2009, at 10:35 PM, David Winsemius wrote:



On Oct 3, 2009, at 7:05 PM, Sebastian P. Luque wrote:


Hi,

I thought the following would only remove the legend element of a
trellis object, but it actually removes both the legend and key
elements:

------
fig <- xyplot(Sepal.Length ~ Petal.Length, groups=Species,  
data=iris,

   key=list(x=1, y=0.02, corner=c(1, 0), size=3, between=1,
 text=list(levels(iris$Species))),
   legend=list(inside=list(fun="draw.key", x=0, y=1,
 corner=c(0, 1),
 args=list(key=list(text=list("a)",  
cex=1.5)),

   draw=FALSE
update(fig, legend=NULL)
------


Is this the right way to remove an element from the object, using
update.trellis()?  Thanks.

It probably depends on the element. In the case of "key", it is a  
descendant of the legend list so when you make legend NULL you are  
wiping out all of its descendants as well:

> str(fig)
List of 43
snipped a few lines
$ legend   :List of 2
..$ inside:List of 5
.. ..$ fun   : chr "draw.key"
.. ..$ args  :List of 2
.. .. ..$ key :List of 6
.. .. .. ..$ x  : num 1
.. .. .. ..$ y  : num 0.02
.. .. .. ..$ corner : num [1:2] 1 0
.. .. .. ..$ size   : num 3
.. .. .. ..$ between: num 1
.. .. .. ..$ text   :List of 1
.. .. .. .. ..$ : chr [1:3] "setosa" "versicolor" "virginica"
.. .. ..$ draw: logi FALSE
.. ..$ x : num 1
.. ..$ y : num 0.02
.. ..$ corner: num [1:2] 1 0
..$ inside:List of 5
.. ..$ fun   : chr "draw.key"
.. ..$ x : num 0
.. ..$ y : num 1
.. ..$ corner: num [1:2] 0 1
.. ..$ args  :List of 2
.. .. ..$ key :List of 1
.. .. .. ..$ text:List of 2
.. .. .. .. ..$: chr "a)"
.. .. .. .. ..$ cex: num 1.5
.. .. ..$ draw: logi FALSE



Cheers,

--
Seb

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


David Winsemius, MD
Heritage Laboratories
West Hartford, CT



David Winsemius, MD
Heritage Laboratories
West Hartford, CT

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


[R] Ask about the memory size problem

2009-10-04 Thread Yi Du
Hi there,

I run a loop program with R and need to save the variable in each step into
a vector. After I ran the code, R told me that Error: cannot allocate vector
of size 266.6 Mb. Is there any solution of this kind of problem? Thank you
for your attention.


Yi


-- 
Yi Du

[[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] multicore - no parallel

2009-10-04 Thread David M Smith
On Sat, Oct 3, 2009 at 7:13 PM, dunno87  wrote:
> Thanks for the help in advance. I just want to know if there is absolutely
> any way of using multicore if my loop can't run in parallel as each
> iteration depends on the previous iteration. I have Windows R 2.9.2 and
> REvolution R Enterprise 2.0 for Windows 64 bit. I also have if necessary R
> on Ubuntu. 8gb of ram and a core 2 duo processor but I could use a quad core
> as well.

Without more details about your particular problem, it's hard to tell
if it's possible to parallelize the problem using foreach. If one
iteration does depend on the value of the previous one, it's not
immediately parallelizable. Sometimes you can refactor the problem (or
part of it) to remove the dependence, but not always.

If each iteration makes heavy use of matrix operations (multiply,
invert, decompose) you may already be making use of your multiple
cores. REvolution R Enterprise is linked to multi-threaded math
libraries which use multiple cores in parallel for such operations.
Make sure getMKLthreads() is returning the number cores you have (and
if not, use setMKLthreads).

While your loop is running, use the Task Manager to take a look at
your CPU usage -- if all cores are already being utilized there's no
real need to parallelize the for loop.
By the way, since you have a support subscription with REvolution R
Enterprise you can always ask your questions directly of our support
team or via http://forums.revolution-computing.com.

# David Smith

--
David M Smith 
Director of Community, REvolution Computing www.revolution-computing.com
Tel: +1 (206) 577-4778 x3203 (San Francisco, USA)

Check out our upcoming events schedule at www.revolution-computing.com/events

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] CRAN (and crantastic) updates this week

2009-10-04 Thread Crantastic
CRAN (and crantastic) updates this week

New packages


* EQL (1.0-0)
  Thorn Thaler
  http://crantastic.org/packages/EQL

  Computation of the EQL for a given family of variance functions,
  Saddlepoint-approximations and related auxiliary functions (e.g.
  Hermite polynomials)

* flsa (1.03)
  Holger Hoefling
  http://crantastic.org/packages/flsa

  This package implements a path algorithm for the Fused Lasso Signal
  Approximator. For more details see the help files

* glmperm (1.0-1)
  Wiebke Werft
  http://crantastic.org/packages/glmperm

  A permutation test is used for inference in generalized linear models
  (glm). The procedure is useful when parameter estimates in ordinary
  glm fail to converge or are unreliable due to small sample size.

* HMR (0.1.0)
  Asger R. Pedersen
  http://crantastic.org/packages/HMR

  Statistical analysis of static chamber concentration data for trace
  gas flux estimation

* inlinedocs (1.0)
  Toby Dylan Hocking
  http://crantastic.org/packages/inlinedocs

  Generates Rd files from R source code with comments, providing for
  quick, sustainable package development. The syntax keeps code and
  documentation close together, and is inspired by the Don't Repeat
  Yourself principle.

* intamap (1.2-18)
  Edzer J. Pebesma
  http://crantastic.org/packages/intamap

  A package that provides classes and methods for automated spatial
  interpolation.

* intamapInteractive (1.0-6)
  Edzer J. Pebesma
  http://crantastic.org/packages/intamapInteractive

  A package that provides classes and methods for automated spatial
  interpolation.

* lda (1.1)
  Jonathan Chang
  http://crantastic.org/packages/lda

  This package implements latent Dirichlet allocation (LDA) and related
  models.  This includes (but is not limited to) sLDA, corrLDA, and
  the mixed-membership stochastic blockmodel. Inference for all of
  these models is implemented via a fast collapsed Gibbs sampler
  writtten in C.  Utility functions for reading/writing data typically
  used in topic models, as well as tools for examining posterior
  distributions are also included.

* phull (0.2-1)
  Marek Gagolewski
  http://crantastic.org/packages/phull

  The package computes the p-hull of a finite planar set, which is a
  generalization of the convex hull, X-Y hull and bounding rectangle.
  A fast, O(n log n) Graham-scan based routine is used.

* psgp (0.2-7)
  Jon Skoien
  http://crantastic.org/packages/psgp

  implements projected sparse Gaussian process kriging for the intamap
  package

* QCA3 (0.0-1)
  HUANG Ronggui
  http://crantastic.org/packages/QCA3

  A set of functions is for Qulitative Comparative Analysis (QCA). It
  can be used for all three types of QCA.

* RC (1.0.1.27)
  Send complaints to
  http://crantastic.org/packages/RC

  The RC package allows the user to create and use reproducible
  computations for the purpose of research and education. The meta
  data about the computations are stored in a remote repository which
  is hosted at www.freestatistics.org

* RelativeRisk (1.0-1)
  Bob Wheeler
  http://crantastic.org/packages/RelativeRisk

  Relative risk estimation for prospective and retrospective data.

* ttutils (1.0-0)
  Thorn Thaler
  http://crantastic.org/packages/ttutils

  Contains some auxiliary functions.


Updated packages


AICcmodavg (1.02), AlgDesign (1.0-12), alr3 (1.1.12), arm (1.2-9.01),
benchden (1.0.2), BMN (1.01), caret (4.23), caret (4.24), clustTool
(1.6.4), coin (1.0-7), ctv (0.5-4), DEoptim (2.0-0), dplR (1.1.9.2),
eba (1.5-5), Epi (1.1.7), epicalc (2.9.2.3), epicalc (2.9.2.5), ez
(1.4.1), fArma (2100.76), fAsianOptions (2100.76), fAssets (2100.78),
fBasics (2100.78), fBonds (2100.75), fCopulae (2100.77),
fExoticOptions (2100.76), fExtremes (2100.77), fGarch (2100.79),
fImport (2100.77), flsa (1.03), fMultivar (2100.76), fNonlinear
(2100.76), fOptions (2100.76), fPortfolio (2100.78), fRegression
(2100.76), fTrading (2100.76), fUnitRoots (2100.76), fUtilities
(2100.77), Geneland (3.1.5), glmulti (0.5-2), haplo.stats (1.4.4),
hash (1.0), hmm.discnp (0.1-0), KFAS (0.4.2), KFAS (0.4.3), KFAS
(0.4.4), locpol (0.4-0), lpSolveAPI (5.5.0.15), MCMCglmm (1.12),
meboot (1.0-1), mi (0.08-04.02), MLCM (0.0-5), MLDS (0.2-3), npmlreg
(0.44), oce (0.1-78), optmatch (0.6-0), OrdFacReg (1.0.1), PearsonDS
(0.91), peperr (1.1-4), plink (1.2-1), plm (1.2-1), psych (1.0-80),
psyphy (0.1-3), qtl (1.14-2), quantmod (0.3-12), RcmdrPlugin.DoE
(0.5-3), RInside (0.1.1), rmeta (2.16), robust (0.3-9), SensoMineR
(1.10), sos (1.1-5), spatialsegregation (2.11), STAR (0.3-4), statmod
(1.4.1), SuppDists (1.1-6), tikzDevice (0.4.8), tileHMM (1.0-3),
timeDate (2100.86), timeSeries (2100.84), tlnise (1.1), ttrTests
(1.2), urca (1.2-3), VR (7.2-49), WINRPACK (1.0-9)


New reviews
---

* distrEx, by cranktastic
  http://crantastic.org/reviews/34



This email provided as a service for the R community by
http://crantastic.org.

Like it?  Hate it?  Please let us know: crana...@gm

Re: [R] Urgently needed Exercise solutions related to Practical Data Analysis Using R Statisctial Software

2009-10-04 Thread John Kane
Ah, but the offer of the permanent job with a foreign company is so enticing.  
BTW I think he says that he is a computer science student. I doubt business 
school students would be so cheap.

--- On Sat, 10/3/09, David Winsemius  wrote:

> From: David Winsemius 
> Subject: Re: [R] Urgently needed Exercise solutions related to Practical Data 
> Analysis Using R Statisctial Software
> To: "Mahesh Krishnan" 
> Cc: r-help@r-project.org
> Received: Saturday, October 3, 2009, 9:47 PM
> 
> On Oct 3, 2009, at 8:31 PM, Mahesh Krishnan wrote:
> 
> > Hello,
> > 
> > Can anybody help me in solving these exercises on
> regular basis paid or
> > unpaid basis.
> > If he/she want to pay by PayPal then it should be
> noticed that mention at
> > this email kindly
> > your paypal email account where one can transfer money
> in all cases.
> > 
> > But please respect the deadline in al cases.. *Dealine
> for this assignment
> > is 07.10.09.*
> > *If it is paid based then kindly let me know a decent
> price for this ..*
> > 
> > Regard,
> > Mahesh
> 
> Mahesh has also posted this at:
> http://www.odesk.com/jobs/Practical-Data-Analysis-Statistical-software-data-analysis-needed_~~ee9e750d03fe4303?source=rss
> 
> And is offering payment for a longer term for "Solving
> Exercises for a student on regular basis!
> Estimated Workload:As needed - Less than 10 hrs/week
> Estimated Duration:3 to 6 months Last Buyer
> Activity:September 15, 2009"
> 
> Who could resist with the average fee of $11.64?
> 
> It's probably a life strategy. Pay your way through your
> business school homework exercises and then hire someone to
> do all your technical work once you get a management
> position.
> 
> --
> David Winsemius, MD
> Heritage Laboratories
> West Hartford, CT
> 
> __
> R-help@r-project.org
> mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained,
> reproducible code.
> 


  __
The new Internet Explorer® 8 - Faster, safer, easier.  Optimized for Yahoo
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] update'ing trellis object

2009-10-04 Thread David Winsemius
I wonder if you noticed that you had managed to create a "fig" object  
that has two "inside" lists by specifying first a key "list" which  
required a legend list, and then specifying a "legend" list that also  
had a key function? The solution to your specific request by Kortschak  
"nulled-out" the second of those.


--
David

On Oct 3, 2009, at 10:35 PM, David Winsemius wrote:



On Oct 3, 2009, at 7:05 PM, Sebastian P. Luque wrote:


Hi,

I thought the following would only remove the legend element of a
trellis object, but it actually removes both the legend and key
elements:

------

fig <- xyplot(Sepal.Length ~ Petal.Length, groups=Species, data=iris,
key=list(x=1, y=0.02, corner=c(1, 0), size=3, between=1,
  text=list(levels(iris$Species))),
legend=list(inside=list(fun="draw.key", x=0, y=1,
  corner=c(0, 1),
  args=list(key=list(text=list("a)",  
cex=1.5)),

draw=FALSE
update(fig, legend=NULL)
------


Is this the right way to remove an element from the object, using
update.trellis()?  Thanks.

It probably depends on the element. In the case of "key", it is a  
descendant of the legend list so when you make legend NULL you are  
wiping out all of its descendants as well:

> str(fig)
List of 43
snipped a few lines
$ legend   :List of 2
 ..$ inside:List of 5
 .. ..$ fun   : chr "draw.key"
 .. ..$ args  :List of 2
 .. .. ..$ key :List of 6
 .. .. .. ..$ x  : num 1
 .. .. .. ..$ y  : num 0.02
 .. .. .. ..$ corner : num [1:2] 1 0
 .. .. .. ..$ size   : num 3
 .. .. .. ..$ between: num 1
 .. .. .. ..$ text   :List of 1
 .. .. .. .. ..$ : chr [1:3] "setosa" "versicolor" "virginica"
 .. .. ..$ draw: logi FALSE
 .. ..$ x : num 1
 .. ..$ y : num 0.02
 .. ..$ corner: num [1:2] 1 0
 ..$ inside:List of 5
 .. ..$ fun   : chr "draw.key"
 .. ..$ x : num 0
 .. ..$ y : num 1
 .. ..$ corner: num [1:2] 0 1
 .. ..$ args  :List of 2
 .. .. ..$ key :List of 1
 .. .. .. ..$ text:List of 2
 .. .. .. .. ..$: chr "a)"
 .. .. .. .. ..$ cex: num 1.5
 .. .. ..$ draw: logi FALSE



Cheers,

--
Seb

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


David Winsemius, MD
Heritage Laboratories
West Hartford, CT

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


Re: [R] Modify base R functions in Rprofile.site

2009-10-04 Thread cls59


Yihui Xie wrote:
> 
> 
> Thanks a lot, Charlie. What a coincidence -- I'm also working on 
> Sweave functions. parse() and deparse() can make the code more tidy 
> (they are used in source() and RweaveLatexRuncode()), 
> 
>> RweaveLatex 
> function () 
> { 
> list(setup = RweaveLatexSetup, runcode = RweaveLatexRuncode, 
> writedoc = RweaveLatexWritedoc, finish = RweaveLatexFinish, 
> checkopts = RweaveLatexOptions) 
> } 
>  
> 
> but we can either (1) let R automatically 'tidy up' our code and 
> remove all the comments or (2) keep the comments but leave the 
> original code untouched. 
> 
> I worked out a trick to preserve the comments while tidying up the R 
> code, and I want to replace parse() and deparse() with my customized 
> functions, in which case Sweave will keep the comments. 
> 
> However, my functions will need base::parse() and base::deparse() to
> help me, therefore my real difficulty is, how to let Sweave use my
> functions to parse and deparse R code without really modifying them in
> the base enviroment? I'm using the command 'R CMD Sweave'. 
> 
> 

Well, if you want to alter the behavior of RweaveLatexRunCode(), it can be
done from within a Sweave file. This happens to be what I did to Sweave-- I
wanted a little more control over the specifics of how it formatted code
chunk output in the .tex file. The steps involved are:

1. Make a copy of the Sweave function makeRweaveLatexCoderunner(). Patch it
so that it generates a RweaveLatexRuncode() function of your liking.

2. Overwrite utils:::makeRweaveLatexCodeRunner using the method I described
previously.

3. Generate a new code runner function using your patched version of
makeRweaveLatexCodeRunner().

4. Search all environments for old versions of RweaveLatexRuncode() and
replace them with your patched one.

An example of this approach is used to build the tikzDevice vignette, you
can view it at:

http://github.com/Sharpie/RTikZDevice/blob/master/inst/doc/tikzDevice.Rnw

Look for the line that says "Begin Mother of All R Hacks".




Yihui Xie wrote:
> 
> 
> If there is no neat approach, I'll change my question to: how to write a
> package,
> say, Sweave2, that can be run using command line 'R CMD Sweave2 file'?
> 
> 

This is also doable, at least for Linux and OS X systems that are installing
from source. You need to add a Make target that installs your script, named
Sweave2, into R_HOME/bin/ when the package is installed. This is the
approach we took in the pgfSweave package-- you can view an example at:

http://github.com/cameronbracken/pgfSweave/blob/master/src/Makevars

I hope this helps!

-Charlie

-
Charlie Sharpsteen
Undergraduate
Environmental Resources Engineering
Humboldt State University
-- 
View this message in context: 
http://www.nabble.com/Modify-base-R-functions-in-Rprofile.site-tp25735437p25743082.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] changing number of axis

2009-10-04 Thread Dan Kortschak
Hi Deepayan,

I'm building the pipeline to generate the data, so that can easiy be
inserted into the code upstream.

Thanks for your help.

Dan

On Sun, 2009-10-04 at 12:16 -0700, Deepayan Sarkar wrote:
> On Thu, Oct 1, 2009 at 11:30 PM, Dan Kortschak
>  wrote:
> > Thanks for that again. That almost works, except that lines are drawn
> > between non-empty bins (in various degrees of diagonality), so absent
> > points (important here) don't show clearly. It's not a huge issue, so I
> > might leave it, unless there is a simple way around this.
> 
> Including absent points as NA-s will work to break the lines; not sure
> if that would be hard to do in your example.
> 
> -Deepayan
> 
> >
> > cheers
> > Dan
> >
> > On Tue, 2009-09-29 at 23:17 -0700, Deepayan Sarkar wrote:
> >> On Tue, Sep 29, 2009 at 11:09 PM, Dan Kortschak
> >>  wrote:
> >> > Hi Deepayan,
> >> >
> >> > Thanks for that, I had a think (a few hour too late) and came to the
> >> > same conclusion. I had wanted to have vertical bars for each of the
> >> data
> >> > points, I have gone to a straight xyplot and this shows other
> >> intersting
> >> > information - maybe I want to be able to do both point and bar plots
> >> > (the bars show gaps in the bins nicely where the points don't).
> >>
> >> Perhaps  type = c("l", "h") in xyplot.
> >>
> >> -Deepayan
> >>
> >
> >

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] is that possible to graph 4 dimention plot

2009-10-04 Thread milton ruser
How about : google "r graph gallery 4d" ?

abs

On Sun, Oct 4, 2009 at 3:31 PM, Duncan Murdoch  wrote:

> On 04/10/2009 3:14 PM, gcheer3 wrote:
>
>> Suppose there are 4 variables
>> d is a function of a , b and c
>> I want to know how a, b and c change will make d change
>> It will be straightforward to see it if we can graph the d surface
>>
>> if d is only a function of a and b, I can use 'persp' to see the surface
>> of
>> d. I can easily see at what values of a and b, d will get the maxium or
>> minium or multiple modes, etc
>>
>> But for 4 dimention graph, is there a way to show the surface of d
>> Will use color help
>>
>
> contour3d in the misc3d package can do something like that.
>
> 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.
>

[[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] Modify base R functions in Rprofile.site

2009-10-04 Thread Duncan Murdoch

On 04/10/2009 6:07 PM, Yihui Xie wrote:

Thanks a lot, Charlie. What a coincidence -- I'm also working on
Sweave functions. parse() and deparse() can make the code more tidy
(they are used in source() and RweaveLatexRuncode()),


RweaveLatex

function ()
{
list(setup = RweaveLatexSetup, runcode = RweaveLatexRuncode,
writedoc = RweaveLatexWritedoc, finish = RweaveLatexFinish,
checkopts = RweaveLatexOptions)
}


but we can either (1) let R automatically 'tidy up' our code and
remove all the comments or (2) keep the comments but leave the
original code untouched.

I worked out a trick to preserve the comments while tidying up the R
code, and I want to replace parse() and deparse() with my customized
functions, in which case Sweave will keep the comments.

However, my functions will need base::parse() and base::deparse() to
help me, therefore my real difficulty is, how to let Sweave use my
functions to parse and deparse R code without really modifying them in
the base enviroment? I'm using the command 'R CMD Sweave'. 


I think it's really unlikely that you need to modify those two 
functions.  If you leave the source references turned on, the standard 
parse will tell you where all the code is; you can then write it out in 
any way you like, calling the standard deparse on bits and pieces, and 
mixing in the comments as you like.


The disadvantage of replacing parse or deparse is the maintenance:  if 
the standard ones change, you have to decide whether to incorporate 
those changes or not, in every case.  Neither parse nor deparse change a 
lot, but there have still been 2-3 dozen changes in the last year.


Now, if you choose instead to modify the original sources, in most cases 
Subversion will correctly merge the new changes in.  So that's better 
than a wholesale replacement, but still not as good as simply working 
with the output of the standard functions.


> If there is
> no neat approach, I'll change my question to: how to write a package,
> say, Sweave2, that can be run using command line 'R CMD Sweave2 file'?

Currently you can do that by writing Sweave2 as a Perl script and 
installing it in the RHOME/bin directory, but that may change:  we are 
working hard to do away with the need for Perl.


Duncan Murdoch



Regards,
Yihui
--
Yihui Xie 
Phone: 515-294-6609 Web: http://yihui.name
Department of Statistics, Iowa State University
3211 Snedecor Hall, Ames, IA



2009/10/4 cls59 :



Yihui Xie wrote:

Hi everyone,

I want to modify two base R functions 'parse' and 'deparse'
immediately after R has started, so I added some code in the file
'Rprofile.site' under the 'etc' directory. Here is a simple example:

parse=function(...){
base::parse(...)
}

I'll get an error when I start R as follows:

Error: cannot change value of locked binding for 'parse'

Is there a solution for my problem? Please note that I *have to*
override the function names. Thanks very much!




Hi Yihui,

I have had cause to do some some similar things to Sweave functions-- maybe
the following will help:

 # Find out where the function lives.
 env <- as.environment( 'package:base' )

 # Crack the binding.
 unlockBinding( 'parse', env )

 # Replace the function.
 assignInNamespace( 'parse', function(...){

  # Your function here, or an object that contains it.

  }, ns = 'base' )

 # Relock the binding.
 lockBinding( 'parse', env )


Note that the above is *very* dark voodoo-- it may cause unforeseen
consequences.

Good luck!

-Charlie

-
Charlie Sharpsteen
Undergraduate
Environmental Resources Engineering
Humboldt State University


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


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


Re: [R] Problem using with panel.average in Lattice package

2009-10-04 Thread Peter Ehlers

Deepayan,

Is something similar needed in the last example in ?xyplot? I don't
see panel.linejoin producing any lines.

Regards,
Peter Ehlers

Deepayan Sarkar wrote:

On Fri, Oct 2, 2009 at 8:03 PM, Mark Dalphin  wrote:

Hi,

I'm having a problem getting the panel.average function to work as I
expect it to in a lattice plot. I wish to draw lines between the
averages of groups of y-values at specific x-values. I have created a
dataset below which is similar to my real data. I also show an example
of using panel.loess in place of panel.average; it performs in a
manner similar to what I want panel.average to do except it shows a
loess line rather than a straight line connecting the means of the
groups.

Please see my coded examples, below.

Regards,
Mark Dalphin

=
My system information:


library(lattice)
print(sessionInfo())

R version 2.9.1 (2009-06-26) i686-pc-linux-gnu
locale:
LC_CTYPE=en_NZ.UTF-8;LC_NUMERIC=C;LC_TIME=en_NZ.UTF-8;LC_COLLATE=en_NZ.UTF-8;
LC_MONETARY=C;LC_MESSAGES=en_NZ.UTF-8;LC_PAPER=en_NZ.UTF-8;LC_NAME=C;
LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=en_NZ.UTF-8;LC_IDENTIFICATION=C

attached base packages:
[1] stats graphics  grDevices utils datasets  methods   base
other attached packages:
[1] lattice_0.17-25

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

##--
## This dataset is too complicated, but it does show the type of plot I
want.
##
## Create a fake qPCR dataset: Eight 96-well plates over 4 days (2 per day),
## 2 genes per plate (multiplexed), and 4 "Hi" positive control and
## 4 "Lo" positive controls per plate.
## Create the experimental data; by rights it is all identical, expect for
## experimental errors with in days and between days.
## For this simulation, each gene will be given a base value.
## In qPCR the higher the "Ct" value, the lower the concentration.
library(lattice)  # Add for ease of cut-n-paste of this code
date  <- c('2009-09-07', '2009-09-08', '2009-09-10', '2009-09-14')
probe <- c('Gene.A1', 'Gene.A2', 'Gene.B1', 'Gene.B2')
conc  <- c('Lo', 'Hi')
base.lo <- c(Gene.A1=29, Gene.A2=25, Gene.B1=28, Gene.B2=31)
base.hi <- base.lo - 8
day.err <- c(Day.1=0, Day.2=1, Day.3=1.5, Day.4=1.0)

d <- data.frame()
for(i in seq(along=date)) {
  for(j in seq(along=probe)) {
  for(k in seq(along=conc)) {
   d <- rbind(d, data.frame(Date=rep(date[i], length=4),
   Probe=rep(probe[j], length=4),
   Conc=rep(conc[k], length=4),
   Ct=rnorm(4, sd=0.5) + (k-1)*8 +
base.hi[j] + day.err[i]
   ))
  }
  }
}
d$Date <- as.POSIXct(d$Date)

##--
## Example 1
## Print with LOESS line showing the 'means' for the groups.
## This is close, but I don't want a loess line; I want straight lines
## between mean values.
print(xyplot(Ct ~ Date|Probe, group=Conc, data=d,
   panel="panel.superpose",
 panel.groups=function(x, y, ...) {
   panel.loess(x, y, ...)
   panel.xyplot(x, y, ...)
   },
   auto.key=TRUE))

##--
## Example 2
## Parallel construction to the loess example, above.
## Note the loss of the lines. The 'horizontal' default
## is different between 'panel.loess' and 'panel.average'.
print(xyplot(Ct ~ Date|Probe, group=Conc, data=d,
   panel="panel.superpose",
   panel.groups=function(x, y, ...) {
   panel.average(x, y, horizontal=FALSE, ...)
   panel.xyplot(x, y, ...)
   },
   auto.key=TRUE))


Unfortunately, the implicit type="p" argument in panel.superpose is
overriding the type="l" in panel.average (may be it should be
unmodifiable). So, you need

print(xyplot(Ct ~ Date|Probe, group=Conc, data=d,
 panel="panel.superpose",
 panel.groups=function(x, y, ..., type) {
 panel.average(x, y, ..., type = "l", horizontal = FALSE)
 panel.xyplot(x, y, ..., type = type)
 },
 auto.key=TRUE))

It's more common to use the syntactic sugar provided by panel.xyplot:

print(xyplot(Ct ~ Date|Probe, group=Conc, data=d,
 type = c("p", "a"),
 auto.key=TRUE))



##--
## Example 3
## Don't pass along the '...' to the panel.average. Now I
## get lines, but not matching colours to the points.
print(xyplot(Ct ~ Date|Probe, group=Conc, data=d,
   panel="panel.superpose",
   panel.groups=function(x, y, ...) {
   panel.average(x, y, horizontal=FALSE)
   panel.xyplot(x, y, ...)
   },
   auto.key=TRUE))

##**
Main question:

I want to create a plot that loo

Re: [R] Modify base R functions in Rprofile.site

2009-10-04 Thread Yihui Xie
Thanks a lot, Charlie. What a coincidence -- I'm also working on
Sweave functions. parse() and deparse() can make the code more tidy
(they are used in source() and RweaveLatexRuncode()),

> RweaveLatex
function ()
{
list(setup = RweaveLatexSetup, runcode = RweaveLatexRuncode,
writedoc = RweaveLatexWritedoc, finish = RweaveLatexFinish,
checkopts = RweaveLatexOptions)
}


but we can either (1) let R automatically 'tidy up' our code and
remove all the comments or (2) keep the comments but leave the
original code untouched.

I worked out a trick to preserve the comments while tidying up the R
code, and I want to replace parse() and deparse() with my customized
functions, in which case Sweave will keep the comments.

However, my functions will need base::parse() and base::deparse() to
help me, therefore my real difficulty is, how to let Sweave use my
functions to parse and deparse R code without really modifying them in
the base enviroment? I'm using the command 'R CMD Sweave'. If there is
no neat approach, I'll change my question to: how to write a package,
say, Sweave2, that can be run using command line 'R CMD Sweave2 file'?

Regards,
Yihui
--
Yihui Xie 
Phone: 515-294-6609 Web: http://yihui.name
Department of Statistics, Iowa State University
3211 Snedecor Hall, Ames, IA



2009/10/4 cls59 :
>
>
>
> Yihui Xie wrote:
>>
>> Hi everyone,
>>
>> I want to modify two base R functions 'parse' and 'deparse'
>> immediately after R has started, so I added some code in the file
>> 'Rprofile.site' under the 'etc' directory. Here is a simple example:
>>
>> parse=function(...){
>>     base::parse(...)
>> }
>>
>> I'll get an error when I start R as follows:
>>
>> Error: cannot change value of locked binding for 'parse'
>>
>> Is there a solution for my problem? Please note that I *have to*
>> override the function names. Thanks very much!
>>
>>
>
>
> Hi Yihui,
>
> I have had cause to do some some similar things to Sweave functions-- maybe
> the following will help:
>
>  # Find out where the function lives.
>  env <- as.environment( 'package:base' )
>
>  # Crack the binding.
>  unlockBinding( 'parse', env )
>
>  # Replace the function.
>  assignInNamespace( 'parse', function(...){
>
>   # Your function here, or an object that contains it.
>
>   }, ns = 'base' )
>
>  # Relock the binding.
>  lockBinding( 'parse', env )
>
>
> Note that the above is *very* dark voodoo-- it may cause unforeseen
> consequences.
>
> Good luck!
>
> -Charlie
>
> -
> Charlie Sharpsteen
> Undergraduate
> Environmental Resources Engineering
> Humboldt State University

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


Re: [R] update'ing trellis object

2009-10-04 Thread Sebastian P. Luque
On Sun, 4 Oct 2009 16:14:58 -0400,
Gabor Grothendieck  wrote:

> On Sun, Oct 4, 2009 at 3:45 PM, Deepayan Sarkar
>  wrote:

> Yes, unfortunately the trellis object cannot distinguish between the
>> "legend" and the "key" any more.

> If you are willing to muck around at the grid level you can do it.
> First list out the grid objects using grid.ls(). Now looking for 3
> grid text objects in proximity we see 3 such objects as descendants of
> GRID.frame.215 and we examine the first one which, GRID.text.218,
> which indeed contains setosa in its label.  Finally we zap the labels
> of those three grid text objects.

[...]

Thanks everyone.  Besides Gabor's grid approach, another option, short
of redoing the plot entirely, would be to simply target the list element
to remove:

fig$legend[[2]] <- NULL

I don't know if the index (2) would be constant for any such plot
though.

Cheers,

-- 
Seb

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


Re: [R] update'ing trellis object

2009-10-04 Thread Gabor Grothendieck
On Sun, Oct 4, 2009 at 3:45 PM, Deepayan Sarkar
 wrote:
>
> Yes, unfortunately the trellis object cannot distinguish between the
> "legend" and the "key" any more.
>

If you are willing to muck around at the grid level you can do it.
First list out the grid objects using grid.ls(). Now looking for 3
grid text objects in proximity we see 3 such objects as descendants of
GRID.frame.215 and we examine the first one which, GRID.text.218,
which indeed contains setosa in its label.  Finally we zap the labels
of those three grid text objects.

> library(grid)
> print(fig)
> grid.ls()
GRID.rect.233
plot1.xlab
plot1.ylab
GRID.segments.234
GRID.segments.235
GRID.text.236
GRID.segments.237
GRID.text.238
GRID.segments.239
GRID.points.240
GRID.points.241
GRID.points.242
GRID.rect.243
GRID.frame.215
  GRID.cellGrob.217
GRID.rect.216
  GRID.cellGrob.219
GRID.text.218
  GRID.cellGrob.221
GRID.text.220
  GRID.cellGrob.223
GRID.text.222
GRID.frame.224
  GRID.cellGrob.226
GRID.rect.225
  GRID.cellGrob.228
GRID.text.227
> str(grid.get("GRID.text.218"))
List of 11
 $ label: chr "setosa"
 $ x:Class 'unit'  atomic [1:1] 0
  .. ..- attr(*, "unit")= chr "npc"
  .. ..- attr(*, "valid.unit")= int 0
 $ y:Class 'unit'  atomic [1:1] 0.5
  .. ..- attr(*, "unit")= chr "npc"
  .. ..- attr(*, "valid.unit")= int 0
 $ just : chr "centre"
 $ hjust: num 0
 $ vjust: NULL
 $ rot  : num 0
 $ check.overlap: logi FALSE
 $ name : chr "GRID.text.218"
 $ gp   :List of 6
  ..$ col   : chr "black"
  ..$ alpha : num 1
  ..$ lineheight: num 1
  ..$ fontface  : num 1
  ..$ cex   : num 1
  ..$ font  : int 1
  ..- attr(*, "class")= chr "gpar"
 $ vp   : NULL
 - attr(*, "class")= chr [1:3] "text" "grob" "gDesc"
> grid.edit("GRID.text.218", label = "")
> grid.edit("GRID.text.220", label = "")
> grid.edit("GRID.text.222", label = "")

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


Re: [R] update'ing trellis object

2009-10-04 Thread Deepayan Sarkar
On Sat, Oct 3, 2009 at 7:35 PM, David Winsemius  wrote:
>
> On Oct 3, 2009, at 7:05 PM, Sebastian P. Luque wrote:
>
>> Hi,
>>
>> I thought the following would only remove the legend element of a
>> trellis object, but it actually removes both the legend and key
>> elements:
>>
>> ---> here---start--->---
>> fig <- xyplot(Sepal.Length ~ Petal.Length, groups=Species, data=iris,
>>             key=list(x=1, y=0.02, corner=c(1, 0), size=3, between=1,
>>               text=list(levels(iris$Species))),
>>             legend=list(inside=list(fun="draw.key", x=0, y=1,
>>                           corner=c(0, 1),
>>                           args=list(key=list(text=list("a)", cex=1.5)),
>>                             draw=FALSE
>> update(fig, legend=NULL)
>> ---> here---end->---
>>
>> Is this the right way to remove an element from the object, using
>> update.trellis()?  Thanks.
>>
> It probably depends on the element. In the case of "key", it is a descendant
> of the legend list so when you make legend NULL you are wiping out all of
> its descendants as well:

Yes, unfortunately the trellis object cannot distinguish between the
"legend" and the "key" any more.

-Deepayan

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


Re: [R] Problem using with panel.average in Lattice package

2009-10-04 Thread Deepayan Sarkar
On Fri, Oct 2, 2009 at 8:03 PM, Mark Dalphin  wrote:
> Hi,
>
> I'm having a problem getting the panel.average function to work as I
> expect it to in a lattice plot. I wish to draw lines between the
> averages of groups of y-values at specific x-values. I have created a
> dataset below which is similar to my real data. I also show an example
> of using panel.loess in place of panel.average; it performs in a
> manner similar to what I want panel.average to do except it shows a
> loess line rather than a straight line connecting the means of the
> groups.
>
> Please see my coded examples, below.
>
> Regards,
> Mark Dalphin
>
> =
> My system information:
>
>> library(lattice)
>> print(sessionInfo())
>
> R version 2.9.1 (2009-06-26) i686-pc-linux-gnu
> locale:
> LC_CTYPE=en_NZ.UTF-8;LC_NUMERIC=C;LC_TIME=en_NZ.UTF-8;LC_COLLATE=en_NZ.UTF-8;
> LC_MONETARY=C;LC_MESSAGES=en_NZ.UTF-8;LC_PAPER=en_NZ.UTF-8;LC_NAME=C;
> LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=en_NZ.UTF-8;LC_IDENTIFICATION=C
>
> attached base packages:
> [1] stats     graphics  grDevices utils     datasets  methods   base
> other attached packages:
> [1] lattice_0.17-25
>
> loaded via a namespace (and not attached):
> [1] grid_2.9.1  tools_2.9.1
>
> ##--
> ## This dataset is too complicated, but it does show the type of plot I
> want.
> ##
> ## Create a fake qPCR dataset: Eight 96-well plates over 4 days (2 per day),
> ## 2 genes per plate (multiplexed), and 4 "Hi" positive control and
> ## 4 "Lo" positive controls per plate.
> ## Create the experimental data; by rights it is all identical, expect for
> ## experimental errors with in days and between days.
> ## For this simulation, each gene will be given a base value.
> ## In qPCR the higher the "Ct" value, the lower the concentration.
> library(lattice)  # Add for ease of cut-n-paste of this code
> date  <- c('2009-09-07', '2009-09-08', '2009-09-10', '2009-09-14')
> probe <- c('Gene.A1', 'Gene.A2', 'Gene.B1', 'Gene.B2')
> conc  <- c('Lo', 'Hi')
> base.lo <- c(Gene.A1=29, Gene.A2=25, Gene.B1=28, Gene.B2=31)
> base.hi <- base.lo - 8
> day.err <- c(Day.1=0, Day.2=1, Day.3=1.5, Day.4=1.0)
>
> d <- data.frame()
> for(i in seq(along=date)) {
>   for(j in seq(along=probe)) {
>       for(k in seq(along=conc)) {
>            d <- rbind(d, data.frame(Date=rep(date[i], length=4),
>                                    Probe=rep(probe[j], length=4),
>                                    Conc=rep(conc[k], length=4),
>                                    Ct=rnorm(4, sd=0.5) + (k-1)*8 +
> base.hi[j] + day.err[i]
>                                    ))
>       }
>   }
> }
> d$Date <- as.POSIXct(d$Date)
>
> ##--
> ## Example 1
> ## Print with LOESS line showing the 'means' for the groups.
> ## This is close, but I don't want a loess line; I want straight lines
> ## between mean values.
> print(xyplot(Ct ~ Date|Probe, group=Conc, data=d,
>            panel="panel.superpose",
>  panel.groups=function(x, y, ...) {
>                panel.loess(x, y, ...)
>                panel.xyplot(x, y, ...)
>            },
>            auto.key=TRUE))
>
> ##--
> ## Example 2
> ## Parallel construction to the loess example, above.
> ## Note the loss of the lines. The 'horizontal' default
> ## is different between 'panel.loess' and 'panel.average'.
> print(xyplot(Ct ~ Date|Probe, group=Conc, data=d,
>            panel="panel.superpose",
>            panel.groups=function(x, y, ...) {
>                panel.average(x, y, horizontal=FALSE, ...)
>                panel.xyplot(x, y, ...)
>            },
>            auto.key=TRUE))

Unfortunately, the implicit type="p" argument in panel.superpose is
overriding the type="l" in panel.average (may be it should be
unmodifiable). So, you need

print(xyplot(Ct ~ Date|Probe, group=Conc, data=d,
 panel="panel.superpose",
 panel.groups=function(x, y, ..., type) {
 panel.average(x, y, ..., type = "l", horizontal = FALSE)
 panel.xyplot(x, y, ..., type = type)
 },
 auto.key=TRUE))

It's more common to use the syntactic sugar provided by panel.xyplot:

print(xyplot(Ct ~ Date|Probe, group=Conc, data=d,
 type = c("p", "a"),
 auto.key=TRUE))


>
> ##--
> ## Example 3
> ## Don't pass along the '...' to the panel.average. Now I
> ## get lines, but not matching colours to the points.
> print(xyplot(Ct ~ Date|Probe, group=Conc, data=d,
>            panel="panel.superpose",
>            panel.groups=function(x, y, ...) {
>                panel.average(x, y, horizontal=FALSE)
>                panel.xyplot(x, y, ...)
>            },
>            auto.key=TRUE))
>
> ##**
> Main questi

Re: [R] is that possible to graph 4 dimention plot

2009-10-04 Thread Duncan Murdoch

On 04/10/2009 3:14 PM, gcheer3 wrote:

Suppose there are 4 variables
d is a function of a , b and c
I want to know how a, b and c change will make d change
It will be straightforward to see it if we can graph the d surface

if d is only a function of a and b, I can use 'persp' to see the surface of
d. I can easily see at what values of a and b, d will get the maxium or
minium or multiple modes, etc

But for 4 dimention graph, is there a way to show the surface of d
Will use color help


contour3d in the misc3d package can do something like that.

Duncan Murdoch

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


[R] is that possible to graph 4 dimention plot

2009-10-04 Thread gcheer3

Suppose there are 4 variables
d is a function of a , b and c
I want to know how a, b and c change will make d change
It will be straightforward to see it if we can graph the d surface

if d is only a function of a and b, I can use 'persp' to see the surface of
d. I can easily see at what values of a and b, d will get the maxium or
minium or multiple modes, etc

But for 4 dimention graph, is there a way to show the surface of d
Will use color help

Thanks a lot
-- 
View this message in context: 
http://www.nabble.com/is-that-possible-to-graph-4-dimention-plot-tp25741135p25741135.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] Row to Column help

2009-10-04 Thread AC Del Re
>
> Wonderful, Phil! Your suggestion produced the exact format I desired.
> Thank you kindly,
>

   AC Del Re

>
>
> On Sun, Oct 4, 2009 at 2:03 PM, Phil Spector wrote:
>
>> AC -
>>   The easiest way I can think of is to create a time variable,
>> so reshape will know which observation to call 1, 2, or 3.
>>
>> data$time = unlist(sapply(split(data,data$id),function(x)1:nrow(x)))
>> or
>> data$time = unlist(tapply(data$id,data$id,function(x)1:length(x))
>>
>> Then
>>
>> reshape(data,idvar=c('id','author'),timevar='time',direction='wide')
>>
>> should give you what you want.
>>- Phil Spector
>> Statistical Computing Facility
>> Department of Statistics
>> UC Berkeley
>> spec...@stat.berkeley.edu
>>
>>
>>
>> On Sun, 4 Oct 2009, AC Del Re wrote:
>>
>>  Dear R Community,
>>> I am attempting to transpose a dataset from rows to columns but am stuck.
>>> I
>>> have tried using reshape() with little luck, possibly due to the
>>> categorical
>>> nature of the data. For example:
>>>
>>> id<-c(1,2,2,3,3,3)
>>> author<-c("j","k","k","l","l","l")
>>> tmt<-c("cbt","act","dbt","act","act","cbt")
>>> alliance<-c("wai","other","calpas","wai","itas","other")
>>> data<-as.data.frame(cbind(id,author,tmt,alliance))
>>>
>>>  data

>>>  id author  tmt  alliance
>>> 1  1  jcbt  wai
>>> 2  2  k   actother
>>> 3  2  k   dbt   calpas
>>> 4  3  l   act  wai
>>> 5  3  l   act itas
>>> 6  3  l   cbtother
>>>
>>> I would like the data to be in the following format:
>>>
>>> id   author   tmt.1  tmt.2   alliance.1   alliance.2alliance.3
>>> 1j   cbt  NAwai  NANA
>>> 2   k   act  dbtother   calpasNA
>>> 3   lact  actwai  itasother
>>>
>>>
>>> I tried:
>>>
>>>  wide <- reshape(data, idvar=c("id","author"), direction="wide")

>>>
>>> Error in `[.data.frame`(data, , timevar) : undefined columns selected
>>>
>>> If I specify all columns, it gives the following format (which is not
>>> desired):
>>>
>>> wide <- reshape(data, idvar=c("id","author"),
>>> + direction="wide", *v.names="tmt", timevar="alliance"*)
>>>
>>>  wide

>>>  id author tmt.wai tmt.other tmt.calpas tmt.itas
>>> 1  1  j cbt  
>>> 2  2  k   actdbt 
>>> 4  3  l act   cbt act
>>>
>>> Any help is much appreciated!
>>>
>>> AC
>>>
>>>[[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] changing number of axis

2009-10-04 Thread Deepayan Sarkar
On Thu, Oct 1, 2009 at 11:30 PM, Dan Kortschak
 wrote:
> Thanks for that again. That almost works, except that lines are drawn
> between non-empty bins (in various degrees of diagonality), so absent
> points (important here) don't show clearly. It's not a huge issue, so I
> might leave it, unless there is a simple way around this.

Including absent points as NA-s will work to break the lines; not sure
if that would be hard to do in your example.

-Deepayan

>
> cheers
> Dan
>
> On Tue, 2009-09-29 at 23:17 -0700, Deepayan Sarkar wrote:
>> On Tue, Sep 29, 2009 at 11:09 PM, Dan Kortschak
>>  wrote:
>> > Hi Deepayan,
>> >
>> > Thanks for that, I had a think (a few hour too late) and came to the
>> > same conclusion. I had wanted to have vertical bars for each of the
>> data
>> > points, I have gone to a straight xyplot and this shows other
>> intersting
>> > information - maybe I want to be able to do both point and bar plots
>> > (the bars show gaps in the bins nicely where the points don't).
>>
>> Perhaps  type = c("l", "h") in xyplot.
>>
>> -Deepayan
>>
>
>

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


Re: [R] Help for 3D Plotting Data on 'Irregular' Grid

2009-10-04 Thread Deepayan Sarkar
On Thu, Oct 1, 2009 at 6:38 AM, Lorenzo Isella  wrote:
> Dear All,
> Here is what I am trying to achieve: I would like to plot some data in 3D.
> Usually, one has a matrix of the kind
>
> y_1(x_1) , y_1(x_2).y_1(x_i)
> y_2(x_1) , y_2(x_2).y_2(x_i)
> ...
> y_n(x_1) , y_n(x_2)..y_n(x_i)
>
>
> where e.g. y_2(x_1) is the value of y at time 2 at point x_1 (see that the
> grid in x is the same for the y values at all times).
> Instead, in my case, the quantity y is observed at each time on a different
> grid in x; in other words not only do I have a different number of
> observations (y values) at each time, but I also have observations taken on
> a a different x grid each time.
> As a matter of fact, it is as if I had a set of independent observations,
> for each of which I can create effortlessly a 2D plot, that I want to stitch
> together into a 3D plot.
> I have no idea of how to achieve that. Examples I have found with lattice or
> scatterplot3D all assume a regular grid like the one I described above.

3-D scatter plots with cloud() etc. should be easy with irregular
data. Surfaces do require a regular grid, and you need some form of
interpolation for that. The akima package seems popular for that (I
haven't used it myself).

-Deepayan

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

2009-10-04 Thread Phil Spector

AC -
   The easiest way I can think of is to create a time variable,
so reshape will know which observation to call 1, 2, or 3.

data$time = unlist(sapply(split(data,data$id),function(x)1:nrow(x)))
or
data$time = unlist(tapply(data$id,data$id,function(x)1:length(x))

Then

reshape(data,idvar=c('id','author'),timevar='time',direction='wide')

should give you what you want.
- Phil Spector
 Statistical Computing Facility
 Department of Statistics
 UC Berkeley
 spec...@stat.berkeley.edu


On Sun, 4 Oct 2009, AC Del Re wrote:


Dear R Community,
I am attempting to transpose a dataset from rows to columns but am stuck. I
have tried using reshape() with little luck, possibly due to the categorical
nature of the data. For example:

id<-c(1,2,2,3,3,3)
author<-c("j","k","k","l","l","l")
tmt<-c("cbt","act","dbt","act","act","cbt")
alliance<-c("wai","other","calpas","wai","itas","other")
data<-as.data.frame(cbind(id,author,tmt,alliance))


data

 id author  tmt  alliance
1  1  jcbt  wai
2  2  k   actother
3  2  k   dbt   calpas
4  3  l   act  wai
5  3  l   act itas
6  3  l   cbtother

I would like the data to be in the following format:

id   author   tmt.1  tmt.2   alliance.1   alliance.2alliance.3
1j   cbt  NAwai  NANA
2   k   act  dbtother   calpasNA
3   lact  actwai  itasother


I tried:


wide <- reshape(data, idvar=c("id","author"), direction="wide")


Error in `[.data.frame`(data, , timevar) : undefined columns selected

If I specify all columns, it gives the following format (which is not
desired):

wide <- reshape(data, idvar=c("id","author"),
+ direction="wide", *v.names="tmt", timevar="alliance"*)


wide

 id author tmt.wai tmt.other tmt.calpas tmt.itas
1  1  j cbt  
2  2  k   actdbt 
4  3  l act   cbt act

Any help is much appreciated!

AC

[[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] Row to Column help

2009-10-04 Thread AC Del Re
Dear R Community,
I am attempting to transpose a dataset from rows to columns but am stuck. I
have tried using reshape() with little luck, possibly due to the categorical
nature of the data. For example:

id<-c(1,2,2,3,3,3)
author<-c("j","k","k","l","l","l")
tmt<-c("cbt","act","dbt","act","act","cbt")
alliance<-c("wai","other","calpas","wai","itas","other")
data<-as.data.frame(cbind(id,author,tmt,alliance))

> data
  id author  tmt  alliance
1  1  jcbt  wai
2  2  k   actother
3  2  k   dbt   calpas
4  3  l   act  wai
5  3  l   act itas
6  3  l   cbtother

I would like the data to be in the following format:

id   author   tmt.1  tmt.2   alliance.1   alliance.2alliance.3
1j   cbt  NAwai  NANA
2   k   act  dbtother   calpasNA
3   lact  actwai  itasother


I tried:

> wide <- reshape(data, idvar=c("id","author"), direction="wide")

Error in `[.data.frame`(data, , timevar) : undefined columns selected

If I specify all columns, it gives the following format (which is not
desired):

wide <- reshape(data, idvar=c("id","author"),
+ direction="wide", *v.names="tmt", timevar="alliance"*)

> wide
  id author tmt.wai tmt.other tmt.calpas tmt.itas
1  1  j cbt  
2  2  k   actdbt 
4  3  l act   cbt act

Any help is much appreciated!

AC

[[alternative HTML version deleted]]

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


Re: [R] help about solving the equations

2009-10-04 Thread Berend Hasselman



Gabor Grothendieck wrote:
> 
> x is the eigenvector corresponding to eigenvalue 1.   See  ?eigen.
> 
> 

Correct.
I should have looked better.

Berend
-- 
View this message in context: 
http://www.nabble.com/help-about-solving-the-equations-tp25738073p25740459.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] help about solving the equations

2009-10-04 Thread Gabor Grothendieck
x is the eigenvector corresponding to eigenvalue 1.   See  ?eigen.

On Sun, Oct 4, 2009 at 9:31 AM, dahuang  wrote:
>
> i wanna get x from the equations: Ax=x, given A is a matrix. How can i apply
> it in R? thanks
> --
> View this message in context: 
> http://www.nabble.com/help-about-solving-the-equations-tp25738073p25738073.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] Modify base R functions in Rprofile.site

2009-10-04 Thread cls59


Duncan Murdoch-2 wrote:
> 
> 
> Why not just modify their source, and rebuild R?
> 
> Duncan Murdoch
> 
> 

In my case, the IT guys don't always provide the necessary tools and/or
permissions to do this. Which is why we are fortunate that R is so flexible
as to allow modification of core routines in some cases.

-Charlie

-
Charlie Sharpsteen
Undergraduate
Environmental Resources Engineering
Humboldt State University
-- 
View this message in context: 
http://www.nabble.com/Modify-base-R-functions-in-Rprofile.site-tp25735437p25740138.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] extraction from data.frame

2009-10-04 Thread David Winsemius


On Oct 4, 2009, at 12:09 PM,  wrote:


Hi,
I extracted from a data.frame (x) of 27 columns a smaller data.frame  
(x2) with 12 columns whit the following:


x2=x[, c("BROVISINGVal", "CHATVal", "EMAILVal", ...,  
"Piano.Tariffario")]


Something like this (untested):

x2=x[ x$Piano.Tariffario == 2 , c("BROVISINGVal", "CHATVal",  
"EMAILVal", ..., "Piano.Tariffario")]


Logical vectors, such as that created by x$Piano.Tariffario == 2 , are  
often used in the row postion of an extraction using "[ , ]" indexing.





Anyway I want to form x2 by extracting all the rows that assume any  
value for the first 11 columns but a particular value (2) for the  
last one "Piano.Tariffario".

How do I continue?
Thanks
Sabrina



David Winsemius, MD
Heritage Laboratories
West Hartford, CT

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


Re: [R] convenience question

2009-10-04 Thread Gabor Grothendieck
Add a flush.console() statement after each cat.


On Sun, Oct 4, 2009 at 11:32 AM, Philip A. Viton  wrote:
>
> On: R 2.8.1 / Ms Windows / R-Gui-R-console
>
> I have a long-ish function, and to re-assure myself that it's actually
> making progress I've arranged a set of messages to the console (using cat).
> But what happens is that the messages don't actually display until the
> function  has finished, which sort of negates the purpose. However, if I hit
> Return after starting the function, then all is well. I'm pretty sure that
> what's happening is that the function isn't yielding time to the operating
> system in order that messages be processed: so my question is, is there any
> way to do that within the function? Or maybe, to simulate the Return
> keystroke?
>
> Thanks!
>
> 
> Philip A. Viton
> City Planning, Ohio State University
> 275 West Woodruff Avenue, Columbus OH 43210
> vito...@osu.edu
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Modify base R functions in Rprofile.site

2009-10-04 Thread Duncan Murdoch

On 04/10/2009 12:41 PM, cls59 wrote:



Yihui Xie wrote:

Hi everyone,

I want to modify two base R functions 'parse' and 'deparse'
immediately after R has started, so I added some code in the file
'Rprofile.site' under the 'etc' directory. Here is a simple example:


Why not just modify their source, and rebuild R?

Duncan Murdoch



parse=function(...){
base::parse(...)
}

I'll get an error when I start R as follows:

Error: cannot change value of locked binding for 'parse'

Is there a solution for my problem? Please note that I *have to*
override the function names. Thanks very much!





Hi Yihui,

I have had cause to do some some similar things to Sweave functions-- maybe
the following will help:

  # Find out where the function lives.
  env <- as.environment( 'package:base' )

  # Crack the binding.
  unlockBinding( 'parse', env )

  # Replace the function.
  assignInNamespace( 'parse', function(...){
  
   # Your function here, or an object that contains it.


   }, ns = 'base' )

  # Relock the binding.
  lockBinding( 'parse', env )


Note that the above is *very* dark voodoo-- it may cause unforeseen
consequences.

Good luck!

-Charlie

-
Charlie Sharpsteen
Undergraduate
Environmental Resources Engineering
Humboldt State University


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


Re: [R] Modify base R functions in Rprofile.site

2009-10-04 Thread cls59



Yihui Xie wrote:
> 
> Hi everyone,
> 
> I want to modify two base R functions 'parse' and 'deparse'
> immediately after R has started, so I added some code in the file
> 'Rprofile.site' under the 'etc' directory. Here is a simple example:
> 
> parse=function(...){
> base::parse(...)
> }
> 
> I'll get an error when I start R as follows:
> 
> Error: cannot change value of locked binding for 'parse'
> 
> Is there a solution for my problem? Please note that I *have to*
> override the function names. Thanks very much!
> 
> 


Hi Yihui,

I have had cause to do some some similar things to Sweave functions-- maybe
the following will help:

  # Find out where the function lives.
  env <- as.environment( 'package:base' )

  # Crack the binding.
  unlockBinding( 'parse', env )

  # Replace the function.
  assignInNamespace( 'parse', function(...){
  
   # Your function here, or an object that contains it.

   }, ns = 'base' )

  # Relock the binding.
  lockBinding( 'parse', env )


Note that the above is *very* dark voodoo-- it may cause unforeseen
consequences.

Good luck!

-Charlie

-
Charlie Sharpsteen
Undergraduate
Environmental Resources Engineering
Humboldt State University
-- 
View this message in context: 
http://www.nabble.com/Modify-base-R-functions-in-Rprofile.site-tp25735437p25739660.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] convenience question

2009-10-04 Thread Philip A. Viton


On: R 2.8.1 / Ms Windows / R-Gui-R-console

I have a long-ish function, and to re-assure myself that it's 
actually making progress I've arranged a set of messages to the 
console (using cat). But what happens is that the messages don't 
actually display until the function  has finished, which sort of 
negates the purpose. However, if I hit Return after starting the 
function, then all is well. I'm pretty sure that what's happening is 
that the function isn't yielding time to the operating system in 
order that messages be processed: so my question is, is there any way 
to do that within the function? Or maybe, to simulate the Return keystroke?


Thanks!


Philip A. Viton
City Planning, Ohio State University
275 West Woodruff Avenue, Columbus OH 43210
vito...@osu.edu

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


[R] help about solving the equations

2009-10-04 Thread dahuang

i wanna get x from the equations: Ax=x, given A is a matrix. How can i apply
it in R? thanks
-- 
View this message in context: 
http://www.nabble.com/help-about-solving-the-equations-tp25738073p25738073.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] extraction from data.frame

2009-10-04 Thread sabrina.michielin
Hi,
I extracted from a data.frame (x) of 27 columns a smaller data.frame (x2) with 
12 columns whit the following:
 
x2=x[, c("BROVISINGVal", "CHATVal", "EMAILVal", ..., "Piano.Tariffario")]
 
Anyway I want to form x2 by extracting all the rows that assume any value for 
the first 11 columns but a particular value (2) for the last one 
"Piano.Tariffario".
How do I continue?
Thanks
Sabrina

[[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] Copying matrices with certain probabilities

2009-10-04 Thread David Winsemius


On Oct 4, 2009, at 9:36 AM, William Aue wrote:


Hi all! Below is the problem I am struggling with.

Let’s say I have a matrix (x) of values:

# [,1] [,2] [,3] [,4]
#[1,]1321
#[2,]2132

I need to copy the items into a new matrix (y) with certain
probability guidelines. I need to set it up such that:

1. for each item there is a probability (a) that the item will or will
not be copied at all from x to y. If nothing is copied then the
corresponding value in y should be 0.


That would be simple enough with binomial sampling using the specified  
probabilities.


?sample
?rbinom

Matrices in R can be thought of as folded vectors so the "*" operator  
acts element wise. If you populated a probability matrix, P, you could  
get useful results with M * P



2. If something is copied from x to y, then there should be a separate
probability (b) that the items will be correctly copied to y with
items that are incorrectly copied being randomly drawn from a
geometric distribution.


So, why then did you not offer two 2 x 4 matrices of correct and  
incorrect probabilities to specify what you mean? And while you are at  
it can you also specify what sort of geometric distribution parameters  
you have in mind to go along with the "incorrect" draws?


?rgeom




So y may look like the below example. Row 1 shows that [1,2] was
copied and subsequently correctly copied but nothing else in [1,] was
copied. In [2,], [2,1] was copied but subsequently incorrectly copied,
[2,2] & [2,3] were not copied at all, and [2,4] was copied and
correctly copied.

# [,1] [,2] [,3] [,4]
#[1,]0300
#[2,]5002

I would also like to setup a loop for this process wherein if
something doesn’t get copied at all during a previous pass, then there
is the opportunity for it to be copied on a second/third/etc pass.


And can you clarify whether this would be the same matrix that I above  
suggested should have been offered in your original posting should the  
probabiliies increase if the item was not copied at all. If the  
probabilies should get altered , i.e, the (inhomogeneous) process has  
memory, then in what way should thoe probabilities change?




I hope this is clear enough. I am still a novice at R, so any
help/guidance that can be offered will be greatly appreciated.

OK, ... "and provide commented, minimal, self-contained, reproducible  
code." That would mean specifying your matrices along the lines of:


M <- matrix(c( 0, 3, 0,  0,  5, 0, 0, 2), nrow=2, byrow=TRUE)

...rather than expecting the responders to repeat that work.


Best,

Billy Aue



David Winsemius, MD
Heritage Laboratories
West Hartford, CT

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


Re: [R] xyplot key

2009-10-04 Thread Deepayan Sarkar
On Wed, Sep 30, 2009 at 6:54 AM, Andrewjohnclose  wrote:
>
> Hi,
>
> I'm having trouble matching the symbols/color of the key to match those
> specifiec in the plot.
>
> Here is the code I used:
>
>
> xyplot(GCR+GCT ~ FRAC, data=RWF, type=c("g","p"),cex=1.2,pch=c(22,21),
> xlab=expression(italic("f")),ylab=expression(italic("S")),
> key=list(points=list(pch=c(22,21),cex=1.2),
> text=list(c("Targeted Deletion","Random Deletion"
>
> I'm, sorry if this is an apparently easy/obvious mistake on my part.

(For complicated reasons, ) The easiest way to to do this is with something like

xyplot(GCR+GCT ~ FRAC, data=RWF, type=c("g","p"),
   xlab=expression(italic("f")),ylab=expression(italic("S")),
   par.settings = simpleTheme(cex=1.2,pch=c(22,21)),
   auto.key = list(text=c("Targeted Deletion","Random Deletion")))

-Deepayan

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

2009-10-04 Thread Deepayan Sarkar
On Mon, Sep 28, 2009 at 9:08 AM, Antje  wrote:
> I had a bit success with the following usage:
>
> my.padding <- list(layout.heights = list(
>                        top.padding = 0,
>                        main.key.padding = 0,
>                        key.axis.padding = 0,
>                        axis.xlab.padding = 0,
>                        xlab.key.padding = 0,
>                        key.sub.padding = 0),
>                layout.widths = list(
>                        left.padding = 0,
>                        key.ylab.padding = 0,
>                        ylab.axis.padding = 0,
>                        axis.key.padding = 0,
>                        right.padding = 0)
>                )
>
> levelplot(..., scales = list(draw = FALSE), colorkey = FALSE, xlab = NULL,
> ylab = NULL, par.settings = my.padding)
>
>
> But still I have a upper and lower margin (left and right margins are gone)
>
> What else do I have to do?

Actually, for your use it's easier to bypass lattice and use grid
directly. You can still use panel.levelplot() as a low level drawing
function. For example, using the volcano data:

my.matrix <- volcano

library(grid)
grid.newpage()
pushViewport(viewport(xscale = c(0, 1 + ncol(my.matrix)), yscale =
c(0, 1 + nrow(my.matrix
panel.levelplot(col(my.matrix), row(my.matrix), my.matrix,
subscripts=TRUE, at = do.breaks(range(my.matrix), 30))


Of course, this requires you to do some limit calculations beforehand,
and the arguments of the panel function are not always obvious. You
can use lattice to take care of these things for you:


p <- levelplot(volcano)
grid.newpage()
pushViewport(viewport(xscale = p$x.limits, yscale = p$y.limits))
do.call(panel.levelplot, trellis.panelArgs(p, 1))

-Deepayan

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


Re: [R] help about solving the equations

2009-10-04 Thread Berend Hasselman



dahuang wrote:
> 
> i wanna get x from the equations: Ax=x, given A is a matrix. How can i
> apply it in R? thanks
> 

?solve

-- 
View this message in context: 
http://www.nabble.com/help-about-solving-the-equations-tp25738073p25738401.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] Copying matrices with certain probabilities

2009-10-04 Thread William Aue
Hi all! Below is the problem I am struggling with.

Let’s say I have a matrix (x) of values:

# [,1] [,2] [,3] [,4]
#[1,]    1    3    2    1
#[2,]    2    1    3    2

I need to copy the items into a new matrix (y) with certain
probability guidelines. I need to set it up such that:

1. for each item there is a probability (a) that the item will or will
not be copied at all from x to y. If nothing is copied then the
corresponding value in y should be 0.

2. If something is copied from x to y, then there should be a separate
probability (b) that the items will be correctly copied to y with
items that are incorrectly copied being randomly drawn from a
geometric distribution.

So y may look like the below example. Row 1 shows that [1,2] was
copied and subsequently correctly copied but nothing else in [1,] was
copied. In [2,], [2,1] was copied but subsequently incorrectly copied,
[2,2] & [2,3] were not copied at all, and [2,4] was copied and
correctly copied.

# [,1] [,2] [,3] [,4]
#[1,]0300
#[2,]5002

I would also like to setup a loop for this process wherein if
something doesn’t get copied at all during a previous pass, then there
is the opportunity for it to be copied on a second/third/etc pass.

I hope this is clear enough. I am still a novice at R, so any
help/guidance that can be offered will be greatly appreciated.

Best,

Billy Aue

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Access to conditioning variables (lattice)

2009-10-04 Thread Deepayan Sarkar
On Thu, Sep 24, 2009 at 2:14 PM, Martin Lepage
 wrote:
>> The problem I am facing is that I do not know how to generically access
>> the conditioning variables within the panel function. In this simple
>> case, I can achieve what I want to do with the following call :
>>
>>    do_something_with(Type[which.packet()])
>>
>
> I just continued testing and I realized that the last line I wrote only
> worked on my test session because I had a object named 'Type'
> that existed in the workplace :
>
>    Type <- dataset.Type
>
> I cannot access the xyplot 'data$Type' object from within the panel
> function (although dataset$Type obviously works).
>
> I will continue my search through the documentation and report any
> success.

The way to pass extra variables to panel functions is to add arguments
to the high-level call, e.g.,

xyplot( y ~ x | Type, dataset,
   type.var = dataset$Type,
   type.levels = levels(dataset$Type)
   panel = function(..., type.var, type.levels) {
   panel.xyplot(...)
   do_something_with(type.levels[which.packet()])
   })

The fact that the extra variable here is a conditioning variable is a
coincidence. There is no special mechanism to access conditioning
variables inside the panel function.

-Deepayan

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

2009-10-04 Thread Peter Ehlers

It's probably called summaryStats() now.

 -Peter Ehlers

Rene wrote:

Dear all,

 


Have you experienced problem of using numerical.summary() function?  I used
to be able to run this function in R, but not any more.  Now I try to use
this function, it gives me error like this:

 


Error: could not find function "numerical.summary"

 


I used to be able to run this function under library(s20x).

 


Can someone please guide me on this ?

 

Thanks. 


Rene

 



[[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] add lines() to 1st plot in layout() after calling 2nd plot()?

2009-10-04 Thread Marianne Promberger
baptiste auguie 04-Oct-09 10:32:
> dev.new()
> layout(matrix(1:4,2, by=T))
> 
> plot(1:10,main="top left plot")
> plot(1:10,main="top right plot")
> plot(1:10,main="bottom left plot")
> plot(1:10,main="bottom right plot")
>
> [...]
>
> par(mfg=c(1,1))
> lines(c(3:7,7:3),col="red")

Brilliant! Thanks!

baptiste auguie 04-Oct-09 10:50:
> After some checking, I think the documentation is at best misleading
> on this particular query. Nowhere could I find mention that par(mfg)
> can work with layout. Instead, I found a warning that suggests
> incompatibility (since mpg is explicitly tied to mfrow in ?par and
> layout is said incompatible with par(mfrow)).

Indeed. I did look around ?par, but due to this warning thought
anything relating to mfrow() and mfcol() would not work anyway.

Thanks again,

Marianne


-- 
Marianne Promberger PhD, King's College London
http://promberger.info
R version 2.9.2 (2009-08-24)
Ubuntu 9.04

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


Re: [R] add lines() to 1st plot in layout() after calling 2nd plot()?

2009-10-04 Thread baptiste auguie
After some checking, I think the documentation is at best misleading
on this particular query. Nowhere could I find mention that par(mfg)
can work with layout. Instead, I found a warning that suggests
incompatibility (since mpg is explicitly tied to mfrow in ?par and
layout is said incompatible with par(mfrow)).


Relevant bits from "?par":
mfcol, mfrow
Consider the alternatives, layout and split.screen.

mfg
A numerical vector of the form c(i, j) where i and j indicate which
figure in an array of figures is to be drawn next (if setting) or is
being drawn (if enquiring). The array must already have been set by
mfcol or mfrow.

>From "?layout",

Warnings
These functions are totally incompatible with the other mechanisms for
arranging plots on a device: par(mfrow), par(mfcol) and split.screen.

See Also
par with arguments mfrow, mfcol, or mfg.


I suggest the following changes,

in ?layout, section "Details": "The user can navigate to a given cell
using the the mpg parameter (see ?par)."

in ?par, parameter "mpg": "The array must already have been set by
either mfcol, mfrow, or layout."

It may be that I missed an important incompatibility in complicated
layouts, but it seems to work at least for simple ones.

Best regards,

baptiste





2009/10/4 baptiste auguie :
> Hi,
>
> Try this,
>
> dev.new()
> layout(matrix(1:4,2, by=T))
>
> plot(1:10,main="top left plot")
> plot(1:10,main="top right plot")
> plot(1:10,main="bottom left plot")
> plot(1:10,main="bottom right plot")
>
> for (ii in 1:2){
> for (jj in 1:2){
> par(mfg=c(ii,jj))
> text(5,2, lab=paste("plot #:",ii,",",jj,sep=""))
> }
> }
> par(mfg=c(1,1))
> lines(c(3:7,7:3),col="red")
>
> HTH,
>
> baptiste
> 2009/10/4 Marianne Promberger :
>> Thanks for the quick reply. However ...
>>
>> David Winsemius  03-Oct-09 20:50:
>> MP> layout(matrix(c(1,2),1))
>> MP> plot(1:10,main="left plot")
>> MP> plot(10:1,main="right plot")
>> MP> lines(c(3:7,7:3),col="red")
>> MP>
>> MP> but of course now lines() gets added to the "right plot". I
>> MP>
>> MP> Is there any way to make the lines() go to the fist plot ("left
>> MP> plot")?
>>>
>>> If you look at layout's help page there appears to be a worked example
>>> of an even more complex task. The answer appears to be assingning
>>> numbers to regions and then inserting par(mar=  with an appropriately
>>> constructed destination arguments prior to each added piece.
>>
>> Sorry, but I fail to find the solution in the page returned by
>> ?layout, assuming that's what you mean.
>>
>> Yes, the numbers in the matrix given to layout() give the order of
>> where plots will be put, so
>>
>> layout(matrix(c(2,1),1))
>>
>> then
>>
>> plot(1:10,main="left plot")
>> plot(10:1,main="right plot")
>> lines(c(3:7,7:3),col="red")
>>
>> puts "left plot" on the right hand side and "right plot" on the
>> left. But the lines() still go to the "right plot" plot (now on the
>> left hand side) which gets called last.
>>
>> The par(mar ... of the "scatterplot with marginal histograms" example
>> just set the margins of the histogram plots, then they get plotted to
>> the region with the next number given in the layout() matrix.
>>
>> Maybe I'm missing something.
>>
>> Thanks,
>>
>> Marianne
>>
>>>
>>> --
>>> David
>>>
>>> On Oct 3, 2009, at 3:15 PM, Marianne Promberger wrote:
>>>
 Dear R users,

 I create a graphic with two plots side by side using layout(), like
 this:

 layout(matrix(c(1,2),1))
 plot(1:10,main="left plot")
 lines(c(3:7,7:3),col="red")
 plot(10:1,main="right plot")

 The lines() obivously get added to the "left plot" plot.

 Now, I'm trying to write a function that builds up a plot bit by bit
 to
 then include it in a LaTeX presentation with overlays. I'm using
 dev.copy(), and it would make my life much easier (because in fact I
 call all sorts of additional axis() etc after plot) if I could call
 the above commands in this order:

 layout(matrix(c(1,2),1))
 plot(1:10,main="left plot")
 plot(10:1,main="right plot")
 lines(c(3:7,7:3),col="red")

 but of course now lines() gets added to the "right plot". I

 Is there any way to make the lines() go to the fist plot ("left
 plot")?

 Marianne

>>>
>>> David Winsemius, MD
>>> Heritage Laboratories
>>> West Hartford, CT
>>>
>>> __
>>> R-help@r-project.org mailing list
>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>>> and provide commented, minimal, self-contained, reproducible code.
>>
>> --
>> Marianne Promberger PhD, King's College London
>> http://promberger.info
>> R version 2.9.2 (2009-08-24)
>> Ubuntu 9.04
>>
>> __
>> R-help@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and p

Re: [R] add lines() to 1st plot in layout() after calling 2nd plot()?

2009-10-04 Thread baptiste auguie
Hi,

Try this,

dev.new()
layout(matrix(1:4,2, by=T))

plot(1:10,main="top left plot")
plot(1:10,main="top right plot")
plot(1:10,main="bottom left plot")
plot(1:10,main="bottom right plot")

for (ii in 1:2){
for (jj in 1:2){
par(mfg=c(ii,jj))
text(5,2, lab=paste("plot #:",ii,",",jj,sep=""))
}
}
par(mfg=c(1,1))
lines(c(3:7,7:3),col="red")

HTH,

baptiste
2009/10/4 Marianne Promberger :
> Thanks for the quick reply. However ...
>
> David Winsemius  03-Oct-09 20:50:
> MP> layout(matrix(c(1,2),1))
> MP> plot(1:10,main="left plot")
> MP> plot(10:1,main="right plot")
> MP> lines(c(3:7,7:3),col="red")
> MP>
> MP> but of course now lines() gets added to the "right plot". I
> MP>
> MP> Is there any way to make the lines() go to the fist plot ("left
> MP> plot")?
>>
>> If you look at layout's help page there appears to be a worked example
>> of an even more complex task. The answer appears to be assingning
>> numbers to regions and then inserting par(mar=  with an appropriately
>> constructed destination arguments prior to each added piece.
>
> Sorry, but I fail to find the solution in the page returned by
> ?layout, assuming that's what you mean.
>
> Yes, the numbers in the matrix given to layout() give the order of
> where plots will be put, so
>
> layout(matrix(c(2,1),1))
>
> then
>
> plot(1:10,main="left plot")
> plot(10:1,main="right plot")
> lines(c(3:7,7:3),col="red")
>
> puts "left plot" on the right hand side and "right plot" on the
> left. But the lines() still go to the "right plot" plot (now on the
> left hand side) which gets called last.
>
> The par(mar ... of the "scatterplot with marginal histograms" example
> just set the margins of the histogram plots, then they get plotted to
> the region with the next number given in the layout() matrix.
>
> Maybe I'm missing something.
>
> Thanks,
>
> Marianne
>
>>
>> --
>> David
>>
>> On Oct 3, 2009, at 3:15 PM, Marianne Promberger wrote:
>>
>>> Dear R users,
>>>
>>> I create a graphic with two plots side by side using layout(), like
>>> this:
>>>
>>> layout(matrix(c(1,2),1))
>>> plot(1:10,main="left plot")
>>> lines(c(3:7,7:3),col="red")
>>> plot(10:1,main="right plot")
>>>
>>> The lines() obivously get added to the "left plot" plot.
>>>
>>> Now, I'm trying to write a function that builds up a plot bit by bit
>>> to
>>> then include it in a LaTeX presentation with overlays. I'm using
>>> dev.copy(), and it would make my life much easier (because in fact I
>>> call all sorts of additional axis() etc after plot) if I could call
>>> the above commands in this order:
>>>
>>> layout(matrix(c(1,2),1))
>>> plot(1:10,main="left plot")
>>> plot(10:1,main="right plot")
>>> lines(c(3:7,7:3),col="red")
>>>
>>> but of course now lines() gets added to the "right plot". I
>>>
>>> Is there any way to make the lines() go to the fist plot ("left
>>> plot")?
>>>
>>> Marianne
>>>
>>
>> David Winsemius, MD
>> Heritage Laboratories
>> West Hartford, CT
>>
>> __
>> R-help@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>
> --
> Marianne Promberger PhD, King's College London
> http://promberger.info
> R version 2.9.2 (2009-08-24)
> Ubuntu 9.04
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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] offlist Re: AW: Urgently needed Exercise solutions related to PracticalData Analysis Using R Statisctial Software

2009-10-04 Thread David Winsemius


On Oct 4, 2009, at 1:42 AM, Daniel Malter wrote:


http://www.odesk.com/jobs/College-Assistance_~~dd7622f6bdef9177



He is one very cheeky blighter isn't he?

Why would he say he was a student in a "foreign university"? Does he  
think it will lower the readers' concern for academic malfeasance if  
they believe it is not in their backyard?


--

David Winsemius, MD
Heritage Laboratories
West Hartford, CT

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


Re: [R] add lines() to 1st plot in layout() after calling 2nd plot()?

2009-10-04 Thread Marianne Promberger
Thanks for the quick reply. However ...

David Winsemius  03-Oct-09 20:50:
MP> layout(matrix(c(1,2),1))
MP> plot(1:10,main="left plot")
MP> plot(10:1,main="right plot")
MP> lines(c(3:7,7:3),col="red")
MP>
MP> but of course now lines() gets added to the "right plot". I
MP>
MP> Is there any way to make the lines() go to the fist plot ("left  
MP> plot")?
>
> If you look at layout's help page there appears to be a worked example  
> of an even more complex task. The answer appears to be assingning  
> numbers to regions and then inserting par(mar=  with an appropriately  
> constructed destination arguments prior to each added piece.

Sorry, but I fail to find the solution in the page returned by
?layout, assuming that's what you mean.

Yes, the numbers in the matrix given to layout() give the order of
where plots will be put, so 

layout(matrix(c(2,1),1))

then

plot(1:10,main="left plot")
plot(10:1,main="right plot")
lines(c(3:7,7:3),col="red")

puts "left plot" on the right hand side and "right plot" on the
left. But the lines() still go to the "right plot" plot (now on the
left hand side) which gets called last.

The par(mar ... of the "scatterplot with marginal histograms" example
just set the margins of the histogram plots, then they get plotted to
the region with the next number given in the layout() matrix.

Maybe I'm missing something.

Thanks,

Marianne

>
> -- 
> David
>
> On Oct 3, 2009, at 3:15 PM, Marianne Promberger wrote:
>
>> Dear R users,
>>
>> I create a graphic with two plots side by side using layout(), like  
>> this:
>>
>> layout(matrix(c(1,2),1))
>> plot(1:10,main="left plot")
>> lines(c(3:7,7:3),col="red")
>> plot(10:1,main="right plot")
>>
>> The lines() obivously get added to the "left plot" plot.
>>
>> Now, I'm trying to write a function that builds up a plot bit by bit  
>> to
>> then include it in a LaTeX presentation with overlays. I'm using
>> dev.copy(), and it would make my life much easier (because in fact I
>> call all sorts of additional axis() etc after plot) if I could call
>> the above commands in this order:
>>
>> layout(matrix(c(1,2),1))
>> plot(1:10,main="left plot")
>> plot(10:1,main="right plot")
>> lines(c(3:7,7:3),col="red")
>>
>> but of course now lines() gets added to the "right plot". I
>>
>> Is there any way to make the lines() go to the fist plot ("left  
>> plot")?
>>
>> Marianne
>>
>
> David Winsemius, MD
> Heritage Laboratories
> West Hartford, CT
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

-- 
Marianne Promberger PhD, King's College London
http://promberger.info
R version 2.9.2 (2009-08-24)
Ubuntu 9.04

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Paste a character to an object

2009-10-04 Thread David Winsemius


On Oct 4, 2009, at 3:40 AM, Tim Clark wrote:


David,

Thanks!  You just gave me the answer.  All I had to do was:

xx<-c()
for (i in c('100', '75', '50') )
{
x<-homerange[[1]]$polygons[[i]] ; xx<-rbind(x,xx)
}
xx

I didn't know you could use characters as index values in a for  
loop, or that you could use characters in double brackets instead of  
using the $ symbol.


Looping over vectors or lists is pretty common. Sometimes you will  
want to assign their sequence number in which case the loop would look  
like:


for (i in seq_along(c(100', '75', '50') ) { }



homerange[[1]]$polygons[['100']]
is the same as
homerange[[1]]$polygons$'100

Only if you match the quotes (at least on my version of R), and even  
that was a bit of a surprise to me. The "[[" indexing is the more  
fundamental extraction operator and is more flexible in the loop  
situation.


The list is actually the output of the NNCH function in Adehabitat.   
I thought about changing the function first, but looked at the code  
and couldn't figure it out.  I knew there had to be an easier way.


I greatly appreciate all your help,

Tim

Tim Clark
Department of Zoology
University of Hawaii


--- On Sat, 10/3/09, David Winsemius  wrote:


From: David Winsemius 
Subject: Re: [R] Paste a character to an object
To: "Tim Clark" 
Cc: r-help@r-project.org
Date: Saturday, October 3, 2009, 5:43 PM

On Oct 3, 2009, at 11:14 PM, Tim Clark wrote:


David,

Thanks, that helps me in making an example of what I

am trying to do.  Given the following example, I would
like to run through a for loop and obtain a vector of the
data only for the 100, 75, and 50 percent values.  Is
there a way to get this to work, either using paste as in
the example below or some other method?


homerange <- list()
homerange[[1]] <- "test"
homerange[[1]]$polygons <- "test2"
homerange[[1]]$polygons$`100` <- rnorm(20,10,1)
homerange[[1]]$polygons$`90` <- rnorm(20,10,1)
homerange[[1]]$polygons$`75` <- rnorm(20,10,1)
homerange[[1]]$polygons$`50` <- rnorm(20,10,1)

xx<-c()
percent<-c("100","75","50")
for (i in 1:length(percent))
{
x<-paste(homerange[[1]]$polygons$

,percent[i]) #This does not work!!!


  ^?^
And why _would_ you expect an expression ending in a "$" to
be acceptable to the parser? You did not put quotes around
it so the interpreter tried to evaluate it.

You are probably looking for the capabilities of the
functions get and assign which take string variable and
either get the object named by a sstring or assign a vlaue
to an object so named.

But why are you intent in causing yourself all this
pain?  (Not to mention asking questions I cannot
answer.)  Working with expressions involving backquotes
is a recipe for hair-pulling and frustration for us normal
mortals. Why not call your lists "p100", "p90", "p75",
"p50"? Then everything is simple:


xx<-c()
percent<-c(100, 75, 50)
for (i in c("p100", "p75", "p50") )

+ {
+ x<-homerange[[1]]$polygons[[i]] ;
xx<-rbind(x,xx)  # could have simplified this
+ }

xx

   [,1]
   [,2] [,3]
[,4] [,5]
  [,6]  [,7]
[,8] [,9]
x  9.660935 10.46526 10.75813  8.866064
9.967950  9.987941 10.757160 10.180826 9.992162
x 11.674645 10.51753 10.88061 10.515120 9.440838 11.460845
12.033612  9.318392 9.592026
x 10.057021 10.14339 10.29757  9.164233 8.977280
9.733971  9.965002  9.693649 9.430043
 [,10]
   [,11] [,12]
   [,13] [,14]
   [,15] [,16]
   [,17][,18]
x 11.78904  9.437353 11.910747 10.996167
11.631264  9.386944  9.602160 10.498921
9.09349
x  9.11036  9.546378 11.030323
9.715164  9.500268 11.762440  9.101104
9.610251 10.56210
x  9.62574 12.738020  9.146863 10.497626
10.485520 11.644503 10.303581 11.340263 11.34873
  [,19] [,20]
x 10.146955  9.640136
x  9.334912 10.101603
x  8.710609 11.265633







The x<-paste(...) in this function does not work,

and that is what I am stuck on.  The result should be a
vector the values for the "100","75",and "50" levels, but
not the "90" level.


Aloha,

Tim Clark
Department of Zoology
University of Hawaii


--- On Sat, 10/3/09, David Winsemius 

wrote:



From: David Winsemius 
Subject: Re: [R] Paste a character to an object
To: "Tim Clark" 
Cc: r-help@r-project.org
Date: Saturday, October 3, 2009, 4:45 PM

On Oct 3, 2009, at 10:26 PM, Tim Clark wrote:


Dear List,

I can't seem to get a simple paste function to

work

like I need.  I have an object I need to call

but it

ends in a character string.  The object is a

list of

home range values for a range of percent

isopleths.  I

need to loop through a vector of percent values,

so I need

to paste the percent as a character on the end of

the object

variable.  I have no idea why the percent is

in

character form, and I can't use a simple index

value

(homerange[[1]]$polygons[100]) because there are a

variable

number of isopleths that are calculated and [100]

will not

always correspond to "100".  So I am stuck.


What I want is:

homerange[[1]]$polygons$"100"

What I need is something

Re: [R] Paste a character to an object

2009-10-04 Thread Tim Clark
David,

Thanks!  You just gave me the answer.  All I had to do was:

xx<-c()
for (i in c('100', '75', '50') )
{
x<-homerange[[1]]$polygons[[i]] ; xx<-rbind(x,xx)
}
 xx

I didn't know you could use characters as index values in a for loop, or that 
you could use characters in double brackets instead of using the $ symbol.

homerange[[1]]$polygons[['100']]
is the same as
homerange[[1]]$polygons$'100

The list is actually the output of the NNCH function in Adehabitat.  I thought 
about changing the function first, but looked at the code and couldn't figure 
it out.  I knew there had to be an easier way.

I greatly appreciate all your help,

Tim

Tim Clark
Department of Zoology 
University of Hawaii


--- On Sat, 10/3/09, David Winsemius  wrote:

> From: David Winsemius 
> Subject: Re: [R] Paste a character to an object
> To: "Tim Clark" 
> Cc: r-help@r-project.org
> Date: Saturday, October 3, 2009, 5:43 PM
> 
> On Oct 3, 2009, at 11:14 PM, Tim Clark wrote:
> 
> > David,
> > 
> > Thanks, that helps me in making an example of what I
> am trying to do.  Given the following example, I would
> like to run through a for loop and obtain a vector of the
> data only for the 100, 75, and 50 percent values.  Is
> there a way to get this to work, either using paste as in
> the example below or some other method?
> > 
> > homerange <- list()
> > homerange[[1]] <- "test"
> > homerange[[1]]$polygons <- "test2"
> > homerange[[1]]$polygons$`100` <- rnorm(20,10,1)
> > homerange[[1]]$polygons$`90` <- rnorm(20,10,1)
> > homerange[[1]]$polygons$`75` <- rnorm(20,10,1)
> > homerange[[1]]$polygons$`50` <- rnorm(20,10,1)
> > 
> > xx<-c()
> > percent<-c("100","75","50")
> > for (i in 1:length(percent))
> > {
> > x<-paste(homerange[[1]]$polygons$   
> ,    percent[i]) #This does not work!!!
>                
>                
>   ^?^
> And why _would_ you expect an expression ending in a "$" to
> be acceptable to the parser? You did not put quotes around
> it so the interpreter tried to evaluate it.
> 
> You are probably looking for the capabilities of the
> functions get and assign which take string variable and
> either get the object named by a sstring or assign a vlaue
> to an object so named.
> 
> But why are you intent in causing yourself all this
> pain?  (Not to mention asking questions I cannot
> answer.)  Working with expressions involving backquotes
> is a recipe for hair-pulling and frustration for us normal
> mortals. Why not call your lists "p100", "p90", "p75",
> "p50"? Then everything is simple:
> 
> > xx<-c()
> > percent<-c(100, 75, 50)
> > for (i in c("p100", "p75", "p50") )
> + {
> + x<-homerange[[1]]$polygons[[i]] ;
> xx<-rbind(x,xx)  # could have simplified this
> + }
> > xx
>        [,1] 
>    [,2]     [,3] 
>     [,4]     [,5]   
>   [,6]      [,7]     
> [,8]     [,9]
> x  9.660935 10.46526 10.75813  8.866064
> 9.967950  9.987941 10.757160 10.180826 9.992162
> x 11.674645 10.51753 10.88061 10.515120 9.440838 11.460845
> 12.033612  9.318392 9.592026
> x 10.057021 10.14339 10.29757  9.164233 8.977280 
> 9.733971  9.965002  9.693649 9.430043
>      [,10] 
>    [,11]     [,12] 
>    [,13]     [,14] 
>    [,15]     [,16] 
>    [,17]    [,18]
> x 11.78904  9.437353 11.910747 10.996167
> 11.631264  9.386944  9.602160 10.498921 
> 9.09349
> x  9.11036  9.546378 11.030323 
> 9.715164  9.500268 11.762440  9.101104 
> 9.610251 10.56210
> x  9.62574 12.738020  9.146863 10.497626
> 10.485520 11.644503 10.303581 11.340263 11.34873
>       [,19]     [,20]
> x 10.146955  9.640136
> x  9.334912 10.101603
> x  8.710609 11.265633
> 
> 
> 
> 
> > 
> > 
> > The x<-paste(...) in this function does not work,
> and that is what I am stuck on.  The result should be a
> vector the values for the "100","75",and "50" levels, but
> not the "90" level.
> > 
> > Aloha,
> > 
> > Tim Clark
> > Department of Zoology
> > University of Hawaii
> > 
> > 
> > --- On Sat, 10/3/09, David Winsemius 
> wrote:
> > 
> >> From: David Winsemius 
> >> Subject: Re: [R] Paste a character to an object
> >> To: "Tim Clark" 
> >> Cc: r-help@r-project.org
> >> Date: Saturday, October 3, 2009, 4:45 PM
> >> 
> >> On Oct 3, 2009, at 10:26 PM, Tim Clark wrote:
> >> 
> >>> Dear List,
> >>> 
> >>> I can't seem to get a simple paste function to
> work
> >> like I need.  I have an object I need to call
> but it
> >> ends in a character string.  The object is a
> list of
> >> home range values for a range of percent
> isopleths.  I
> >> need to loop through a vector of percent values,
> so I need
> >> to paste the percent as a character on the end of
> the object
> >> variable.  I have no idea why the percent is
> in
> >> character form, and I can't use a simple index
> value
> >> (homerange[[1]]$polygons[100]) because there are a
> variable
> >> number of isopleths that are calculated and [100]
> will not
> >> always correspond to "100".  So I am stuck.
> >>> 
> >>> What I want is:
> >>> 
> >>> homerange[[1]]$polygons$"100"
> >>> 
> >>> What I need is something like the fo