Displaying 20 results from an estimated 20000 matches similar to: "Comparing rows of matrices with different dimensions"
2005 Dec 22
1
panel order in xyplot
Hi all,
I have a question concerning xyplot. My data is a data.frame looking like that:
In the first column I have numbers from 0 to 23 (hours of a day), the second column contains the name of a weekday (Day as factor) and the third column contains the number I am interested in. So as an example, the first five rows look like that:
Hour Day Freq
1 0 Mo 23
2 1 Mo
2006 Jun 27
1
Adding elements of matrices of different dimensions
If I have two matrices:
> a<-matrix(1:5,ncol=1)
[,1]
[1,] 1
[2,] 2
[3,] 3
[4,] 4
[5,] 5
> b<-matrix(1:50,ncol=10)
[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
[1,] 1 6 11 16 21 26 31 36 41 46
[2,] 2 7 12 17 22 27 32 37 42 47
[3,] 3 8 13 18 23 28 33 38 43 48
[4,] 4 9 14 19
2006 Jan 09
3
two y-axis in xy-plot
Hi there,
I am wondering if it is possible to do an xyplot with two y-axes. I'd like to print two parameters in a time series but they both have different scales.
Which parameter in xyplot can I add to achieve this result?
Thanks a lot for any help.
Antje
[[alternative HTML version deleted]]
2005 Feb 21
5
Compare rows of two matrices
Hello,
#I have two matrices, eg.:
y <- matrix( c(20, NA, NA, 45, 50, 19, 32, 101, 10, 22, NA, NA, 80, 49, 61, 190), ncol=4 )
x <- matrix( c(20, NA, NA, NA, 50, 19, 32, 101, 10, 22, NA, NA, 80, 49, 61, 190), ncol=4 )
#Whereas x contains all NA?s from y plus some additional NA?s.
#I want to find the index of these additional NA?s. I think, there must be a very
2006 Jul 06
3
Comparing two matrices
hi:
I have matrix with dimensions(200 X 20,000). I have
another file, a tab-delim file where first column
variables are row names and second column variables
are column names.
For instance:
> tmat
Apple Orange Mango Grape Star
A 0 0 0 0 0
O 0 0 0 0 0
M 0 0 0 0 0
G 0 0 0 0 0
S 0 0 0 0 0
2006 Aug 23
5
two density curves in one plot?
Hello,
I was wondering if I can plot two curves I get from "density(data)" into
one plot. I want to compare both.
With the following commad, I just get one curve plotted:
plot( density(mydata) )
Sorry for this stupid question but I could not find a solution until now...
Antje
2005 Jan 14
3
summing subsets of rows matrices
I have a large data matrix (4460X3500) and I want to sum row subsets in groups of 10 (bin). Is there an efficient way to do this in R without using loops. Looping takes forever to perform this task!
For example suppose we have the matrix
> matrix(1:12,6,2)
[,1] [,2]
[1,] 1 7
[2,] 2 8
[3,] 3 9
[4,] 4 10
[5,] 5 11
[6,] 6 12
my problem is to sdum for
2008 Mar 13
2
joining matrices, vectors, scalars in one object
Hi,
I have:
a <- matrix(c(0,1,0,1),nrow=2)
b <- matrix(c(1,1,1,0,0,0),nrow=3)
c <- 1
d <- c(1,0,1)
And I would like to join them in an object 'thing' so that I can
access a, b, c, or d through an index in a for loop.
For example:
thing[4]
would return
[1] 1 0 1
Note however, that I have many of these 'thing' components. So many
that a command like
thing
2004 Jun 11
4
rownames of single row matrices
Hi
I want to extract rows of a matrix, and preserve rownames even if only
one row is selected. Toy example:
R> a <- matrix(1:9,3,3)
R> rownames(a) <- letters[1:3]
R> colnames(a) <- LETTERS[1:3]
R> a
A B C
a 1 4 7
b 2 5 8
c 3 6 9
Extract the first two rows:
R> wanted <- 1:2
R> a[wanted,]
A B C
a 1 4 7
b 2 5 8
rownames come through fine. Now extract just
2005 Mar 16
8
Summing up matrices in a list
Dear all,
I think that my question is very simple but I failed to solve it.
I have a list which elements are matrices like this:
>mylist
[[1]]
[,1] [,2] [,3]
[1,] 1 3 5
[2,] 2 4 6
[[2]]
[,1] [,2] [,3]
[1,] 7 9 11
[2,] 8 10 12
I'd like to create a matrix M<-mylist[[1]]+mylist[[2]]
[,1] [,2] [,3]
[1,] 8 12 16
[2,] 10 14 18
2008 Sep 22
1
how to set rownames / colnames for matrices in a list
Hello,
I have another stupid question. I hope you can give me a hint how to solve this:
I have a list and one element is again a list containing matrices, all of the
same dimensions. Now, I'd like to set the dimnames for all matrices:
example code:
m1 <- matrix(1:25, nrow=5)
m2 <- matrix(26:50, nrow=5)
# ... there can be much more than two matrices
l <- list()
l[[1]] <-
2007 May 04
2
Get the difference between two matrices with different length
Hello,
I have got two matrices with different length. The matrices have 3
columuns. The first two are coordinates. The third is a measurement.
Now I want to get a subtraction between every single value of the
third column (between matrix1 and matrix2), but only if the two
first coordinates in matrix1 and matrix2 are the same.
I tried "FUN=?" in aggregate and ave, but I don't know
2006 Jan 16
1
label of second y-axis in xyplot (lattice)
Dear group,
First I provide you with an example, I found in the newsgroup. Then I'd like to explain my problem to you by means of the output.
enviro <-
data.frame(Year = rep(2001:2002, each = 365),
Day = rep(1:365, 2),
Precip = pmax(0, rnorm(365 * 2)),
Temp = 2 + 0.2 * rnorm(365 * 2))
xyplot(Precip + Temp ~ Day | Year,
2008 Jun 04
4
sum of unknown number of matrices
Hi R,
I have a list of matrices. I need to get the sum of all the matrices in
the list.
Example:
a=b=c=d=matrix(1:4,2,2)
l=list(a,b,c,d)
I need:
> a+b+c+d
[,1] [,2]
[1,] 4 12
[2,] 8 16
Something like do.call("+",l) is not working...why is this?
I may not be knowing the number of matrices in the list...
Thanks, Shubha
This e-mail
2007 May 04
4
logical or for two vectors or matrices
Hello,
it might be a very simple question but I cannot find the solution (I tried a || b, any(a,b)... but none works). My problem is:
I have two vectors,
a <- c(TRUE,FALSE,FALSE)
b <- c(TRUE,FALSE,TRUE)
and I would like to obtain a vector that indicates if it is TRUE in any of the two vectors. Hence, the desired output would be: TRUE, FALSE, TRUE
Thank you in advance,
Federico
2004 May 12
2
Extracting data from matrices
Dear R list
I have an m * n matrix P and a vector V of length n containing indices for
rows in P.
For each of the m columns I want to extract the value in the row specified
by V, and put these values into a new vector W of length n.
At present I am doing this with a for.... loop, but I imagine there is a faster
way that doesn?t involve loops.
If anyone knows the way I would be most grateful.
2008 Jul 18
2
generate repeats of a vector's elements
Dear all,
I have got a question for generating repeats of a vector's elements.
Please don't hesitate to email me back and say that it is very easy
although I can't find a method to solve it.
If I have a n-vector b, whose elements are b[1], b[2], ..., b[n], how
can I generate such a vector
b[1], b[1], b[2], b[1], b[2], b[3], b[1], b[2], b[3], b[4],
......, b[1], b[2], ...,
2005 May 10
4
summary statistics for lists of matrices or dataframes
Is there a simple way to calculate summary statistics for all the
matrices or dataframes in a list? For example:
> z <- list(matrix(c(2,2,2,2), ncol = 2), matrix(c(4,4,4,4), ncol = 2))
> z
[[1]]
[,1] [,2]
[1,] 2 2
[2,] 2 2
[[2]]
[,1] [,2]
[1,] 4 4
[2,] 4 4
>
I would like to calculate, for example, the mean value for each
cell. I can do that the hard
2008 Jun 09
3
Overlaying the matrices
Hi R,
I have a matrix,
> x1=matrix(NA,6,6,dimnames=list(letters[1:6],LETTERS[1:6]))
> x1
A B C D E F
a NA NA NA NA NA NA
b NA NA NA NA NA NA
c NA NA NA NA NA NA
d NA NA NA NA NA NA
e NA NA NA NA NA NA
f NA NA NA NA NA NA
> x2=matrix(rpois(9,1),3,3,dimnames=list(c("b","a","f"),c("D","E","F")))
> x2
2006 Jan 10
2
Correct way to test for exact dimensions of matrix or array
Dear R Users,
I want to test the dimensions of an incoming vector, matrix or array safely
and succinctly. Specifically I want to check if the unknown object has
exactly 2 dimensions with a specified number of rows and columns.
I thought that the following would work:
> obj=matrix(1,nrow=3,ncol=5)
> identical( dim( obj) , c(3,5) )
[1] FALSE
But it doesn't because c(3,5) is numeric