[R] Why does the print method fail for very small numbers?

2022-02-17 Thread Marius Hofert
Dear expeRts, I'm familiar with IEEE 754. Is there an easy way to explain why even just printing of small numbers fails? 1e-317 # 1e-317 => fine 1e-318 # 9.87e-319 => gets tricky; seems to call print() => as.character() => format() => paste() 1e-318 == 9.87e-319 # TRUE 2.48e-324 # prints

Re: [R] R_BATCH_OPTIONS not respected?

2019-09-10 Thread Marius Hofert
On Tue, Sep 10, 2019 at 12:38 PM Martin Maechler wrote: > > >>>>> Marius Hofert > >>>>> on Mon, 9 Sep 2019 22:38:38 +0200 writes: > > > Hi, > > I typically start R with "--no-restore --no-save" (to avoid .RData >

[R] R_BATCH_OPTIONS not respected?

2019-09-09 Thread Marius Hofert
Hi, I typically start R with "--no-restore --no-save" (to avoid .RData files being written) and would like to have the same behavior under 'R CMD BATCH'. I use R_BATCH_OPTIONS="--no-restore --no-save" in my ~/.Renviron but running an R script with 'R CMD BATCH' still produces a .RData file. What's

[R] How to create the/an integer 'seed' for set.seed() from a given .Random.seed?

2019-07-20 Thread Marius Hofert
Hi, 1) Given .Random.seed, how can one compute *the* integer 'seed' such that set.seed(seed) generates .Random.seed? 2) If 1) is not possible, how can one compute *an* integer 'seed' from a given .Random.seed such that different .Random.seed's are guaranteed to give different integers 'seed' (or a

Re: [R] How to test existence of an environment and how to remove it (from within functions)?

2016-08-30 Thread Marius Hofert
Hi Duncan, ... I don't have to know (I thought). The idea was to set up the environment only for a single object x. If it (= the environment (see MWE 2) *or* the object (see MWE 1)) exists, it's the right one. But I agree that it's 'cleaner' to work with a hash -- yet I first wanted to understand

Re: [R] How to test existence of an environment and how to remove it (from within functions)?

2016-08-29 Thread Marius Hofert
anks & cheers, Marius On Mon, Aug 29, 2016 at 7:59 PM, Duncan Murdoch wrote: > On 29/08/2016 1:36 PM, Marius Hofert wrote: >> Hi, >> >> I have a function main() which calls another function aux() many times. aux() >> mostly does the same operations based on an obje

[R] How to test existence of an environment and how to remove it (from within functions)?

2016-08-29 Thread Marius Hofert
Hi, I have a function main() which calls another function aux() many times. aux() mostly does the same operations based on an object and thus I would like it to compute and store this object for each call from main() only once. Below are two versions of a MWE. The first one computes the right res

Re: [R] How to split a data.frame into its columns?

2016-08-29 Thread Marius Hofert
Hi David and Jeff, Thanks for your quick help, unclass() was precisely what I was looking for. Cheers, M On Mon, Aug 29, 2016 at 10:39 AM, aditya pant wrote: > > ^^ठश्रएइ),,, > > From: David Winsemius > Sent: ‎29-‎08-‎2016 11:59 > To: Marius H

[R] How to split a data.frame into its columns?

