Re: [Rd] By default, `names<-` alters S4 objects

2011-05-17 Thread Hervé Pagès
On 11-05-17 01:15 PM, John Chambers wrote: On 5/17/11 9:53 AM, Hervé Pagès wrote: On 11-05-17 09:04 AM, John Chambers wrote: One point that may have been unclear, though it's surprising if so. The discussion was about assigning names to S4 objects from classes that do NOT have a formal "names

Re: [Rd] By default, `names<-` alters S4 objects

2011-05-17 Thread John Chambers
On 5/17/11 9:53 AM, Hervé Pagès wrote: On 11-05-17 09:04 AM, John Chambers wrote: One point that may have been unclear, though it's surprising if so. The discussion was about assigning names to S4 objects from classes that do NOT have a formal "names" slot. Of course, having a "names" slot is

Re: [Rd] By default, `names<-` alters S4 objects

2011-05-17 Thread Hervé Pagès
On 11-05-17 09:04 AM, John Chambers wrote: One point that may have been unclear, though it's surprising if so. The discussion was about assigning names to S4 objects from classes that do NOT have a formal "names" slot. Of course, having a "names" slot is not illegal, it's what one should do to de

Re: [Rd] By default, `names<-` alters S4 objects

2011-05-17 Thread John Chambers
One point that may have been unclear, though it's surprising if so. The discussion was about assigning names to S4 objects from classes that do NOT have a formal "names" slot. Of course, having a "names" slot is not illegal, it's what one should do to deal with names in S4. Look at class "na

Re: [Rd] By default, `names<-` alters S4 objects

2011-05-16 Thread Hervé Pagès
On 11-05-16 04:13 PM, Hervé Pagès wrote: On 11-05-16 01:53 PM, John Chambers wrote: On 5/16/11 10:09 AM, Hervé Pagès wrote: On 11-05-16 09:36 AM, John Chambers wrote: You set up a names slot in a non-vector. Maybe that should be allowed, maybe not. But in any case I would not expect the name

Re: [Rd] By default, `names<-` alters S4 objects

2011-05-16 Thread Hervé Pagès
On 11-05-16 01:53 PM, John Chambers wrote: On 5/16/11 10:09 AM, Hervé Pagès wrote: On 11-05-16 09:36 AM, John Chambers wrote: You set up a names slot in a non-vector. Maybe that should be allowed, maybe not. But in any case I would not expect the names() primitive to find it, because your obj

Re: [Rd] By default, `names<-` alters S4 objects

2011-05-16 Thread John Chambers
On 5/16/11 10:09 AM, Hervé Pagès wrote: On 11-05-16 09:36 AM, John Chambers wrote: You set up a names slot in a non-vector. Maybe that should be allowed, maybe not. But in any case I would not expect the names() primitive to find it, because your object has a non-vector type ("S4"). But the

Re: [Rd] By default, `names<-` alters S4 objects

2011-05-16 Thread Hervé Pagès
On 11-05-16 09:36 AM, John Chambers wrote: You set up a names slot in a non-vector. Maybe that should be allowed, maybe not. But in any case I would not expect the names() primitive to find it, because your object has a non-vector type ("S4"). But the names<-() primitive *does* find it. So eith

Re: [Rd] By default, `names<-` alters S4 objects

