Displaying 20 results from an estimated 5000 matches similar to: "model.matrix() (PR#285)"
2005 Dec 21
3
NextMethod causes R 2.2.0 to crash (PR#8416)
I found writing the following default method the for the generic
function "julian" causes R to crash.
julian.default <- function(x, ...) {
x <- as.Date(x)
NextMethod("julian", x, ...)
}
Here is a test example
> m <- as.Date("1972-09-27") + 0:10
> m
[1] "1972-09-27" "1972-09-28" "1972-09-29"
2008 Feb 13
2
apply on large arrays
I have a big contingency table, approximately of size 60*2*500*500,
and I need to count the number of cells containing a count of 1 for each
of the factors values defining the first dimension.
Here is my attempt:
tab1<-with(pisa1,table(CNT,GENDER,ISCOF,ISCOM))
tab2<-apply(tab1,1:4,function(x)ifelse(sum(x)==1,1,0))
tab3<-apply(tab2,1,sum)
Computing tab2 is very slow.
Is there a faster
1999 Feb 17
1
dim enquiry
This is a minor question, but is there any difference between the two
objects
fred <- structure(1:10, dim = c(2,5))
and
fred <- structure(1:10, .Dim = c(2,5))
Should I be using one rather than the other? Thanks, Jonathan.
Jonathan Rougier Science Laboratories
Department of Mathematical Sciences South Road
University of Durham Durham DH1 3LE
1999 Jan 14
1
libraries
Am I right in thinking that there a discrepancy between the ?library
documentation and the library() function? If I have a library called
"patches", then according to the documentation (0.62.4) patches/R should
contain source files like fred.R and george.R, but in practice the library
only loads if both fred.R and george.R are given in a file called patches
in the R subdirectory of
1999 Feb 10
1
Function parsing (PR#118)
Is anyone else concerned with the way in which the R function parser
relocates comments that occur after condional expressions in functions to
before, i.e.
fred <- function(x) {
# wonder what x is like
if (x>0) stop("Sorry non-positive x only")
# that showed x big-time!
x
}
but then fred is parsed and stored as
"fred" <-
function (x)
{
# wonder what x is
1999 Oct 08
1
dimnames and subscripting (PR#293)
I am not sure that this is a bug, but it was unexpected -- of course my
expectations are fallible, eg column ordering in model.matrix()! When an
array is subscripted the names of the dimnames list are lost (v 64.1).
fred <- array(1:12, 2:4, list(A = letters[1:2], B = letters[3:5], C =
letters[6:9]))
dimnames(fred)
dimnames(fred[1, , ])
dimnames(fred[1, , , drop=FALSE])
In the first
1999 Oct 26
1
dodgy list operation (PR#298)
I can generate a segmentation fault as follows, where I would expect a
syntax error:
fred <- as.list(1:10)
lapply(fred, "[[")
platform sparc-sun-solaris2.5.1
arch sparc
os solaris2.5.1
system sparc, solaris2.5.1
status
status.rev 0
major 0
minor 64.1
1999 Jan 08
0
Function suggestion
I hope this is the right forum (it'll be second time lucky if it is!). I
note in the current distribution that functions passed as arguments (eg to
outer, sweep and the applys) are not handled consistently. As I often
pass functions myself, I find the following simple function useful ...
match.fun <- function (FUN, descend = F)
{
if (is.character(FUN))
get(FUN,
1999 Mar 22
0
Extension to outer()
This message is in MIME format. The first part should be readable text,
while the remaining parts are likely unreadable without MIME-aware tools.
Send mail to mime@docserver.cac.washington.edu for more info.
---559023410-1804928587-922106403=:691
Content-Type: TEXT/PLAIN; charset=US-ASCII
A couple of weeks ago I asked if anyone had generalised outer to include
bound extents -- effectively
1999 Jun 17
0
save.image()
Would it be reasonable to suggest adding an `all' flag to save.image(),
i.e.
"save.image" <-
function (f = ".RData", all.names = F)
eval(substitute(save(list = ls(all.names = all.names), file = f)),
.GlobalEnv)
I only ask because I keep losing my .First() function. I would like to
start R in a particular directory and have it configure according to the
First()
1999 Dec 22
0
Apply dimnames (PR#385)
This message is in MIME format. The first part should be readable text,
while the remaining parts are likely unreadable without MIME-aware tools.
Send mail to mime@docserver.cac.washington.edu for more info.
---559023410-1251336619-945861747=:5357
Content-Type: TEXT/PLAIN; charset=US-ASCII
While fiddling with apply I noticed that there appears to be an error in
the dimnames, which actually
2000 Jan 04
2
set functions
I wonder if we might also include an "equiv" function along with the other
set functions (ie "union", "intersect", etc), perhaps along the lines of
"equiv" <- function(x, y) all(c(match(x, y, 0)>0, match(y, x, 0)>0))
(which I think might be the quickest implementation). I use this type of
function quite frequently: is there some reason why it is
2000 Jan 04
2
set functions
I wonder if we might also include an "equiv" function along with the other
set functions (ie "union", "intersect", etc), perhaps along the lines of
"equiv" <- function(x, y) all(c(match(x, y, 0)>0, match(y, x, 0)>0))
(which I think might be the quickest implementation). I use this type of
function quite frequently: is there some reason why it is
1999 Apr 30
1
legend()
In legend() is it possibly to mix lines and boxes? I would like to do
something like
legend(locator(1), legend = c("al", "ben", "chris", "dave"), lty =
c(1, 2, 3, NA), fill = c(NA, NA, NA, "gray"))
to indicate that "al", "ben" and "chris" have lines, and "dave" has a gray
shading.
Many thanks,
2005 Apr 30
3
as.numeric method for objects of class "difftime"
I have just become painfully aware that objects of class "difftime",
generated by the difference of two POSIXct objects, carry a "units"
attribute, which flashes by when the object is printed, for example.
The pain was occasioned when I tried to turn these objects into numberic
objects for use elsewhere as a covariate.
as.numeric(difftime object)
simply turns off the units
2008 Feb 01
6
Accessing the elements of a list
Hi R,
I wanted to know how do we access the elements of a list. In particular,
v=list(c(1,2,3,4,5),c(1,2,33,4,5),c(1,2,333,4,5),c(1,2,3333,4,5))
I want to access all the thirds items of the elements of the list. i.e.,
I want to access the elements, 3,33,333,3333. This can be done through
sapply as:
sapply(v,function(x) x[3])
But I need to access this without using
1999 Aug 25
2
Error in ?text (PR#256)
Just a minor point, but the adj argument in ?text is described wrongly
(0.64.1). Perhaps the following might be added to the details.
Values of 0, 0.5, and 1 specify left/top, middle and right/bottom,
respectively. The default is for centred text, ie \code{adj = c(0.5,
0.5)}.
Cheers, Jonathan.
Jonathan Rougier Science Laboratories
Department of
1999 Sep 27
2
chol() dimnames
Hi Everyone,
Just a minor point, but could chol() be changed to include the dimnames of
the original matrix? This will ensure that x and t(R) %*% R have the same
dimnames, where R <- chol(x). So we just need to insert
if (!is.null(dx <- dimnames(x)))
dimnames(z$v) <- dx
ahead of the return. Cheers, Jonathan.
Jonathan Rougier Science Laboratories
2006 Dec 22
5
substitute creates an object which prints incorrectly (PR#9427)
The function "substitute" seems to fail to make a genuine
substitution, although the printed verision seems fine. Here is an
example.
> m <- substitute(Y <- function(x) FUN(x+1),
+ list(Y = as.name("y"), FUN = as.name("sin")))
> m
y <- function(x) sin(x + 1)
> eval(m)
> y
function(x) FUN(x+1)
However the story doesn't end there. The
1999 Aug 18
2
diag()
I would like to suggest a slight modification to diag(). In the case
where x is a matrix with both row names and column names the same, it
would be reasonable if the resulting vector also had those names. I often
use diag() on variance matrices, where this modification is helpful.
The modification requires replacing
if (is.matrix(x) && nargs() == 1)
return(c(x)[1 +