2016-08-28 Thread Marius Hofert
Hi, I need a fast way to split a data.frame (and matrix) into a list of columns. For matrices, split(x, col(x)) works (which can then be done in C for speed-up, if necessary), but for a data.frame? split(iris, col(iris)) does not work as expected (?). The outcome should be lapply(seq_len(ncol(iris

Re: [R] What's box() (exactly) doing?

2016-06-27 Thread Marius Hofert
On Mon, Jun 27, 2016 at 5:42 PM, Greg Snow <538...@gmail.com> wrote: > You can use the grconvertX and grconvertY functions to find the > coordinates (in user coordinates to pass to rect) of the figure region > (or other regions). > > Probably something like: > grconvertX(c(0,1), from='nfc', to='use

Re: [R] What's box() (exactly) doing?

2016-06-24 Thread Marius Hofert
col = adjustcolor("grey80", alpha.f = 0.5)) par(xpd = FALSE) On Fri, Jun 24, 2016 at 8:40 PM, Marius Hofert wrote: > Hi Jim, > > Thanks a lot, exactly what I was looking for. > > Cheers, > Marius > > > > On Thu, Jun 23, 2016 at 11:06 PM, Jim Lemon wrote: >

Re: [R] What's box() (exactly) doing?

2016-06-24 Thread Marius Hofert
gt; Finally your second example simply multiplies the first problem by > specifying a layout of more than one plot. Applying the "xaxs" and > "yaxs" parameters before you start plotting will fix this: > > par(xaxs="i",yaxs="i") > > Jim > &g

[R] What's box() (exactly) doing?

2016-06-23 Thread Marius Hofert
Hi, I would like to replicate the behavior of box() with rect() (don't ask why). However, my rect()angles are always too small. I looked a bit into the internal C_box but couldn't figure out how to solve the problem. Below is a minimal working (and a slightly bigger) example. Cheers, Marius ## M

[R] How to convert a C vector to an SEXP for using it in R_orderVector()?

2015-03-01 Thread Marius Hofert
Hi, Inside a C function (foo()), I need to call R's order(). Writing R Extensions (2014, Section 6.10) gave me the hint to use R_orderVector() for this task. The third argument of this function needs an SEXP containing (in my case) the vector x (of which I would like to determine order()). My que

Re: [R] Is there a plotmath symbol \mapsto?

2014-12-12 Thread Marius Hofert
Dear Professor Ripley, Thank you for your reply. Do you specify \u21A6 via something like this? plot(1, main=expression(symbol("\u21A6"))) This gives an the 'registered trademark symbol' (circled R) for me (also cairo-based Linux). Thanks and cheers, Marius ___

[R] Is there a plotmath symbol \mapsto?

2014-12-11 Thread Marius Hofert
Hi, Is there a plotmath symbol like LaTeX's \mapsto? I need this comparably often, for example if you want to plot a two-place function in one variable (and thus would like to have ylab="t \mapsto f(t,s)", for example). If there is such a symbol, I'd be great to have it as an example on ?plotmath.

Re: [R] Where to find source of C_pbinom?

2014-08-27 Thread Marius Hofert
Dear Ranjan, thanks, that was what I was looking for. Somehow my 'grep' must have missed that. Cheers, Marius On Wed, Aug 27, 2014 at 8:34 AM, Marius Hofert wrote: > Dear Sarah, Dear David, > > thanks for helping. I know the FAQ and I know the R News article, but > I st

Re: [R] Where to find source of C_pbinom?

2014-08-27 Thread Marius Hofert
4 at 7:28 AM, Sarah Goslee wrote: > R FAQ 7.40 > > http://cran.r-project.org/doc/FAQ/R-FAQ.html#How-do-I-access-the-source-code-for-a-function_003f > > Sarah > > > On Tuesday, August 26, 2014, Marius Hofert > wrote: >> >> Dear expeRts, >> >> I w

[R] Where to find source of C_pbinom?

2014-08-26 Thread Marius Hofert
Dear expeRts, I would like to find out how R computes pbinom(). A grep in the source code reveiled src/library/stats/R/distn.R:146: .External(C_pbinom, q, size, prob, lower.tail, log.p), so 'C_pbinom' refers to compiled C/C++ code loaded into R. Where can I find the source code of C_pbinom? Cheer

Re: [R] sort() depends on locale (and platform and build)

2014-06-15 Thread Marius Hofert
Hi, ... so something like this? [in foo.R] old.coll <- Sys.getlocale("LC_COLLATE") Sys.setlocale("LC_COLLATE", locale="C") Sys.setlocale("LC_COLLATE", locale=old.coll) Cheers, Marius __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/

Re: [R] sort() depends on locale (and platform and build)

2014-06-15 Thread Marius Hofert
Hi, Thanks for you help. I use R-devel under Ubuntu 14.04, here is the output of sessionInfo(): > sessionInfo() R Under development (unstable) (2014-06-02 r65832) Platform: x86_64-unknown-linux-gnu (64-bit) locale: [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C [3] LC_TIME=en_US.UTF-8LC_C

[R] sort() depends on locale

2014-06-14 Thread Marius Hofert
Hi, If I use invisible(Sys.setlocale("LC_COLLATE", "C")) in ~/.Rprofile, then > sort(c("L.Y", "Lu", "L.Q")) [1] "L.Q" "L.Y" "Lu" whereas using invisible(Sys.setlocale("LC_COLLATE", "en_US.UTF-8")) results in > sort(c("L.Y", "Lu", "L.Q")) [1] "L.Q" "Lu" "L.Y" I know this issue has appeared alr

Re: [R] (gam) formula: Why different results for terms being factor vs. numeric?

2013-11-02 Thread Marius Hofert
Dear Bert, Thanks for helping. Your questions 'answers' why I get the expected behavior if 'group' is a factor. My question was why I don't get the expected behavior if 'group' is not a factor. >From a theoretical (non-programming) point of view, there is no difference in a factor with two level

[R] (gam) formula: Why different results for terms being factor vs. numeric?

2013-10-29 Thread Marius Hofert
Dear expeRts, If I specify group = as.factor(rep(1:2, each=n)) in the below definition of dat, I get the expected behavior I am looking for. I wonder why I don't get it if group is *not* a factor... My guess was that, internally, factors are treated as natural numbers (and this indeed seems to be

[R] double.xmin really the smallest non-zero normalized floating-point number?

2013-09-10 Thread Marius Hofert
Hi, ?.Machine says that 'double.xmin' is 'the smallest non-zero normalized floating-point number'. On my machine, this is 2.225074e-308. However, 2.225074e-308 / 2 is > 0 and smaller than 2.225074e-308, so double.xmin is not the smallest such number (?) Am I missing anything? Cheers, Marius ___

Re: [R] double.xmin really the smallest non-zero normalized floating-point number?

2013-09-10 Thread Marius Hofert
exp(-x) being not quite 0, but x=746 leads to exp(-x)==0 being TRUE. But these are integer x's... Many thanks and cheers, Marius > > Bill Dunlap > Spotfire, TIBCO Software > wdunlap tibco.com > > >> -Original Message----- >> From: r-help-boun...@r-project.or

[R] How to construct a 'proper' Q-Q line in log-log space?

2013-06-29 Thread Marius Hofert
Dear expeRts, I would like to create a Q-Q plot including a Q-Q line for Gamma distributed data. The specialty is that it should be in log-log scale. For Q-Q line in log-log scale, I discovered the argument 'untf' of abline. As you can see in 2), this works fine. But for 3) it does not provide the

Re: [R] aggregate(), tapply(): Why is the order of the grouping variables not kept?

2013-03-12 Thread Marius Hofert
> > I'm no expeRt, but suppose that we change the setup slightly: > > xx <- x[sample(nrow(x)), ] > > Now what would you like > > aggregate(value ~ group + year, data=xx, FUN=function(z) z[1]) > > to return? > > Personally, I prefer to have R return the same thing regardless > of how the input da

[R] aggregate(), tapply(): Why is the order of the grouping variables not kept?

2013-03-11 Thread Marius Hofert
Dear expeRts, The question is rather simple: Why does aggregate (or similarly tapply()) not keep the order of the grouping variable(s)? Here is an example: x <- data.frame(group = rep(LETTERS[1:2], each=10), year = rep(rep(2001:2005, each=2), 2), value = rep(1:1

Re: [R] How to 'extend' a data.frame based on given variable combinations ?

2013-03-11 Thread Marius Hofert
tply, by=c("group", "year"), all=TRUE) # merge the two data.frames tply$num[is.na(tply$num)] <- 0 tply Marius Hofert <> writes: > Dear expeRts, > > I have a data.frame with certain covariate combinations ('group' and 'year') >

[R] How to 'extend' a data.frame based on given variable combinations ?

2013-03-11 Thread Marius Hofert
Dear expeRts, I have a data.frame with certain covariate combinations ('group' and 'year') and corresponding values: set.seed(1) x <- data.frame(group = c(rep("A", 4), rep("B", 3)), year = c(2001, 2003, 2004, 2005, 2003, 2004, 2005),

Re: [R] How to construct a valid seed for l'Ecuyer's method with given .Random.seed?

2013-01-24 Thread Marius Hofert
Thanks a lot, Duncan, that solved it! Cheers, Marius Duncan Murdoch writes: > On 13-01-24 2:09 AM, Marius Hofert wrote: >> Dear Daniel, >> >> That's exactly what I also suspected (last post). The question now seems how >> to >> correctly convert .Rando

Re: [R] How to construct a valid seed for l'Ecuyer's method with given .Random.seed?

2013-01-23 Thread Marius Hofert
Dear Daniel, That's exactly what I also suspected (last post). The question now seems how to correctly convert .Random.seed from signed to unsigned so that it is accepted by the rlecuyer package. Cheers, Marius __ R-help@r-project.org mailing list ht

Re: [R] How to construct a valid seed for l'Ecuyer's method with given .Random.seed?

2013-01-23 Thread Marius Hofert
Dear Hana, Thanks for helping. I am still wondering, why m1 (which should be 2^32-209 [see line 34 in ./src/RngStream.c]) is -767742437 in my case and why the minimal example you gave was working for you but isn't for me. Apart from that, ?.Random.seed -> "L'Ecuyer-CMRG" says: , | The 6 ele

Re: [R] How to construct a valid seed for l'Ecuyer's method with given .Random.seed?

2013-01-23 Thread Marius Hofert
Since clusterSetupRNG() calls clusterSetupRNGstream() and this calls .lec.SetPackageSeed(), I could further minimalize the problem: set.seed(1) RNGkind("L'Ecuyer-CMRG") # => .Random.seed is of length 7 (first number encodes the rng kind) (seed <- .Random.seed[2:7]) # should give a valid seed for

Re: [R] How to construct a valid seed for l'Ecuyer's method with given .Random.seed?

2013-01-22 Thread Marius Hofert
I updated to the latest CRAN versions of 'rlecuyer', 'Rmpi', and 'snow': ,[ sessionInfo() ] | ... | other attached packages: | [1] rlecuyer_0.3-3 Rmpi_0.6-1 snow_0.3-10 | ... ` But I still obtain: , | Error in .lec.SetPackageSeed(seed) : | Seed[1] >= -1065242851, Seed i

Re: [R] How to construct a valid seed for l'Ecuyer's method with given .Random.seed?

2013-01-22 Thread Marius Hofert
;> library(snow) >> RNGkind("L'Ecuyer-CMRG") >> cl <- makeCluster(parallel::detectCores(), type="MPI") > 4 slaves are spawned successfully. 0 failed. >> .t <- snow::clusterSetupRNG(cl, seed=.Random.seed[2:7]) >> stopCluster(cl) > >

[R] How to construct a valid seed for l'Ecuyer's method with given .Random.seed?

2013-01-22 Thread Marius Hofert
Dear expeRts, I struggle with the following problem using snow clusters for parallel computing: I would like to specify l'Ecuyer's random number generator. Base R creates a .Random.seed of length 7, the first value indicating the kind fo random number generator. I would thus like to use the com

[R] tables package: How to remove column headings and alignment issues

2013-01-18 Thread Marius Hofert
Dear expeRts, Here is a minimal example with the latest version of 'tables' (questions below): require(tables) saveopts <- table_options(toprule="\\toprule", midrule="\\midrule", bottomrule="\\bottomrule", titlerule="\\cmidrule(lr)", rowlabeljustification="r")#, justi

[R] How to efficiently compare each row in a matrix with each row in another matrix?

2012-12-08 Thread Marius Hofert
Dear expeRts, I have two matrices A and B. They have the same number of columns but possibly different number of rows. I would like to compare each row of A with each row of B and check whether all entries in a row of A are less than or equal to all entries in a row of B. Here is a minimal work

Re: [R] Constant (= wrong) historical quotes via get.hist.quote() from yahoo.finance

2012-11-23 Thread Marius Hofert
gt; On Fri, 23 Nov 2012, Marius Hofert wrote: > >> Dear expeRts, >> >> I would like to download a time series of historical data from the ticker >> with >> symbol "ROG.VX". Interestingly, I obtain constant values (138.3 for each day >> in the chosen p

[R] Constant (= wrong) historical quotes via get.hist.quote() from yahoo.finance

2012-11-22 Thread Marius Hofert
Dear expeRts, I would like to download a time series of historical data from the ticker with symbol "ROG.VX". Interestingly, I obtain constant values (138.3 for each day in the chosen period) although the yahoo.finance website tells me that the time series is not at all constant. What's wrong?

[R] \lstdefinelanguage error: undefined control sequence

2012-11-02 Thread Marius Hofert
Dear expeRts, I'm trying to use the package SweaveListingUtils, but the rather minimal example below leads to , | ./minimal.tex:43: Undefined control sequence. | l.43 \lstdefinelanguage |{Rd}[common]{TeX}% | ? ` Why? Cheers, Marius \documentclass[article]{jss}

Re: [R] How to nicely display R code with the LaTeX package 'listings'?

2012-11-01 Thread Marius Hofert
ell > wrote: >> The knitr package makes this relatively easy to do. See for example >> http://biostat.mc.vanderbilt.edu/KnitrHowto >> >> Frank >> >> >> Marius Hofert-3 wrote >>> Dear expeRts, >>> >>> What's a 'good&#x

[R] How to nicely display R code with the LaTeX package 'listings'?

2012-11-01 Thread Marius Hofert
Dear expeRts, What's a 'good' (nice-looking, easy-to-read) setup for the LaTeX package 'listings' to display R code? The two versions below are partly inspired by the settings of the package SweaveListingUtils and http://r.789695.n4.nabble.com/R-How-to-format-R-code-in-LaTex-documents-td816055.ht

Re: [R] grid(Base): How to avoid "Figure region too small and/or viewport too large" by specifying 'relative' units?

2012-10-22 Thread Marius Hofert
ith the diagram. > If you change your grid.show.layout() call to the following (which "removes" > the > normal margin used by grid.show.layout()) ... > > grid.show.layout(gl, vp=viewport(width=1.25, height=1.25)) > > ... then you should find your viewports line up with

Re: [R] quantile regression using copulas

2012-10-21 Thread Marius Hofert
Please note: 1) your example is not working in the way you provided it (see http://www.minimalbeispiel.de/mini-en.html) 2) you receive a warning, not an error 3) I'd try and debug qua.regressCOP2 to see why the warning appears 4) in case 3) does not help, contact the maintainer of copBasic (Willia

Re: [R] grid(Base): How to avoid "Figure region too small and/or viewport too large" by specifying 'relative' units?

2012-10-19 Thread Marius Hofert
In the meanwhile, I found a more minimal example which shows the problem (just change 'inch' to TRUE to see the difference): require(grid) inch <- FALSE # TRUE d <- if(inch) 5 else 1 pspc <- d*c(0.3, 0.3) # width, height of panels spc <- d*c(0.05, 0.05) # width, height of space axlabspc <- d*c(

[R] grid(Base): How to avoid "Figure region too small and/or viewport too large" by specifying 'relative' units?

2012-10-19 Thread Marius Hofert
Dear grid-expeRts, The goal: I would like to construct a plot (matrix) with grid and gridBase, which consists of four "sub-plots". The sub-plots should have a square plotting region as one would force with par(pty="s") in base graphics. The problem: I don't get a square plotting region, not eve

Re: [R] Background color in a grid plot seems to interfere with plot()

2012-09-26 Thread Marius Hofert
Dear Paul, Many thanks, that solved it. Cheers, Marius Paul Murrell writes: > Hi > > On 25/09/2012 6:10 p.m., Marius Hofert wrote: >> Dear Paul, >> >> Thanks. Redrawing the points solves it for the minimal example, but >> what happens if you have plot(..,

Re: [R] Background color in a grid plot seems to interfere with plot()

2012-09-24 Thread Marius Hofert
="n", yaxt="n") grid(col="white", lty="solid", lwd=1.6, equilogs=FALSE) # background grid upViewport() } } par(par.) dev.off() Paul Murrell writes: > Hi > > On 25/09/12 11:50, Marius Hofert wrote: >> Dear Paul, >> >

Re: [R] Background color in a grid plot seems to interfere with plot()

2012-09-24 Thread Marius Hofert
frame.plot=FALSE, xaxt="n", yaxt="n") grid(col="white", lty="solid", lwd=1.6, equilogs=FALSE) # background grid upViewport() } } par(par.) dev.off() Paul Murrell writes: > Hi > > On 24/09/12 18:06, Marius Hofert wrote:

Re: [R] Background color in a grid plot seems to interfere with plot()

2012-09-23 Thread Marius Hofert
Embedded Controllers) .OO#. .OO#. rocks...1k > --- > Sent from my phone. Please excuse my brevity. > > Marius Hofert wrote: > >>Dear Paul, >> >>Thank you for helping. T

Re: [R] Background color in a grid plot seems to interfere with plot()

2012-09-23 Thread Marius Hofert
par(plt=gridPLT()) ## plot par(new=TRUE) # always do this before each new 'graphics' plot grid(col=1) plot(1:10, 1:10, log="y", xlab="", ylab="", xaxt=if(i==2) "s" else "n", yaxt=if(j==1) &q

[R] Background color in a grid plot seems to interfere with plot()

2012-09-23 Thread Marius Hofert
Hi, Why does the upper left panel (in the plot below) not have a gray background? Cheers, Marius require(grid) require(gridBase) pdf(file="Rplot.pdf", width=8, height=8, onefile=FALSE) ## set up the grid layout gl <- grid.layout(5, 5, widths=unit(c(1.8, 8, 0.8, 8, 0.8), "cm"),

Re: [R] grid: How to merge cells in grid.layout?

2012-09-23 Thread Marius Hofert
Ahh, now I see what you mean... Thanks, that indeed works. Cheers, Marius Marius Hofert writes: > Bert Gunter writes: > >> Inline below. >> >> On Sun, Sep 23, 2012 at 1:41 AM, Marius Hofert >> wrote: >>> Dear grid expeRts, >>> >>>

Re: [R] grid: How to merge cells in grid.layout?

2012-09-23 Thread Marius Hofert
Bert Gunter writes: > Inline below. > > On Sun, Sep 23, 2012 at 1:41 AM, Marius Hofert > wrote: >> Dear grid expeRts, >> >> I would like to create a layout with grid that looks like the following, but >> with cells (1,1), (1,4), (4,1), and (4,4) removed and

[R] grid: How to merge cells in grid.layout?

2012-09-23 Thread Marius Hofert
Dear grid expeRts, I would like to create a layout with grid that looks like the following, but with cells (1,1), (1,4), (4,1), and (4,4) removed and cells (2,1) and (3,1) (and (4,2) and (4,3)) combined to one cell (so that contents can easily be centered. How can this be achieved? requir

Re: [R] How to determine R version?

2012-09-22 Thread Marius Hofert
Thanks, Berend, that works. Cheers, Marius Berend Hasselman writes: > On 22-09-2012, at 19:32, Marius Hofert wrote: > >> Hi, >> >> What's the best approach to determine if a user uses an R version before >> 2.15.1 >> patched? >> I know that

[R] How to determine R version?

2012-09-22 Thread Marius Hofert
Hi, What's the best approach to determine if a user uses an R version before 2.15.1 patched? I know that the sessionInfo() command provides details, but I'm not sure how the output of sessionInfo() is best used to determine R versions. This seems to work, but a) there is certainly a better way and

Re: [R] How to convert the output of tapply() so that it has the same order as the input?

2012-09-15 Thread Marius Hofert
Dear Bill, Thanks a lot for your quick reply, that was exactly what I was looking for. Cheers, Marius William Dunlap writes: > Does ave() do what you want? > y. <- ave(x$value, x$x1, x$x2, FUN=function(x)x) > > Bill Dunlap > Spotfire, TIBCO Software > wdunlap tibco.com > >

[R] How to convert the output of tapply() so that it has the same order as the input?

2012-09-15 Thread Marius Hofert
Hi, I try to apply a function to subsets of a data.frame. tapply() does the job, but the as output, I am looking for a vector (not an array/matrix) ordered in the same way as the original data, so I can simply cbind the result to the original data.frame. Below is a minimal example. I know that th

Re: [R] How to insert vertical space between lines of tables created with the R package 'tables'?

2012-09-08 Thread Marius Hofert
Duncan Murdoch writes: > > The + means concatenation, so that spec says to put the RowFactor above the > d*beta rows. Not sure why that causes an error, but it's likely because > you've > got the wrong number of items. > > This should work, but it doesn't give you the extra spacing properly.

[R] How to insert vertical space between lines of tables created with the R package 'tables'?

2012-09-08 Thread Marius Hofert
I have the data frame... df <- cbind(expand.grid(d=as.factor(c(2,5)), n=c(100, 200), beta=as.factor(c(0.2, 0.8)), group=LETTERS[1:2]), value=runif(16)) ... which I would like to display in a table like ... require(tables) tabular(d * beta ~ group * mean * Heading() * value, data=df) Now I would

Re: [R] patchDVI: how to pass encoding of the .Rnw file?

2012-08-24 Thread Marius Hofert
Dear Duncan, many thanks for helping. It works fine. Cheers, Marius Duncan Murdoch writes: > On 12-08-19 3:47 PM, Marius Hofert wrote: >> Dear Duncan, >> >> I recently asked a question concerning patchDVI on r-help, see >> >> , >> | https://st

[R] How to call patchDVI::SweavePDF on an .Rnw which is not the master file?

2012-08-16 Thread Marius Hofert
Dear expeRts, I have a master file master.tex containing the preamble and which inputs (via \input{chapter01}, \input{chapter02}, ...) chapters. The chapters are .Rnw files. My goal is to use patchDVI::SweavePDF to compile the chapters (say, chapter.Rnw) individually (each chapter starts with sour

Re: [R] Hmisc's latex: na.blank and grouping not working as expected

2012-05-02 Thread Marius Hofert
ted due to "cgroup", but I don't know how to avoid this. On 2012-05-02, at 09:26 , Marius Hofert wrote: > Dear expeRts, > > Why does na.blank=TRUE not replace the NA's in the following LaTeX table? > > x <- matrix(1:72, ncol=4, nrow=8) > colnames(x) <-

[R] Hmisc's latex: na.blank and grouping not working as expected

2012-05-02 Thread Marius Hofert
Dear expeRts, Why does na.blank=TRUE not replace the NA's in the following LaTeX table? x <- matrix(1:72, ncol=4, nrow=8) colnames(x) <- c("gr1.sgr1", "gr1.sgr2", "gr2.sgr1", "gr2.sgr2") rn <- apply(expand.grid(beta=c(0.25, 0.75), n=c(100, 500), d=c(10, 100))[, 3:1], 2, rmNames) x <- cbind(rn, x

Re: [R] How to colorize the panel backgrounds of pairs()?

2012-03-02 Thread Marius Hofert
Okay, one simply has to use label.pos=0.5 in pairs() to get the correct behavior. On 2012-03-02, at 09:10 , Marius Hofert wrote: > Dear Ilai, > > I tried to also adjust the diagonal panels. However, the variable names are > not > positioned correctly anymore. Do you

Re: [R] How to colorize the panel backgrounds of pairs()?

2012-03-02 Thread Marius Hofert
else "transparent" ll <- par("usr") rect(ll[1], ll[3], ll[2], ll[4], col=bg) points(x, y, cex=0.5) } mydiag.panel <- function(x, ...){ ll <- par("usr") rect(ll[1], ll[3], ll[2], ll[4], col="#FDFF65") } U <- matrix(runif(4*5

[R] How to colorize the panel backgrounds of pairs()?

2012-03-01 Thread Marius Hofert
Dear expeRts, I would like to colorize the backgrounds of a pairs plot according to the respective panel number. Here is what I tried (without success): count <- 0 mypanel <- function(x, y, ...){ count <<- count+1 bg. <- if(count %in% c(1,4,9,12)) "#FDFF65" else NA points(x, y, cex=0

[R] Fwd: How to access the panel rows/columns in pairs()?

2012-01-21 Thread Marius Hofert
okay, I found something. Not very elegant, but it does the job: ## generate data U <- matrix(runif(4000), ncol=4) ## define panel function for colorizing the panels cols <- c("blue", "black", "black", "blue", "black", "black", "black", "black", "green", "black", "bla

[R] How to access the panel rows/columns in pairs()?

2012-01-21 Thread Marius Hofert
Hi, I would like to colorize certain panels in the pairs plot below with certain colors. How can access the panel row and column in a pairs plot to achieve this? Cheers, Marius ## generate data U <- matrix(runif(4000), ncol=4) ## define panel function for colorizing the panels mypanel <- fun

Re: [R] How to color a region in a contour plot with the contour being the boundary?

2012-01-03 Thread Marius Hofert
<- pmax(f(dat$x) + f(dat$y) - 10, 0) > > levelplot(z ~ x * y, dat, > at=c(-1, 0.02, 1, 5, 10, 20, 50, 500, 900), > labels=TRUE, contour=TRUE, colorkey=FALSE, > col.regions=gray(c(0.2, 0.5, 0.6, 0.7, 0.8, 0.9, 1, 1))) > > Jean >

[R] How to color a region in a contour plot with the contour being the boundary?

2011-12-31 Thread Marius Hofert
Dear expeRts, I would like to color a certain region in a levelplot. The region for z <= 0.02 should have a dark gray color. Below is a minimal example. It almost does what I want, but The region between z=0.02 and z=1 is also colored in dark gray (instead of just the region for z <= 0.02). How

[R] acast: how to obtain names?

2011-11-18 Thread Marius Hofert
Hi, After applying acast() I typically have to adjust the names of the array by hand. Is there any way to tell acast to do this automatically? Cheers, Marius require(reshape2) (df <- data.frame(a=c("a1","a2"), b=c("b1","b2"), c=c("c1","c2"))) a.df <- acast(df, a~b, value_var="c") names(dimname

Re: [R] Rgl and plotmath symbols (via sprites): a trial

2011-09-09 Thread Marius Hofert
;) par3d(windowRect=c(0,0,600,600), zoom=1.6) rgl.snapshot("W.png", fmt="png") # print to file On 2011-09-09, at 17:26 , Duncan Murdoch wrote: > On 09/09/2011 11:10 AM, Marius Hofert wrote: >> Dear all, >> >> Below is some code where I try to get plotmath

Re: [R] rgl: axis/viewport/box problems in persp3d()

2011-09-09 Thread Marius Hofert
Dear Duncan, thanks a lot. Is it possible to rotate the label drawn by mtext3d, say, by 90 degrees? [a "rot=90" did not help] Cheers, Marius On 2011-09-09, at 14:32 , Duncan Murdoch wrote: > On 09/09/2011 8:02 AM, Marius Hofert wrote: >> Dear Duncan, >> >>

Re: [R] rgl: axis/viewport/box problems in persp3d()

2011-09-09 Thread Marius Hofert
t(zoom=pl$zoom, fov=pl$FOV, userMatrix=pl$userMatrix, interactive=FALSE) # set the viewpoint for the next plot to make sure it looks the same On 2011-09-09, at 12:41 , Duncan Murdoch wrote: > On 11-09-09 6:18 AM, Marius Hofert wrote: >> Dear expeRts, >> >> I am a new us

[R] rgl: axis/viewport/box problems in persp3d()

2011-09-09 Thread Marius Hofert
Dear expeRts, I am a new user of rgl, below is my first trial to plot a simple function in 3d. I managed to put the axes in the right locations, but: (1) The xlab, ylab, and zlab arguments are ignored; how can I put in axes labels? (2) Since I removed the axes in persp3d() the viewport is too s

Re: [R] Best way/practice to create a new data frame from two given ones with last column computed from the two data frames?

2011-08-18 Thread Marius Hofert
Dear all, okay, I found a one liner based on mutate: (df3 <- mutate(df1, Value=Value[order(Year,Group)] / df2[with(df2, order(Year,Group)),"Value"])) Cheers, Marius On 2011-08-18, at 20:41 , Marius Hofert wrote: > Dear expeRts, > > What is the best approach to cre

[R] Best way/practice to create a new data frame from two given ones with last column computed from the two data frames?

2011-08-18 Thread Marius Hofert
Dear expeRts, What is the best approach to create a third data frame from two given ones, when the new/third data frame has last column computed from the last columns of the two given data frames? ## Okay, sounds complicated, so here is an example. Assume we have the two data frames: df1 <- dat

Re: [R] How to apply a function to subsets of a data frame *and* obtain a data frame again?

2011-08-17 Thread Marius Hofert
Dear all, thanks a lot for the quick help. Below is what I built with the hint of Nick. Cheers, Marius library(plyr) set.seed(1) (df <- data.frame(Group=rep(c("Group1","Group2","Group3"), each=10), Value=c(rexp(10, 1), rexp(10, 4), rexp(10, 10)))[sample(1:30,30),]) edf <-

[R] How to apply a function to subsets of a data frame *and* obtain a data frame again?

2011-08-17 Thread Marius Hofert
Dear all, First, let's create some data to play around: set.seed(1) (df <- data.frame(Group=rep(c("Group1","Group2","Group3"), each=10), Value=c(rexp(10, 1), rexp(10, 4), rexp(10, 10)))[sample(1:30,30),]) ## Now we need the empirical distribution function: edf <- function(x) e

Re: [R] lattice: How to vertically adjust an axis label?

2011-07-09 Thread Marius Hofert
ainly dirty, but it solves the problem :-) Cheers, Marius On 2011-07-09, at 24:12 , David Winsemius wrote: > > On Jul 8, 2011, at 6:54 PM, Marius Hofert wrote: > >> Dear expeRts, >> >> How can I vertically adjust an axis tick label so that it is nicely alig

[R] lattice: How to vertically adjust an axis label?

2011-07-08 Thread Marius Hofert
Dear expeRts, How can I vertically adjust an axis tick label so that it is nicely aligned with the other labels? library(lattice) xyplot(0~0, xlim=c(0,3), scales=list(x=list(at=c(1,1.1), labels=c(expression(hat(theta)[italic(n)]),expression(theta) ## aim: move the leftmost expression up so t

Re: [R] Odp: data.frame: How to get the classes of all components and how to remove their factor structure?

2011-06-28 Thread Marius Hofert
Dear Petr, thanks for your posts, they perfectly answered my questions. Cheers, Marius On 2011-06-28, at 09:49 , Petr PIKAL wrote: >> >> Dear expeRts, >> >> I have two questions concerning data frames: >> (1) How can I apply the class function to each component in a > data.frame? >> As yo

[R] data.frame: How to get the classes of all components and how to remove their factor structure?

2011-06-27 Thread Marius Hofert
Dear expeRts, I have two questions concerning data frames: (1) How can I apply the class function to each component in a data.frame? As you can see below, applying class to each column is not the right approach; applying it to each component seems bulky. (2) After transforming the data frame a b

Re: [R] Tricky (?) conversion from data.frame to matrix where not all pairs exist

2011-06-22 Thread Marius Hofert
Hi David, thanks for the quick response. That's nice. Is there also a way without loading an additional package? I'd prefer loading less packages if possible. Cheers, Marius On 2011-06-22, at 15:38 , David Winsemius wrote: > > On Jun 22, 2011, at 9:19 AM, Marius Hofert

Re: [R] Tricky (?) conversion from data.frame to matrix where not all pairs exist

2011-06-22 Thread Marius Hofert
gt;> >>> library(reshape) >>> as.matrix(cast(df, year ~ block, fill = 0)) >>>a b c >>> 2000 1 0 5 >>> 2001 2 4 6 >>> 2002 3 0 0 >>> >>> Hopefully this is more helpful... >>> Dennis >>> >>&g

Re: [R] Tricky (?) conversion from data.frame to matrix where not all pairs exist

2011-06-21 Thread Marius Hofert
>> 2000 1 0 5 >> 2001 2 4 6 >> 2002 3 0 0 >> >> HTH, >> Dennis >> >> On Tue, Jun 21, 2011 at 3:13 PM, Marius Hofert wrote: >>> Dear expeRts, >>> >>> In the minimal example below, I have a data.frame containing three &

[R] Tricky (?) conversion from data.frame to matrix where not all pairs exist

2011-06-21 Thread Marius Hofert
Dear expeRts, In the minimal example below, I have a data.frame containing three "blocks" of years (the years are subsets of 2000 to 2002). For each year and block a certain "value" is given. I would like to create a matrix that has row names given by all years ("2000", "2001", "2002"), and c

Re: [R] plot + axis: Individually moving tick labels with hadj?

2011-06-03 Thread Marius Hofert
) twice: > > plot(1:5, 5:1, xaxt="n") > axis(1, at=1:5, labels=c(1,2,"",4,5)) > axis(1, at=3.15, tick=FALSE, labels=expression(3==beta[foo])) > > Sarah > > On Fri, Jun 3, 2011 at 7:02 AM, Marius Hofert wrote: >> Dear all, >> >>

[R] plot + axis: Individually moving tick labels with hadj?

2011-06-03 Thread Marius Hofert
Dear all, consider the following plot: plot(1:5, 5:1, xaxt="n") axis(1, at=1:5, labels=c(1,2,expression(3==beta[foo]),4,5)) the label at 3 is not nice, so consider this plot(1:5, 5:1, xaxt="n") axis(1, at=1:5, labels=c(1,2,expression(3==beta[foo]),4,5), padj=c(0,0,0.18,0,0)) Now

Re: [R] lattice + plotmath: how to get a variable in bold face?

2011-06-02 Thread Marius Hofert
s.character(N), where N is a number. > That trick obviously won't work for symbols, as noted above. > > Dennis > > On Thu, Jun 2, 2011 at 3:50 PM, Marius Hofert wrote: >> Dear all, >> >> How can I get a bold "1000" in the title? I would like to us

[R] lattice + plotmath: how to get a variable in bold face?

2011-06-02 Thread Marius Hofert
Dear all, How can I get a bold "1000" in the title? I would like to use a variable (as opposed to putting in "1000" directly). library(lattice) N <- 1000 xyplot(0~0, xlab.top=list(label=as.expression(bquote(bold("foo" ~ .(N) ~ "bar"))), font=2, cex=1.2)) ## => "font=2" is ignored (of course)

Re: [R] plotmath: paste string and expression [from a vector of expressions]

2011-06-02 Thread Marius Hofert
pressions are not evaluated. You need a call object rather than an > expression inside of bquote(). > > HTH, > Dennis > > On Thu, Jun 2, 2011 at 11:43 AM, Marius Hofert wrote: >> Dear all, >> >> I have a vector of expressions and would like to "paste" so

Re: [R] plotmath: paste string and expression [from a vector of expressions]

2011-06-02 Thread Marius Hofert
k... Cheers, Marius On 2011-06-02, at 22:14 , Uwe Ligges wrote: > > > On 02.06.2011 20:43, Marius Hofert wrote: >> Dear all, >> >> I have a vector of expressions and would like to "paste" some string to it >> before using it in a plot: >>

[R] plotmath: paste string and expression [from a vector of expressions]

2011-06-02 Thread Marius Hofert
Dear all, I have a vector of expressions and would like to "paste" some string to it before using it in a plot: vars <- vector("expression", 2) vars[1] <- expression(alpha) vars[2] <- expression(beta) plot(0, 0, main=substitute(bold("Foo" ~~ VAR), list(VAR=vars[2]) )) Although I tried hard, I j

[R] ftable: how to replace NA and format entries without changing their mode?

2011-05-28 Thread Marius Hofert
Dear all, another ftable problem, now related to formatC. One typically would like to format entries in an ftable (adjust digits, replace NA, ...) before format() is applied to convert the formatted ftable to an object which xtable can deal with. The output of xtable can then be used within a La

  1   2   3   >