Displaying 20 results from an estimated 1000 matches similar to: "optimization problem in R ... can this be done?"
2010 Sep 10
3
Is there a bisection method in R?
Dear fellow R-users,
Is there a function that does the bisection method? I was unable to find one.
Thanks in advance.
Gregory
[[alternative HTML version deleted]]
2008 Jan 14
3
Listing the data contents of a package
Hi R users,
Simply question: On the command line, how do I list the datasets contained within a package, e.g. MASS?
I scanned the mailing list history but was unable to find the answer.
Thanks in advance.
Gregory
---------------------------------
[[alternative HTML version deleted]]
2008 May 21
2
how to do pairwise sums in a matrix
I am looking for an efficient way to solve the following problem. I have a large matrix of continuous values with a small proportion of missing values. Columns correspond to variables where each variable has two measurements, call them A and B. The matrix is such that the columns are in sequence with respect to the variables. I would like to sum up the two measurements for each variable and each
2009 Oct 06
4
Text editors for Sweave (rnw) files
Hi fellow R-users,
Are there any text editors that recognize sweave (.rnw) files? I am running Windows Vista and in the past I used Tinn-R for R files but it (surprisingly) doesn't recognize rnw files and does not do any syntax highlighting for them.
Thanks in advance,
Greg
__________________________________________________________________
Make your browsing faster, safer, and
2007 Jul 30
3
Constructing correlation matrices
Greetings,
I have a seemingly simple task which I have not been able to solve today and I checked all of the help archives on this and have been unable to find anything useful. I want to construct a symmetric matrix of arbtriray size w/o using loops. The following I thought would do it:
p <- 6
Rmat <- diag(p)
dat.cor <- rnorm(p*(p-1)/2)
Rmat[outer(1:p, 1:p, "<")] <-
2007 Jul 28
8
generating symmetric matrices
Greetings,
I have a seemingly simple task which I have not been able to solve today. I want to construct a symmetric matrix of arbtriray size w/o using loops. The following I thought would do it:
p <- 6
Rmat <- diag(p)
dat.cor <- rnorm(p*(p-1)/2)
Rmat[outer(1:p, 1:p, "<")] <- Rmat[outer(1:p, 1:p, ">")] <- dat.cor
However, the problem is that the matrix
2008 Mar 14
2
using nrow to identify one row
Hi fellow R-users,
I have run into a problem when trying to identify the number of rows in a matrix. Say we have an arbitrary 5 by 5 matrix called temp:
temp <- matrix(norm(25), nrow=5)
The problem is that nrow(temp[1,]) returns NULL. I would like it to return 1 because in my larger program I am indexing the rows of large matrices according to another variable and I need to test when the
2010 Jan 27
3
Function for describing segements in sequential data
Dear R-users,
Say that I have a sequence of zeroes and ones:
x <- c(1,1,1,0,0,0,0,1,1,1,0,0,0,0,1,1,1,0,0,0,0)
The sequences of ones represent segments and I want to report the starting and endpoints of these segments. For example, in 'x', the first segment starts at location 1 and ends at 3, and the second segment starts at location 8 and ends at location 10. Is there an efficient
2005 Jul 28
3
using integrate with optimize nested in the integration
Hi guys
im having a problem getting R to numerically integrate for some function,
say f(bhat)*optimize(G(bhat)), over bhat. Where id like to integrate this over some finite range, so that here as we integrate over bhat optimize would return a different optimum.
For instance consider this simple example for which I cannot get R to return the desired result:
f <- function(bhat) exp(bhat)
g
2007 Nov 21
2
matrix elementwise average with NA's
Hello fellow R users,
I have a matrix computation that I imagine should be relatively easy to do, however I cannot figure out a nice way to do it. I have two matrices, for example
mat1 <- matrix(c(1:5,rep(NA,5), 6:10), nrow=3, byrow=T)
mat2 <- matrix(c(2:6, 6:10, rep(NA,5)), nrow=3, byrow=T)
I'd like to compute the element-wise average for non-NA entries. Of course
(mat1+mat2)/2
2008 Mar 10
1
How can I sample from a two-dimensional grid of points
Hi everyone,
My goal is to sample from a two-dimensional grid. Consider the following example of code:
n.grid <- 500
muA.grid <- seq(-4,4, length=n.grid)
muB.grid <- seq(-4,4, length=n.grid)
mu.p <- matrix(NA, nrow=n.grid, ncol=n.grid)
for(i in 1:n.grid){
for(j in 1:n.grid){
mu.p[i,j] <- dnorm(muA.grid[i], 0, 1)*dnorm(muB.grid[j], 0, 0.5)
}
}
mu.p <-
2006 Jun 24
3
getting the smoother matrix from smooth.spline
Can anyone tell me the trick for obtaining the smoother matrix from smooth.spline when there are non-unique values for x. I have the following code but, of course, it only works when all values of x are unique.
## get the smoother matrix (x having unique values
smooth.matrix = function(x, df){
n = length(x);
A = matrix(0, n, n);
for(i in 1:n){
y = rep(0, n); y[i]=1;
yi =
2008 Jan 07
1
evaluating a vector of characters
Dear R users,
I'd like to evaluate a vector of characters. For example, say I have a data frame called Data including the field names x1, x2, x3, and I'd like to a list out of paste("Data$x", 1:3, sep=""). How can I get list to evaluate paste("Data$x", 1:3, sep="") as an R object rather than a string?
Thanks in advance for you assistance.
Gregory
2010 Jul 02
1
Producing residual plots by time for lme object
Fellow R-users,
I have a longitudinal data set with missing values in it. I would like to produce a residual plot for each time using panel.xyplot function but I get an error message. Here's a simple example,
library(nlme)
set.seed(1544)
longdata <- data.frame(ID=gl(10,1,50), y=rnorm(50), time = as.numeric(gl(5,10,50)), x = rnorm(50))
longdata$y[5] <- NA
longdata$x[35] <- NA
2013 Jan 26
2
confidence / prediction ellipse
Hi,
I'm using the R library(car) to draw confidence/prediction ellipses in a
scatterplot.
>From what i understood the ellipse() function return an ellipse based
parameters: shape, center, radius .
If i read dataEllipse() function i can see how these parameters are
calculated for a confidence ellipse.
ibrary(car)
a=c(12,12,4,5,63,63,23)
b=c(13,15,7,10,73,83,43)
v <-
2010 Oct 11
1
MATLAB vrs. R
I need to find the area under a trapezoid for a research-related project. I was able to find the area under the trapezoid in MATLAB using the code:
function [int] = myquadrature(f,a,b)
% user-defined quadrature function
% integrate data f from x=a to x=b assuming f is equally spaced over the interval
% use type
% determine number of data points
npts = prod(size(f));
nint = npts -1; %number of
2005 Jan 12
4
Finding seasonal peaks in a time series....
I have a seasonal time series. I want to calculate the annual mean
value of the time series at its peak
(say the mean of the three values before the peak, the peak, and the
three values after the peak).
The peak of the time series might change cycle slightly from year to year.
# E.g.,
nPts <- 254
foo <- sin((2 * pi * 1/24) * 1:nPts)
foo <- foo + rnorm(nPts, 0, 0.05)
bar <- ts(foo,
2006 Jan 08
1
confint/nls
I have found some "issues" (bugs?) with nls confidence intervals ...
some with the relatively new "port" algorithm, others more general
(but possibly in the "well, don't do that" category). I have
corresponded some with Prof. Ripley about them, but I thought I
would just report how far I've gotten in case anyone else has
thoughts. (I'm finding the code
2001 Feb 28
2
Automating the job?
Hi!
I just started to use R recently, and would like to ask a help about
automating the job.
I need to use "kmeans" function with my own 300 data files, and wonder if
it's possible to do it automatically. For example,
> library (mva)
> mydata <- read.table ("data1")
> cl <- kmeans(mydata, 5, 20)
and I just need to save "cl" info (i.e. the center
2006 Oct 05
1
unexpected behavior of boxplot(x, notch=TRUE, log="y")
A function I've been using for a while returned a surprising [to me,
given the data] error recently:
Error in plot.window(xlim, ylim, log, asp, ...) :
Logarithmic axis must have positive limits
After some digging I realized what was going on:
x <- c(10460.97, 10808.67, 29499.98, 1, 35818.62, 48535.59, 1, 1,
42512.1, 1627.39, 1, 7571.06, 21479.69, 25, 1, 16143.85, 12736.96,