2011-05-16 Thread John Chambers
You set up a names slot in a non-vector. Maybe that should be allowed, maybe not. But in any case I would not expect the names() primitive to find it, because your object has a non-vector type ("S4"). You could do a@names if you thought that made sense: > setClass("A", representation(names

Re: [Rd] By default, `names<-` alters S4 objects

2011-05-15 Thread Hervé Pagès
On 11-05-15 11:33 AM, John Chambers wrote: This is basically a case of a user error that is not being caught: Sure! https://stat.ethz.ch/pipermail/r-devel/2009-March/052386.html On 5/14/11 3:47 PM, Hervé Pagès wrote: Hi, I was stumped by this. The two S4 objects below looked exactly the

Re: [Rd] By default, `names<-` alters S4 objects

2011-05-15 Thread John Chambers
This is basically a case of a user error that is not being caught: On 5/14/11 3:47 PM, Hervé Pagès wrote: Hi, I was stumped by this. The two S4 objects below looked exactly the same: > a1 An object of class "A" Slot "aa": integer(0) > a2 An object of class "A" Slot "aa": integer(0) > str(a

[Rd] By default, `names<-` alters S4 objects

2011-05-14 Thread Hervé Pagès
Hi, I was stumped by this. The two S4 objects below looked exactly the same: > a1 An object of class "A" Slot "aa": integer(0) > a2 An object of class "A" Slot "aa": integer(0) > str(a1) Formal class 'A' [package ".GlobalEnv"] with 1 slots ..@ aa: int(0) > str(a2) Fo

[Rd] 'by' with one-dimensional array

2008-11-16 Thread Patrick Burns
I've played a bit with the problem that Jeff Laake reported on R-help: # create data: jl <- data.frame(x=rep(1, 3), y=tapply(1:9, rep(c('A','B','C'), each=3), sum)) jl2 <- jl jl2$y <- as.numeric(jl2$y) # do the test: > tapply(jl$y, jl$x, length) 1 3 > tapply(jl2$y, jl2$x, length) 1 3 > by(jl

Re: [Rd] by

2008-04-03 Thread Tobias Verbeke
>- Oorspronkelijk bericht - >Van: Peter Dalgaard [mailto:[EMAIL PROTECTED] >Verzonden: donderdag, april 3, 2008 02:16 PM >Aan: 'Tobias Verbeke' >CC: r-devel@r-project.org >Onderwerp: Re: [Rd] by "infelicity" > >Tobias Verbeke wrote: >> De

Re: [Rd] by "infelicity"

2008-04-03 Thread Peter Dalgaard
Tobias Verbeke wrote: > Dear list, > > Please find below an example of odd > behaviour of the by function. > > It occurs both under GNU/Linux R 2.6.2 > and Windows R 2.7.0alpha. Respective > sessionInfo()'s are given below. > > I hope I do not overlook anything. > > testFactor <- factor(sample(LET

[Rd] by "infelicity"

2008-04-03 Thread Tobias Verbeke
Dear list, Please find below an example of odd behaviour of the by function. It occurs both under GNU/Linux R 2.6.2 and Windows R 2.7.0alpha. Respective sessionInfo()'s are given below. I hope I do not overlook anything. testFactor <- factor(sample(LETTERS[1:6], size = 42, replace = TRUE)) tes

[Rd] "by" speed improvement (PR#11064)

2008-04-01 Thread simon . debernard
Full_Name: Simon de Bernard Version: 2.7.0 (44733) OS: MacOS Submission from: (NULL) (140.77.34.213) "by" usually takes forever even on a "not so large" data structure. If one can do with a matrix instead of a data.frame, defining by.matrix as by.data.frame modified to convert data back to a dat

Re: [Rd] by() processing on a dataframe

2005-09-30 Thread Gabor Grothendieck
And here is one more approach using the reshape package: library(reshape) dataset.d <- melt(dataset, id = 1:2) cast(dataset.d, gp1 + gp2 ~ variable, mean) On 9/30/05, Gabor Grothendieck <[EMAIL PROTECTED]> wrote: > Check out summaryBy in the doBy package at: > > http://genetics.agrsci.dk/~sor

Re: [Rd] by() processing on a dataframe

2005-09-30 Thread Duncan Murdoch
On 9/30/2005 1:41 PM, hadley wickham wrote: > I'm not entirely sure what you want, but maybe this does the trick? > > data.frame.by <- function(data, variables, fun, ...) { > if (length(variables) == 0 ) { > df <- data.frame(results = 0) > df$results <- list(fun(d

Re: [Rd] by() processing on a dataframe

2005-09-30 Thread Duncan Murdoch
On 9/30/2005 1:41 PM, Peter Dalgaard wrote: > Duncan Murdoch <[EMAIL PROTECTED]> writes: > >> I want to calculate a statistic on a number of subgroups of a dataframe, >> then put the results into a dataframe. (What SAS PROC MEANS does, I >> think, though it's been years since I used it.) >> >>

Re: [Rd] by() processing on a dataframe

2005-09-30 Thread Marc Schwartz (via MN)
On Fri, 2005-09-30 at 13:22 -0400, Duncan Murdoch wrote: > I want to calculate a statistic on a number of subgroups of a dataframe, > then put the results into a dataframe. (What SAS PROC MEANS does, I > think, though it's been years since I used it.) > > This is possible using by(), but it see

Re: [Rd] by() processing on a dataframe

2005-09-30 Thread Gabor Grothendieck
Check out summaryBy in the doBy package at: http://genetics.agrsci.dk/~sorenh/misc e.g. summaryBy(value ~ gp1 + gp2, data = dataset) On 9/30/05, Duncan Murdoch <[EMAIL PROTECTED]> wrote: > I want to calculate a statistic on a number of subgroups of a dataframe, > then put the results in

Re: [Rd] by() processing on a dataframe

2005-09-30 Thread Peter Dalgaard
Duncan Murdoch <[EMAIL PROTECTED]> writes: > I want to calculate a statistic on a number of subgroups of a dataframe, > then put the results into a dataframe. (What SAS PROC MEANS does, I > think, though it's been years since I used it.) > > This is possible using by(), but it seems cumbersome

Re: [Rd] by() processing on a dataframe

2005-09-30 Thread hadley wickham
I'm not entirely sure what you want, but maybe this does the trick? data.frame.by <- function(data, variables, fun, ...) { if (length(variables) == 0 ) { df <- data.frame(results = 0) df$results <- list(fun(data$value, ...)) return(df)

[Rd] by() processing on a dataframe

2005-09-30 Thread Duncan Murdoch
I want to calculate a statistic on a number of subgroups of a dataframe, then put the results into a dataframe. (What SAS PROC MEANS does, I think, though it's been years since I used it.) This is possible using by(), but it seems cumbersome and fragile. Is there a more straightforward way th

[Rd] by should use match.fun (PR#7936)

2005-06-14 Thread ggrothendieck
Full_Name: G. Grothendieck Version: R version 2.1.0, 2005-06-10 OS: Windows XP Submission from: (NULL) (216.59.226.184) This is an inconsistency between by and similar functions. The 'by' function should have an initial line of: FUN <- match.fun(FUN) All other similar functions including app

Re: [Rd] by should use match.fun

2005-06-12 Thread Peter Dalgaard
Gabor Grothendieck <[EMAIL PROTECTED]> writes: > On 6/12/05, Simon Urbanek <[EMAIL PROTECTED]> wrote: > > Umm.. why don't you just use > > > > by(iris, row.names(iris), `(`) > > > > In general I consider passing functions as text unnecessary - the > > only use I could think of is constructi

Re: [Rd] by should use match.fun

2005-06-12 Thread Gabor Grothendieck
On 6/12/05, Simon Urbanek <[EMAIL PROTECTED]> wrote: > On Jun 12, 2005, at 3:21 PM, Gabor Grothendieck wrote: > > > On 6/12/05, Liaw, Andy <[EMAIL PROTECTED]> wrote: > > > >> I don't get the point. ?by says: > >> > > > > The point is that all other functions of this sort including apply, > > sapp

Re: [Rd] by should use match.fun

2005-06-12 Thread Simon Urbanek
On Jun 12, 2005, at 3:21 PM, Gabor Grothendieck wrote: > On 6/12/05, Liaw, Andy <[EMAIL PROTECTED]> wrote: > >> I don't get the point. ?by says: >> > > The point is that all other functions of this sort including apply, > sapply, > tapply, lapply work like that so 'by' ought to as well. > > Her

Re: [Rd] by should use match.fun

2005-06-12 Thread Gabor Grothendieck
On 6/12/05, Liaw, Andy <[EMAIL PROTECTED]> wrote: > I don't get the point. ?by says: The point is that all other functions of this sort including apply, sapply, tapply, lapply work like that so 'by' ought to as well. Here is the example (changed to use iris) where I noticed it. Suppose we wa

Re: [Rd] by should use match.fun

2005-06-12 Thread Liaw, Andy
I don't get the point. ?by says: FUN a function to be applied to data frame subsets of data. It doesn't say FUN can be a character, and by(iris, iris$Species, summary) works as expected. Andy > From: Gabor Grothendieck > > I noticed that, unlike similar functions, 'by' does not use > match.

[Rd] by should use match.fun

2005-06-12 Thread Gabor Grothendieck
I noticed that, unlike similar functions, 'by' does not use match.fun, e.g. > by(iris, iris$Species, "summary") Error in FUN(X[[1]], ...) : couldn't find function "FUN" The 'by' code should have an initial line of: FUN <- match.fun(FUN) __ R-devel@r-p