Displaying 20 results from an estimated 8000 matches similar to: "matching rows in matrices"
2009 Jul 06
2
Extracting only the non-repeated rows of matrices
I have 2 matrices. One which contains a complete set of row combinations.
Another which contains a subset of the first. What I would like to extract
is the rows which are in the first but not repeated in the second. For
instance if the following were my two matrices,
A
[,1] [,2] [,3] [,4]
[1,] 1 2 3 4
[2,] 1 2 3 5
[3,] 1 2 3 6
[4,] 1 2 3
2005 Oct 06
1
Compare two distance matrices
Hi all,
I am trying to compare two distance matrices with R. I would like to
create a XY plot of these matrices and do some linear regression on
it. But, I am a bit new to R, so i have a few questions (I searched in
the documentation with no success).
The first problem is loading a distance matrix into R. This matrix is
the output of a the Phylip program Protdist and lookes like this:
5
2007 Nov 12
1
update matrix with subset of it where only row names match
I guess this has a simple solution:
I have matrix 'mat1' which has row and column names, e.g.:
A B C
row1 0 0 0
row2 0 0 0
....
rown 0 0 0
I have a another matrix 'mat2', essentially a subset of 'mat1' where the
rownames are all in 'mat1' e.g.:
B
row3 5
row8 6
row54 7
I want to insert the values of matrix mat2 for column B (in reality it
could be some or
2010 Oct 14
1
rbind ing matrices and resetting column numbers
Sorry for the verbose example. I want to row bind two matrices, and all works except I want the column labelled "row" to be sequential in the new matrix, shown as "mat3" here, i.e. needs to be 1:6 and not 1:3 repeated twice. Any suggestions?
Thanks
J
> colnm1 <- c("row","ti","counti")
> colnm2 <-
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
2008 Aug 15
2
cor() btwn columns in two matrices - no complete element pairs
Hi everyone,
I'm trying to calculate correlation coefficients between corresponding
columns in two matrices with identical dimensions but different data. The
problem is that the matrices contain NAs in different locations. I am using
the following code to try to calculate correlations between complete sets of
data:
#Code start
maxcol<-ncol(mat1)
for (i in 1:maxcol)
{
2007 Aug 10
7
Help wit matrices
Hello all,
I am working with a 1000x1000 matrix, and I would like to return a
1000x1000 matrix that tells me which value in the matrix is greater
than a theshold value (1 or 0 indicator).
i have tried
mat2<-as.matrix(as.numeric(mat1>0.25))
but that returns a 1:100000 matrix.
I have also tried for loops, but they are grossly inefficient.
THanks for all your help in advance.
Lanre
2013 Feb 27
2
matrix multiplication
Hi,
Try this:
#mat1 is the data
res<-do.call(cbind,lapply(seq_len(nrow(mat1)),function(i) {new1<-do.call(rbind,lapply(seq_len(nrow(mat1[-i,])),function(j) {x1<-rbind(mat1[i,],mat1[j,]); x2<-(abs(x1[1,1]-x1[2,1])*abs(x1[1,5]-x1[2,5]))+(abs(x1[1,2]-x1[2,2])*abs(x1[1,6]-x1[2,6]))+(abs(x1[1,3]-x1[2,3])*abs(x1[1,7]-x1[2,7]))+(abs(x1[1,4]-x1[2,4])*abs(x1[1,8]-x1[2,8]))}));new1}))
2010 Feb 13
3
how to do calculations in data matrices?
Please give me just a reference where I can find something useful.
In summary, I need to :
- find the median of each row of a matrix
- create a new matrix with each value in the first matrix divided by the median of its row
- if a value "a" in the second matrix is < 1, I need to substitute it with 1/a
I know that for some of you it must be overeasy, but I swear I googled for two
2010 Jan 29
7
Simple question on replace a matrix row
Hello, I have a matrix mat1 of dim [1,8] and mat2 of dim[30,8], I want to
replace the first row of mat2 with mat1, this is what I do:
mat2[1,]<-mat1 but it transforms mat2 in a list I don't understand, I want
it to stay a matrix...
-----
Anna Lippel
--
View this message in context: http://n4.nabble.com/Simple-question-on-replace-a-matrix-row-tp1427857p1427857.html
Sent from the R help
2007 Jan 21
2
multiple bases to decimal (was: comparing two matrices)
Hi again,
I was contemplating the solution using base 3:
set.seed(3)
mat2 <- matrix(sample(0:2, 15, replace=T), 5, 3)
Extracting the line numbers is simple:
bases <- c(3, 3, 3)^(2:0) # or just 3^(2:0)
colSums(apply(mat2, 1, function(x) x*bases)) + 1
[1] 7 23 25 8 1
The problem is sometimes the columns have different number of levels, as in:
mat1 <- expand.grid(0:2, 0:2,
2013 Jun 24
1
help needed with printing multiple arguments as vectors, not matrices
**
I am using the following way to get p-values from fiser exact test.
However, I do need to print for each pair the values "n00, n01, n10, n11".
How can I print that as a table and not a matrix as below along with the
p-value? Any help will be greatly appreciated
fish <- function(y, x) {n00 = sum((1-x)*(1-y)); n01 = sum((1-x)*y);
n10 = sum(x*(1-y)); n11 = sum(x*y); a =
2013 Feb 13
3
date and matrices
Hi Elisa,
Try this:
date1<-format(seq.Date(as.Date("1991.1.1",format="%Y.%m.%d"),as.Date("1996.12.31",format="%Y.%m.%d"),by="day"),"%Y.%m.%d")
?length(date1)
#[1] 2192
mat1<-matrix(c(.314,.314,.273,.273,.236,.236,.236,.236,.273,.314,.403,.314),ncol=1)
res1<-
2013 Sep 02
3
Product of certain rows in a matrix
Hi,
You could try:
A<- matrix(unlist(read.table(text="
1 2 3
4 5 6
7 8 9
9 8 7
6 5 4
3 2 1
",sep="",header=FALSE)),ncol=3,byrow=FALSE,dimnames=NULL)
library(matrixStats)
?res1<-t(sapply(split(as.data.frame(A),as.numeric(gl(nrow(A),2,6))),colProds))
?res1
#? [,1] [,2] [,3]
#1??? 4?? 10?? 18
#2?? 63?? 64?? 63
#3?? 18?? 10??? 4
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){
2005 Nov 03
4
merging dataframes
Dear List,
I often have to merge two or more data frames containing unique row
names but with some columns (names) common to the two data frames and
some columns not common. This toy example will explain the kind of setup
I am talking about:
mat1 <- as.data.frame(matrix(rnorm(20), nrow = 5))
mat2 <- as.data.frame(matrix(rnorm(20), nrow = 4))
rownames(mat1) <- paste("site",
2003 Oct 31
2
Summing elements in a list
Hi,
Suppose that I have a list where each component is a list of two
matrices. I also have a vector of weights. How can I collapse my
list of lists into a single list of two matrices where each matrix
in the result is the weighted sum of the corresponding matrices.
I could use a loop but this is a nested calculation so I was hoping
there is a more efficient way to do this. To help clarify,
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
2013 Mar 18
4
Counting confidence intervals
Hi,
I have a 2 x 10000 matrix of confidence intervals. The first column is the
lower and the next column is the upper. I want to cont how many times a
number say 12 lies in the interval. Can anyone assist?
--
Thanks,
Jim.
[[alternative HTML version deleted]]
2007 Apr 20
2
R: Appending the files
Hello R-Experts,
I am a beginner to R. Can someone please look at my problem
I am trying to append the files in R but couldn't get the answer properly.
My code is
mat1<-matrix(0,2,3)
mat2<-matrix(1,2,3)
write.table(mat1,"foo.csv",sep=",",col.names=NA)
write.table(mat2,"foo.csv", sep=",", col.names=NA, append = TRUE)
I am getting a warning