Displaying 20 results from an estimated 20000 matches similar to: "Sum a list of tables"
2012 Jul 02
5
ggplot: dodge positions
Dear all,
I want to get a series of boxplots (grouped by two factors) and I want to overlay the original observations and the following code does almost what I want:
library(ggplot)
ddf <- data.frame(x=factor(rep(LETTERS[1:4], each=30)), y = runif(120,0,10), grp = factor(rep(rep(1:3, 10), 4)))
ggplot(ddf, aes(x, y, colour=grp)) + geom_boxplot() + geom_point()
Yet the position of the points
2012 Oct 31
1
aggregate.formula: formula from string
Dear all,
I want to use aggregate.formula to conveniently summarize a data.frame. I have quiet some variables in the data.frame and thus I don't want to write all these names by hand, but instead create them on the fly. This approach has the advantage that if there will be even more columns in the data.frame I don't have to change the code.
I've hence tried to construct a formula
2010 Dec 13
1
predict.lm[e] with formula passed as a variable
Dear all,
In a function I paste a string and convert it to a formula which I pass
to lm[e]. The idea is to write a function which takes the name of the
response variable and the explanatory variable and the data frame as an
argument and calculates an lm[e]. (see example below)
This works fine, but if I want to make a prediction on this model, R
complains that the object holding the formula
2011 Jan 05
1
Minimum of an ordered factor
Hi everybody,
Is there a particular reason, why this code does not work as intended:
z <- factor(LETTERS[1:3], ordered = TRUE)
u <- 4:6
min(z[u > 4])
Error in Summary.factor(2:3, na.rm = FALSE) :
min not meaningful for factors
I agree that min is indeed not meaningful for not ordered factors, but
it makes sense for ordered factors. Especially since
z[3] <
2012 Dec 10
1
Sweep out control
Dear all,
Assume that I have the following data structure:
d <- expand.grid(subj=1:5, time=1:3, treatment=LETTERS[1:3])
d$value <- 10 ^ (as.numeric(d$treatment) + 1) + 10 * d$subj + d$time
d$value2 <- 100000 + d$value
where d$treatment == "C" stands for my control group. What I want to achieve now is to subtract the values corresponding to d$treatment == "C" from
2012 Jul 03
2
ggplot2: legend
Dear all,
I produced the following graph with ggplot which is almost fine, yet I don't like that the legend for "Means" and "Observations" includes a line, though no line is used in the plot for those two (the line for "Overall Mean" on the other hand is wanted):
library(ggplot2)
ddf <- data.frame(x = factor(rep(LETTERS[1:2], 5)), y = rnorm(10))
p <-
2010 Aug 30
1
lattice: limits in reversed order with relation="same"
Hi everybody,
I want an x-axis which has xlim=c(max, min) rather than xlim=c(min, max)
in order to reflect the type of the process (cooling):
library(lattice)
myprepanel <- function(x,y,...) list(xlim=rev(range(x)))
x <- rep(1:10, 100)
z <- factor(sample(10, 1000, T))
y <- rnorm(1000, x, as.numeric(z))
xyplot(y~x|z, scales=list(x="free"), prepanel=myprepanel)
This works
2011 Oct 21
1
droplevels: drops contrasts as well
Dear all,
Today I figured out that there is a neat function called droplevels,
which, well, drops unused levels in a data frame. I tried the function
with some of my data sets and it turned out that not only the unused
levels were dropped but also the contrasts I set via "C". I had a look
into the code, and this behaviour arises from the fact that droplevels
uses simply factor to drop
2010 May 04
1
Lazy evaluation in function call
Hi everybody,
how is it possible to refer to an argument passed to a function in the
function call? What I like to do, is something like
f <- function(x,y) x+y
f(2, x) # should give 4
The problem is of course that x is only known inside the function. Of course I
could specify something like
f(z<-2,z)
but I'm just curious whether it is possible to use a fancy combination of
eval,
2004 Apr 19
3
How to write an S4 method for sum or a Summary generic
If I have a class Foo, then i can write an S3 method for sum for it:
>setClass("Foo",representation(a="integer"));aFoo=new("Foo",a=c(1:3,NA))
>sum.Foo <- function(x,na.rm){print(x);print(na.rm);sum(x at a,na.rm=na.rm)}
>sum(aFoo)
But how do I write an S4 method for this? All my attempts to do so have
foundered. For example
2012 Feb 13
1
Overwrite S3 methond from base package
Dear all,
I am developing a package, which bundles my most frequently used
functions. One of those is a modified version of droplevels from the
base package (basically, it preserves any contrast function which was
used to create the factor, contrast matrices are not kept, for they
could be wrong if a level is dropped).
In my NAMESPACE file I've the following directives, which should export
2010 Jun 21
2
list() assigning the same value to two items
Hi everybody,
I'd like to have a list with two elements, where both elements have the same value:
z <- list(a=1, b=1)
If it happens, that I've to change the value, I've to assure that I change both. This is error prone. Hence, a better way to achieve this is to define:
tmp <- 1
z <- list(a=tmp, b=tmp)
Now, I'm wondering if it is possible to make this more compact:
z
2003 Jul 03
1
S4 method and S3 method with same name: potentially dangerous?
Dear list,
yet another question on S4 method behaviour or rather its side effects:
Consider the following example (see below) where a new S4 method 'predict' is
defined which by doing so makes 'predict' a S4 standardGeneric.
It works and simple test examples run but I'm cautious whether this is a 'silly'
thing to do.
Is this a dangerous thing to do, already known to
2009 Jul 06
3
Speed up code, profiling, optimization, lapply vs. loops
High everybody,
currently I'm writinig a package that, for a given family of variance
functions depending on a parameter theta, say, computes the extended
quasi likelihood (eql) function for different values of theta.
The computation involves a couple of calls of the 'glm' routine. What
I'm doing now is to call 'lapply' for a list of theta values and a
function, that
2013 Nov 04
1
ggplot2: Add '+' operator for aes (uneval) objects
Dear all,
Is there a reason, why there is no +-operator for aes (i.e. uneval) objects (as there is for themes and gg objects)? I had a couple of cases where such an operator would be useful, for instance to combine the result of aes and aes_string in functions. Any flaws with the following proposition:
`+.uneval` <- function(e1, e2) {
dup <- names(e1) %in% names(e2)
if (any(dup)) {
2005 May 23
2
Documentation of S3 and S4 classes, inheritance
I'd like to have a class A that computes a likelihood, and a subclass B
that computes the same likelihood by sometimes throws in an additional
term (B includes measurement error).
So B's likelihood needs to call A's, and then (sometimes) multiply by an
additional term.
It sounds as if, in the S3 scheme, NextMethod is supposed to do this:
like.A <- function(stuff) compute value
2018 Mar 16
1
Discrepancy: R sum() VS C or Fortran sum
My simple functions were to compare the result with the gfortran
compiler sum() function. I thought that the Fortran sum could not be
less precise than R. I was wrong. I am impressed. The R sum does in fact
match the result if we use the Kahan algorithm.
P.
I am glad to see that R sum() is more accurate than the gfortran
compiler sum.
On 16/03/18 11:37 AM, luke-tierney at uiowa.edu wrote:
2006 Feb 06
3
decomposed.ts class and method
Dear R People:
In the function "decompose", the object has the class of "decomposed.ts".
(from package stats)
I would like to see the class definition and the method for the plotting.
However, when I use
isClass("decomposed.ts")
I get "FALSE".
When I check getMethods("plot")
there is no method for plot on decomposed.ts
Any suggestions,
2006 Apr 13
2
[R] S4 method dispatch matrixOrArray (fwd)
What a delicious example! (I'm taking the liberty of sharing it with
r-devel, since it raises some good issues.)
You have two questions, presumably:
1 - how could the order of the setMethod calls make a difference in the
results?
2 - what's causing the infinite loop & how could it be avoided, reliably?
Second question first. The danger sign is the "vector" method:
2010 Jul 20
1
Telling R CMD check where to find libraries
Hello everybody,
Currently I'm developing a library, which uses some functions from
another package (namely plotrix). Consequently, I listed this dependency
in the DESCRIPTION file. When I try to run "R CMD check mypackage", the
check fails, for the library plotrix cannot be found on the system. As
far as I understood "R CMD check" uses --vanilla implicitly, thus, no