Displaying 20 results from an estimated 6000 matches similar to: "lm() of one matrix against another"
2008 Jul 03
1
ggplot2 legend for vertical lines
Dear all,
The following example code produces a graph with ggplot2, to which I
add several vertical lines of arbitrary colors. I am not satisfied
with the legend: it automatically adds some vertical lines which I'd
rather not see (they confuse the reader rather than add information
in this case).
> library(ggplot2)
> dfr <- data.frame(values = sin(1:50/10),
> fact =
2008 Jun 18
2
highest eigenvalues of a matrix
DeaR list,
I happily use eigen() to compute the eigenvalues and eigenvectors of
a fairly large matrix (200x200, say), but it seems over-killed as its
rank is limited to typically 2 or 3. I sort of remember being taught
that numerical techniques can find iteratively decreasing eigenvalues
and corresponding orthogonal eigenvectors, which would provide a nice
alternative (once I have the
2008 Feb 14
1
write output in a custom format
Hi,
I need to create a text file in the following format,
> 1 100.0 0
> 0 0
> 1 1
> 0 0
> 1 1
> #
> 1 100.0 0
> 0 0
> 0 1
> 1 0
> 1 1
...
where # is part of the format and not a R comment.
Each block (delimited by #) consists of a first line with three
values, call it dose, and a list of (x,y) coordinates which are a
matrix or data.frame,
>
2007 Dec 28
1
unit attribute to list elements
Hi,
I've started my own (first) package, part of which consists in
listing common physical constants (Planck's constant, the speed of
light in vacuum, etc). I'm wondering what would be a good way of
dealing with pairs of value/unit.
> constants <- list( cel = 2.99792458e8 , #m/s
> Z0 = 376.730313461, #ohm
> eps0 = 8.854187817e-12,#F/m
> mu0 = 4*pi*1e-7,#N/A^2
2008 Apr 03
1
data.frame or list
Dear R list,
I'm having difficulties in choosing between a list or a data.frame,
or an array for the storage and manipulation of my data (example
follows). I've been using the three for different purposes but I
would rather like to know which is more adapted to what task.
Here is the data I'm currently working on: 200 observations, each
observation being a vector of length
2008 Feb 03
1
distances between points in R^3
Dear R helpers,
I'm trying to write a numerical scheme for a boundary integral method
to solve an electromagnetic problem. This requires the computation of
the distance between points at the surface of an object (a sphere, in
my example). Here is my code,
> require(rgl)
> r<-1
> size<-10
> theta<-seq(0,2*pi,length=size*2)
> phi<-seq(0,pi,length=size)
> pc
2008 Jun 25
1
expression, strsplit, ...
DeaR list,
I'm a bit lost in the behavior of substitute and co.
I often use fairly long axis labels in my graphs (long to write, that
is). Typically, they would contain some greek letters and units with
exponents, as in:
> xlab=expression(paste("text ", alpha, " / ", V,".", m^{-3}, ".",
> kg^{-2}, ".", l^{4}))
To make this a
2008 Feb 18
2
question on function arguments
Hi,
I have two small issues with my R code, no big deal but curiosity
really. Here is a sample code,
>
> x <- rnorm(1:10)
>
> foo <- function(a = 1, b = list(x = c(1:10), y = c(1:10))){
>
> for (ii in seq(along=b$y)){
>
> print(x[ii] + b$x[ii])
> }
>
>
> }
>
> foo() # default OK
>
> foo(b=list(x=1, y=c(1:10))) # only the first
2008 May 23
2
[slightly off topic] Sweave with markdown
DeaR list,
Has anyone tried to mix the Sweave paradigm with the Markdown[*] (and
co.) syntax? Would this be hard to implement? My tiny understanding
of Sweave is that one can define new drivers for the text part, while
some functions that deal with the R code would not require any
modification. Here's the reason I'm interested in Mardown for a driver.
I've been orbiting
2008 Mar 09
2
Bessel functions of complex argument
Dear R users,
I'm porting a piece of Matlab code to R, but I'm now stuck with the
following: I need an equivalent of besselJ(x, nu) that can handle a
complex argument x. I couldn't find any R implementation. I did find
a possible fortran solution in SLATEC (< http://www.netlib.org/slatec/
> , CBESJ-C), however I've never tried to use external C or Fortran
code
2008 Mar 09
2
Bessel functions of complex argument
Dear R users,
I'm porting a piece of Matlab code to R, but I'm now stuck with the
following: I need an equivalent of besselJ(x, nu) that can handle a
complex argument x. I couldn't find any R implementation. I did find
a possible fortran solution in SLATEC (< http://www.netlib.org/slatec/
> , CBESJ-C), however I've never tried to use external C or Fortran
code
2008 Jun 27
1
include S4 class and methods in a package
DeaR list,
Pardon the stupidity of this question but I've been trying this for a
while now without success.
I've followed the example given in the green book "programming with
data", and I now have a working example of a S4 class with a few
methods (plot, summary, as.data.frame). It's all very nice in one
file, but I cannot find the way to put this information in a
2008 Apr 26
6
quasi-random sequences
Dear list useRs,
I have to generate a random set of coordinates (x,y) in [-1 ; 1]^2
for say, N points. At each of these points is drawn a circle (later
on, an ellipse) of random size, as in:
> N <- 100
>
> positions <- matrix(rnorm(2 * N, mean = 0 , sd= 0.5), nrow=N)
> sizes<-rnorm(N, mean = 0 , sd= 1)
> plot(positions,type="p",cex=sizes)
My problem is to
2008 Jan 01
4
access data inside package
Dear all,
Happy new year!
I posted a very similar question a few days ago, but probably too
cluttered. Here is a tidy, minimal version:
I want to make a package, with a data.frame d and a function f given
below. Now, the function f needs to use the data.frame d. I could
(and that's what I've done temporarily) make a local duplicate of
this data.frame in the function definition,
2008 May 04
1
adaptive optimization of mesh size
DeaR list,
I'm running an external program that computes some electromagnetic
response of a scattering body. The numerical scheme is based on a
discretization with a characteristic mesh size "y". The smaller y is,
the better the result (but obviously the computation will take longer).
A convergence study showed the error between the computed values and
the exact solution
2007 Dec 30
1
adding a function after package.skeleton()
Dear R helpers,
I've successfully created a package 'constants' using package.skeleton
() with one dataframe and a few functions. However, now that I want
to add some functions and data to the package, I run into a problem.
I ran prompt(...) and moved + edited the resulting .Rd files as
appropriate (I believe). The log file from RCMD check constants does
indicate a few
2008 Aug 09
2
levels values of cut()
Dear list,
I have the following example, from which I am hoping to retrieve
numeric values of the factor levels (that is, without the brackets):
>
> x <- seq(1, 15, length=100)
> y <- sin(x)
>
> my.cuts <- cut(which(abs(y) < 1e-1), 3)
> levels(my.cuts)
hist() does not suit me for this, as it does not necessarily respect
the number of breaks.
getAnywhere
2009 Mar 25
2
"[.data.frame" and lapply
Dear all,
Trying to extract a few rows for each element of a list of
data.frames, I'm puzzled by the following behaviour,
> d <- lapply(1:4, function(i) data.frame(x=rnorm(5), y=rnorm(5)))
> str(d)
>
> lapply(d, "[", i= c(1)) # fine, this extracts the first columns
> lapply(d, "[", j= c(1, 3)) # doesn't do nothing ?!
>
> library(plyr)
2009 Mar 25
2
"[.data.frame" and lapply
Dear all,
Trying to extract a few rows for each element of a list of
data.frames, I'm puzzled by the following behaviour,
> d <- lapply(1:4, function(i) data.frame(x=rnorm(5), y=rnorm(5)))
> str(d)
>
> lapply(d, "[", i= c(1)) # fine, this extracts the first columns
> lapply(d, "[", j= c(1, 3)) # doesn't do nothing ?!
>
> library(plyr)
2008 Dec 02
1
legend idea for latticeExtra
Dear list,
I've written a small utility function to add arbitrary legend(s) to a
lattice graph (or a combination of them), much like the legend
function of base graphics. I though perhaps it could be useful to
someone else, or improved by suggestions. I understand this goes
against the lattice paradigm somewhat, in that you short-cut the link
between group variables and the