Displaying 20 results from an estimated 20000 matches similar to: "Setting xlim in lattice plots"
2023 Jan 27
3
implicit loop for nested list
>
> I am looking for a more elegant way to write below code.
>
> #Simulation results have different dimensions
> mysim <- lapply(1:10, function(y) {
> two.mat <- matrix(rnorm(4), nrow = 2)
> four.mat <- matrix(rnorm(16), nrow = 4)
> list(two.mat = two.mat, four.mat = four.mat) #results with different dimensions
> })
>
> #Collect different
2005 Sep 09
3
how to do something like " subset(mat, ("col1">4 & "col2">4)) "
Dear all,
I have a problem with the "subset()" function. I spent all day yesterday
with a collegue to solve it and we did not find a satisfying solution (even
in the archived mails), so I ask for your help.
Let's say (for a simple example) a matrix mat:
R> mat
cola colb colc
[1,] 1 4 7
[2,] 2 5 8
[3,] 3 6 9
My goal is to select the lines of the matrix on the basis of the
2023 Jan 27
1
implicit loop for nested list
I would use replicate() to do an operation with random numbers repeatedly:
```
mysim <- replicate(10, {
two.mat <- matrix(rnorm(4), 2, 2)
four.mat <- matrix(rnorm(16), 4, 4)
list(two.mat = two.mat, four.mat = four.mat)
})
```
which should give you a matrix-list. You can slice this matrix-list
just like normal, then cbind it in one step:
```
two.mat <-
2012 Mar 12
1
2 images on one plot
Dear all
with image I can plot only one set of values in one plot.
Do somebody have any insight how to put those 2 matrices into one picture
so that in one cell in image picture are both values from mat[1,1] and
mat2[1,1].
mat<-matrix(1:4, 2,2)
mat2<-matrix(4:1,2,2)
x <-1:2
y <-1:2
image(x, y, mat)
image(x, y, mat2)
The only way I found is to mix x or y for both matrices let
2008 Dec 05
2
xtable html links
Hi,
I was trying to get hyperlinks using xtable, but couldn't get the hyperlinks to function properly. For example, if I use
## Try to link NY times website to every figure in column 4
mat <- matrix(1:43,6,5)
mat[,5] <- "http://nytimes.com"
for(i in 1:nrow(mat)){
strr <- paste('<a href="', mat[i,5],'">', mat[i,4], '</a>',
2011 Sep 08
2
ggplot geom_freqpoly() layers ..?
Hi,
I was trying to overlay/combine two freqpoly plots. The sample code below
illustrates the problem. Essentially, I want to do is:
1. Have the same colour for all the lines in 'Plot 1' (and 'Plot 2').
Currently, all the lines in Plot 1 have different colours and all the lines
in Plot 2 have different colors. I'd like for all lines in Plot 1 to be
'red' and all the
2011 Sep 08
1
ggplot2 freqpoly() layers..?
Hi,
I was trying to overlay/combine two freqpoly plots. The sample code below illustrates the problem. Essentially, I want to do is:
1. Have the same colour for all the lines in 'Plot 1' (and 'Plot 2').
Currently, all the lines in Plot 1 have different colours and all the
lines in Plot 2 have different colors. I'd like for all lines in Plot 1
to be 'red' and all
2011 Nov 27
1
generating a vector of y_t = \sum_{i = 1}^t (alpha^i * x_{t - i + 1})
Dear R-help,
I have been trying really hard to generate the following vector given
the data (x) and parameter (alpha) efficiently.
Let y be the output list, the aim is to produce the the following
vector(y) with at least half the time used by the loop example below.
y[1] = alpha * x[1]
y[2] = alpha^2 * x[1] + alpha * x[2]
y[3] = alpha^3 * x[1] + alpha^2 * x[2] + alpha * x[3]
.....
below are
2010 Mar 02
2
turn character string into unevaluated R object
Hi,
How to turn a character string into an unevaluated R object? I want to load some files in a directory into data matrix R objects. I could do this with read.table and assign (see below). Then, I want to turn the character string representing a file name (the evaluated expression of i) into an unevaluated R object. Basically, I want to create matrices whose names are the same as the related file
2004 Apr 12
2
fractal calculation using fdim
Hello
I am getting this
Error in slopeopt(AllPoints, Alpha) : Object "LineP"
not found
when the dim(<data.frame>) of the data matrix for
which the fdim is being calculated hits a certain
values depending on the data set. e.g
print(dim(mat))
fd <- fdim(mat,q=2)
[1] 2743 2
[1] 2742 3
[1] 2741 4
[1] 2740 5
[1] 2739 6
[1] 2738 7
[1] 2737 8
[1] 2736 9
[1] 2735
2010 Mar 29
2
Need help on matrix manipulation
Dear all,
Ket say I have 3 matrices :
mat1 <- matrix(rnorm(16), 4)
mat2 <- matrix(rnorm(16), 4)
mat3 <- matrix(rnorm(16), 4)
Now I want to merge those three matrices to a single one with dimension
4*3=12 and 4 wherein
on resulting matrix, row 1,4,7,10 will be row-1,2,3,4 of "mat1", row
2,5,8,11 will be row-1,2,3,4 of "mat2" and row 3,6,8,12 will be row-1,2,3,4
of
2007 Aug 17
0
superposing lattice plots
Hello everyone,
I am sorry if this has already been asked but I can't find it. I want
to superpose two lattice plots, namely a levelplot and a contourplot
of two different variables with the same x-y scale. I found
information about panel.superpose but it does not seem to correspond
to what I want (I have two different variables, not groups of the
same variable)
How can I do this?
2006 Jul 20
2
Timing benefits of mapply() vs. for loop was: Wrap a loop inside a function
List:
Thank you for the replies to my post yesterday. Gabor and Phil also gave
useful replies on how to improve the function by relying on mapply
rather than the explicit for loop. In general, I try and use the family
of apply functions rather than the looping constructs such as for, while
etc as a matter of practice.
However, it seems the mapply function in this case is slower (in terms
of CPU
2004 May 14
5
Tagging identical rows of a matrix
I would like to generate a vector having the same length
as the number of rows in a matrix. The vector should contain
an integer indicating the "group" of the row, where identical
matrix rows are in a group, and a unique row has a unique integer.
Thus, for
a <- c(1,2)
b <- c(1,3)
c <- c(1,2)
d <- c(1,2)
e <- c(1,3)
f <- c(2,1)
mat <- rbind(a,b,c,d,e,f)
I would
2010 Feb 12
3
Code working but too slow, any idea for how to speed it up ?(no loop in it)
Hello my friends,
here is a code I wrote with no loops on matrix that is taking too long (2
seconds and I call him 720 times --> 12 minutes):
mat1 and mat2 are both matrix with 103 columns and 164 rows.
sequence <- matrix(seq(1 : ncol(mat1)))
returns <- apply(sequence, 1, function, mat1= mat1, mat2 = mat2, day = 1)
function<- function(mat1, mat2, colNb, day){
2010 Aug 03
4
Need help on upper.tri()
HI, I am really messing up to make a symmetrical matrix using upper.tri() & lower.tri() function. Here is my code:
> set.seed(1)
> mat = matrix(rnorm(25), 5, 5)
> mat
[,1] [,2] [,3] [,4] [,5]
[1,] -0.6264538 -0.8204684 1.5117812 -0.04493361 0.91897737
[2,] 0.1836433 0.4874291 0.3898432 -0.01619026 0.78213630
[3,] -0.8356286 0.7383247
2008 Aug 01
2
Storing Matrices into Hash
Hi,
Suppose I have these two matrices (could be more).
What I need to do is to store these matrices into a hash.
So that I can call back any of the matrix back later.
Is there a way to do it?
> mat_1
[,1] [,2]
[1,] 9.327924e-01 0.067207616
[2,] 9.869321e-01 0.013067929
[3,] 9.892814e-01 0.010718579
[4,] 9.931603e-01 0.006839735
[5,] 9.149056e-01 0.085094444
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
2006 May 30
2
merging
Dear List,
Given,
y <- matrix(c(0,1,1,1,0,0,0,4,4), ncol = 3, byrow = TRUE)
rownames(y) <- c("a","b","c")
colnames(y) <- c("1","2","3")
y
y2 <- y[2:3, ]
rownames(y2) <- c("x","z")
y2
how can I stop
merge(y, y2, all = TRUE, sort = FALSE)
squishing the extra rows? Ideally I want the same as:
rbind(y,
2010 Dec 02
1
Arrange elements on a matrix according to rowSums + short 'apply' Q
Greetings,
My goal is to create a Markov transition matrix (probability of moving from
one state to another) with the 'highest traffic' portion of the matrix
occupying the top-left section. Consider the following sample:
inputData <- c(
c(5, 3, 1, 6, 7),
c(9, 7, 3, 10, 11),
c(1, 2, 3, 4, 5),
c(2, 4, 6, 8, 10),
c(9, 5, 2, 1, 1)
)
MAT <- matrix(inputData,