Displaying 20 results from an estimated 10000 matches similar to: "finding a faster way to do an iterative computation"
2007 Aug 28
1
alternate methods to perform a calculation
Consider a data frame (x) with 2 variables, x1 and x2, having equal values.
It looks like:
x1 x2
1 1
2 2
3 3
Now, consider a second data frame (xk):
xk1 xk2
0.5 0.5
1.0 0.5
1.5 0.5
2.0 0.5
0.5 1
1.0 1
1.5 1
2.0 1
0.5 1.5
1.0 1.5
1.5 1.5
2.0 1.5
0.5 2
1.0 2
1.5 2
2.0 2
I have written code to calculate some differences between these
2007 Aug 31
2
memory.size help
I keep getting the 'memory.size' error message when I run a program I have
been writing. It always it cannot allocate a vector of a certain size. I
believe the error comes in the code fragement below where I have multiple
arrays that could be taking up space. Does anyone know a good way around
this?
w1 <- outer(xk$xk1, data[,x1], function(y,z) abs(z-y))
w2 <- outer(xk$xk2,
2007 Aug 29
0
a faster and shorter way to perform calculations?
This is a continuation from a previous posting of mine:
The following algorithm below is what I want to accomplish:
Z(xk) = Average(Yi, i belongs to Ik), where Ik contains all i such that for
each j, |Xi,j - xkj?? 2. Here, j = 1, 2 and i corresponds to the elements
in each X and/or xk
>data
x1 x2 y
1 1 2
2 2 6
3 3 12
Now, consider a second data frame or matrix (xk):
2008 Jan 07
1
Avoiding FOR loops
useR's,
I would like to know if there is a way to avoid using FOR loops to perform
the below calculation.
Consider the following data:
> x
[,1] [,2] [,3]
[1,] 4 11 1
[2,] 1 9 2
[3,] 7 3 3
[4,] 3 6 4
[5,] 6 8 5
> xk
Var1 Var2 Var3
1 -0.25 1.75 0.5
2 0.75 1.75 0.5
3 1.75 1.75 0.5
4 2.75 1.75 0.5
5 3.75 1.75
2008 Feb 21
0
extending code to handle more variables
useR's,
Consider the variables defined below:
yvals <- c(25,30,35)
x1 <- c(1,2,3)
x2 <- c(3,4,5)
x3 <- c(6,7,8)
x <- as.data.frame(cbind(x1,x2,x3))
delta <- c(2.5, 1.5, 0.5)
h <- delta/2
vars <- 3
xk1 <- seq(min(x1)-0.5, max(x1)+0.5, 0.5)
xk2 <- seq(min(x2)-0.5, max(x2)+0.5, 0.5)
xk3 <- seq(min(x3)-0.5, max(x3)+0.5, 0.5)
xks <- list(xk1,xk2,xk3)
xk <-
2007 Sep 10
5
finding the minimum positive value of some data
useRs,
I am looking to find the minimum positive value of some data I have.
Currently, I am able to find the minimum of data after I apply some other
functions to it:
> x
[1] 1 0 1 2 3 3 4 5 5 5 6 7 8 8 9 9 10 10
> sort(x)
[1] 0 1 1 2 3 3 4 5 5 5 6 7 8 8 9 9 10 10
> diff(sort(x))
[1] 1 0 1 1 0 1 1 0 0 1 1 1 0 1 0 1 0
> min(diff(sort(x)))
[1] 0
2009 Nov 04
4
unexpected results in comparison (x == y)
Dear readers of the list,
I have a problem a comparison of two data from a vector. The comparison
yields FALSE but should be TRUE. I have checked for mode(), length() and
attributes(). See the following code (R2.10.0):
-----------------------------------------------
# data vector of 66 double data
X =
2008 Jul 24
2
simple random number generation
useR's,
I want to randomly generate 500 numbers from the standard normal
distribution, i.e. N(0,1), but I only want them to be generated in the range
-1.5 to 1.5. Does anyone have a simple way to do this?
Thanks,
dxc13
--
View this message in context: http://www.nabble.com/simple-random-number-generation-tp18642611p18642611.html
Sent from the R help mailing list archive at Nabble.com.
2009 May 24
2
Deleting columns from a matrix
useR's,
I have a matrix given by the code:
mat <-
matrix(c(rep(NA,10),1,2,3,4,5,6,7,8,9,10,10,9,8,NA,6,5,4,NA,2,1,rep(NA,10),1,2,3,4,NA,6,7,8,9,10),10,5)
This is a 10x5 matrix containing missing values. All columns except the
second contain missing values. I want to delete all columns that contain
ALL missing values, and in this case, it would be the first and fourth
columns. Any column
2009 May 04
2
A variation on the bar plot
Hi all,
I cannot think of the technical name of this plot, but I want to create a
plot with the data below that looks like two back-to-back horizontal bar
plots.
Ideally, there would be a vertical line in the center of the plot at zero,
and on the right hand side would be 4 bars representing the values for 2007,
and on the left side of the vertical line would be the corresponding values
for 2005.
2008 Jan 16
3
color ranges on a 2D plot
useR's
I am trying to color the points on a scatter plot (code below) with two
colors. Red for values 0.5 -1.0 and blue for 0.0 - .49. Does anyone know a
easy way to do this?
x <- runif(100, 0, 1)
y <- runif(100, 0, 1)
plot(y ~ x, pch=16)
Thanks,
dxc13
--
View this message in context: http://www.nabble.com/color-ranges-on-a-2D-plot-tp14893457p14893457.html
Sent from the R help
2009 May 19
3
how to calculate means of matrix elements
useR's,
I have several matrices of size 4x4 that I want to calculate means of their
respective positions with. For example, consider I have 3 matrices given by
the code:
mat1 <- matrix(sample(1:20,16,replace=T),4,4)
mat2 <- matrix(sample(-5:15,16,replace=T),4,4)
mat3 <- matrix(sample(5:25,16,replace=T),4,4)
The result I want is one matrix of size 4x4 in which position [1,1] is the
2009 May 11
2
Plotting colors on a world map
Hi useR's
I have created a simple map of the world using the following code:
m <- map(xlim=c(-180,180), ylim=c(-90,90))
map.axes()
I then create a grid of dimension 36x72 using the code:
map.grid(m, nx=72, ny=36, labels=FALSE, col="black")
This gives 2592 grid cells. In a separate data set of dimension 36x72, I
have 2592 temperature values (some missing values are present)
2009 Apr 30
2
gridding values in a data frame
Hi all,
I have a data frame that looks like such:
LATITUDE LONGITUDE TEMPERATURE TIME
36.73 -176.43 58.32 1
50.95 90.00 74.39 1
-30.42 5.45 23.26 1
15.81 -109.31 52.44 1
-80.75 -144.95 66.19 2
90.00 100.55 37.50 2
2007 Sep 17
2
how to compare 2 numeric vectors
useR's
I am trying to compare two vectors that have the same length. More
specifically, I am interested in comparing the corresponding positions of
each element in the vector.
Consider these two vectors of length 20:
v1 <- 2 2 4 NA NA NA 10 NA NA NA NA NA NA NA NA NA NA
NA NA NA
v2 <- NA 4 NA NA NA NA 10 NA NA NA NA NA NA NA NA NA NA
NA
2008 Aug 30
1
help with "persp" function
Dear List,
I am trying to draw a rectangular plane using the persp function, however I
can't seem to get it to work. I want the length along x1 axis to be between
1 and 3 and the length along the x2 axis to be between 1 and 4. All z
values for x1 should be equal (say, z=1) because this is a plane, not a
cube. Below is my current code. Any help is appreciated
Thanks in advance
dxc13
x
1997 Aug 21
1
R-alpha: another ctest question
I have the following problem. Consider a `classical' test which works
for k .ge. 2 samples. Possible interfaces are e.g.
xxx.test(x, g) x ... all data, g ... corresponding groups
xxx.test(x1, ..., xk)
xxx.test(list(x1, ..., xk))
etc etc.
Clearly, the first and the second one are nice, but cannot be combined
without making `g' (i.e., `group') a named argument.
Hence, in
2008 Jan 11
1
matching values in a list
useR's,
I want to match the real number elements of a list that has 3 matrices as
its elements and then average those numbers. I think I am close, but I
can't get it to quite work out. For example,
> a <- list(matrix(c(10,NA,NA,12,11,
> 10,13,NA,14,12),ncol=2),matrix(c(10,12,15,13,11,
> 13,NA,NA,12,10),ncol=2),matrix(c(10,15,NA,13,NA, 13,12,NA,NA,10),ncol=2))
> a
[[1]]
2009 May 13
4
plotting a grid with color on a map
Hi all,
I have posted similar questions regarding this topic, but I just can't seem
to get over the hump and find a straightforward way to do this. I have
attached my file as a reference.
Basically, the attached file is a 5 degree by 5 degree grid of the the world
(2592 cells), most of them are NA's. I just want to be able to plot this
grid over a world map and color code the cells. For
2003 Oct 28
2
outer function problems
I'm pulling my hair (and there's not much left!) on this one. Basically I'm
not getting the same result t when I "step" through the program and evaluate
each element separately than when I use the outer() function in the
FindLikelihood() function below.
Here's the functions:
Dk<- function(xk,A,B)
{
n0 *(A*exp(-0.5*(xk/w)^2) + B)
}
FindLikelihood <-