Displaying 20 results from an estimated 9000 matches similar to: "setMethod "[" - extract by names within Slot"
2011 Oct 01
1
class definition
Hi everybody!
I have a matrix of class "myClass", for example:
myMat <- matrix(rnorm(30), nrow = 6)
attr(myMat, "class") <- "myClass"
class(myMat)
When I extract part of ''myMat'', the corresponding class ''myClass'' unfortunately disappear:
myMat.p <- myMat[,1:2]
class(myMat.p)
Please for any advice / suggestions, how
2008 Mar 20
1
setMethod for "["
Hi R-Help,
Please consider the following simple case: I have a class like
setClass("myClass",
representation(x="matrix", y="character"))
and I would like to use the method *"["* for a *myClass* objects (but
changing the default *drop* argument from TRUE to FALSE):
setMethod("[","myClass",
function(x,i,j,...,drop=FALSE)
2003 Dec 02
1
setMethod("min", "myclass", ...)
Hello,
I have defined a new class
> setClass("myclass", representation(min = "numeric", max = "numeric"))
and want to write accessor functions, so that for
> foo = new("myclass", min = 0, max = 1)
> min(foo) # prints 0
> max(foo) # prints 1
At first i created a generic function for "min"
> setGeneric("min",
2002 Jul 19
1
Rprof and setMethod conflict?
I noticed this oddity about R profiling and setMethod.
First, I "test out" Rprof.
> require(methods)
Loading required package: methods
[1] TRUE
>
> Rprof("test.out")
> data.frame("a")
X.a.
1 a
> Rprof(NULL)
So far, so good. Next, I define myClass.
> setClass("myClass", representation(mySlot = "numeric"))
[1]
2002 Aug 06
2
[ and setMethod conflict?
I noticed this oddity about [ and setMethod.
First, I define testFunc, which sorts a data frame by the first column and
returns the entries that aren't NAs, and testIt, which runs testFunc
repeatedly on a random large data frame, each time saving the return into a
dummy placeholder (for demonstration's sake).
> require(methods)
Loading required package: methods
[1] TRUE
> testFunc
2002 Aug 06
2
[ and setMethod conflict?
I noticed this oddity about [ and setMethod.
First, I define testFunc, which sorts a data frame by the first column and
returns the entries that aren't NAs, and testIt, which runs testFunc
repeatedly on a random large data frame, each time saving the return into a
dummy placeholder (for demonstration's sake).
> require(methods)
Loading required package: methods
[1] TRUE
> testFunc
2007 Mar 30
2
Replacing slot of S4 class in method of S4 class?
Dear all,
Assume that I have an S4 class "MyClass" with a slot "myname", which
is initialized to: myname="" in method("initialize"):
myclass <- new("MyClass", myname="")
Assume that class "MyClass" has a method "mymethod":
"mymethod.MyClass" <-
function(object, myname=character(0), ...) {
2012 Dec 15
3
kruskalmc, significant differences while median values are the same
Dear list!
I work with multiple Kruskal-Wallis test (kruskalmc, package pgirmess), which evaluates differences in medians among groups (5 groups). A result of a test is significant differences among some groups, while median values are the same for 4 groups (using tapply). Why?
p.s.: number of samples in groups vary from 50 to 4900.
Thanks to all, OV
.
2012 Jun 26
5
chisq.test
Dear list!
I would like to calculate "chisq.test" on simple data set with 70 observations, but the output is ''Warning message:''
Warning message:
In chisq.test(tabele) : Chi-squared approximation may be incorrect
Here is an example:
tabele <- matrix(c(11, 3, 3, 18, 3, 6, 5, 21), ncol = 4, byrow = TRUE)
dimnames(tabela) <- list(
2012 Nov 17
3
transform input argument (matrix) of function
Dear list!
I would like to write a function to transform matrix, which is input argument of a written function. It is easy with new matrix (see below), but my idea is to transform input argument (matrix) of function without any additional matrixes. Here is an example:
fun1 <- function(xy) {
xy <- cbind(xy[,1], xy[,2], xy[,1] + xy[,2])
return(xy)
}
df1 <- matrix(c(1,2,3,1,2,3), ncol =
2014 Jan 07
1
Why do methods of "initialize" have no "srcref" attribute as other S4 mehtods?
For documentation we use a system that generates Rd files from special
comments in the code. (inlinedocs).
It is crucial to be able to get the defining source code for objects like
methods to extract the comments from it.
Here is an R session that shows how this works for several kinds of methods
and (at the end of the session) how if fails for methods of "initialize"
>
2002 Aug 26
1
Rprof and setMethod conflict (PR#1949)
Full_Name: Kevin C. Bartz
Version: 1.5.1
OS: Solaris 2.6
Submission from: (NULL) (192.223.226.5)
A while ago, I noticed this oddity about R profiling and setMethod.
First, I "test out" Rprof.
> require(methods)
Loading required package: methods
[1] TRUE
>
> Rprof("test.out")
> data.frame("a")
X.a.
1 a
> Rprof(NULL)
So far, so good. Next, I
2011 Jun 29
1
Ref Classes: bug with using '.self' within initialize methods?
Dear list,
I'm wondering if the following error I'm getting is a small bug in the
Reference Class paradigm or if it makes perfect sense.
When you write an explicit initialize method for a Ref Class, can you
then make use of '.self' WITHIN this initialize method just as you would
once an object of the class has actually been initialized?
Because it seems to me that you can not.
2009 Jan 02
1
"registering" a generic method for a class
Sorry in advance if this is too simple a question, but I'm stuck with
some odd behavior and I can't find the text to rid myself of this
(admittedly somewhat trivial) problem. Note that I've done generic
programming with S3 "objects" in the past, but I've never really
dabbled in creating S4 objects until now.
So, I've created a new S4 class, call it
2005 Dec 07
1
Dots argument in apply method
Hello everyone,
I'm working on a package using S4 classes and methods and I ran into the
following "problem" when I tried to create an "apply" method for objects
of one of my new classes. I've found a way around the problem but I
wonder if I did not paint myself into the corner. I'd like your opinion
about that.
So I have an object "myObj" of class
2011 Jun 06
1
Seeking help to define method for show() for an S4 object
Dear all, I have created a new S4 class with name "MyClass". Please see
below for it's definition. Now I want to create a
method for the show() function for this class. In defining this method, what
I want is, once user would like see an object of this class
some values will be displayed. Then R will ask for **press Enter**. Once
user presses enter then, remaining values will be
2012 Nov 07
1
row index for max values of row groups
Dear list members!
I am looking for ''nice solution'' for (maybe) simple problem. I need a code (small program) to calculate row index for max value (example below: df1$values) by groups (example below: df1$groups).
df1 <- data.frame(
groups = c(1,1,1,1,1,2,2,2,3,3,3,3),
values = c(1,1,1,2,1,1,2,3,2,1,4,3)
)
df1
expected results
> 4 8 11 # row index of max values by group
2017 Sep 22
2
S4 method implementation for S3 class
Hi all,
I'm trying to implement the matrix multiplication operator, which is
S4 generic, for an old-style S3 class. The following works as
expected:
x <- 1:10
class(x) <- "myClass"
setOldClass("myClass")
setGeneric("myMethod", function(x, y) standardGeneric("myMethod"))
setMethod("myMethod", c("myClass", "myClass"),
2012 Apr 07
1
rgeos - gBuffer, width by z-value
Dear list!
I have problem with buffer size (width) in package rgeos. I would like to expand given geometry (points) to specified width based on the z value from attribute table. Here is example:
point <- data.frame(x=c(10,20), y=c(10, 10), z = c(2,7))
point_shp <- SpatialPointsDataFrame(point[,1:2],point)
plot(point_shp, xlim = c(0,30), ylim = c(0,20))
plot(gBuffer(point_shp, width = 5,
2004 Nov 11
1
"<<-" assignment no long work in class methods
Hi-
I used to use "<<-" to do assignment inside a class method, and
just found that now it is broken in R 2.0. For example, the
following code
-----------------------------------------------------------------------
setClass( "myclass", representation(x="numeric") )
setGeneric("incrXByOne", function(obj) standardGeneric("incrXByOne"))