Displaying 20 results from an estimated 4000 matches similar to: "strsplit a matrix"
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",
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
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
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
2007 Jul 24
1
cor inside/outside a function has different output
I'm calculating correlations between two matrices
mat1 <- matrix(sample(1:500,25), ncol = 5,
dimnames=list(paste("mat1row", 1:5, sep=""),
paste("mat1col", 1:5, sep="")))
mat2 <- matrix(sample(501:1000,25), ncol = 5,
dimnames=list(paste("mat2row", 1:5, sep=""),
paste("mat2col", 1:5, sep="")))
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
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
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 <-
2013 Jan 04
2
Working with Matrix
Hello again,
Let say I have 2 matrices which equal number of columns but different
number of rows like:
Mat1 <- matrix(1:20, 4, 5)
Mat2 <- matrix(1:25, 5, 5)
Now for each column 1-to-5 I need to fetch the corresponding columns
of these 2 matrices and add the corresponding elements (ignoring NA
values if any). Therefore for the 1st column I need to do:
(1+1), (2+2),...,(4+4), (NA+5)
and
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
2008 Aug 29
2
Newbie: Examples on functions callling a library etc.
Hello
R is pretty new to me. I need to write a function that returns three
matrices of different dimensions. In addition, I need to call a function
from a contributed package with the function. I have browsed several
manuals and docs but the examples on them are either very simple or
extremely hard to follow.
Many thanks
Ed
[[alternative HTML version deleted]]
2013 Sep 20
3
search species with all absence in a presence-absence matrix
Dear list
I have a matrix composed of islandID as rows and speciesID as columns.
IslandID: Island A, B, C….O (15 islands in total)
SpeciesID: D0001, D0002, D0003….D0100 (100 species in total)
The cell of the matrix describes presence (1) or absence (0) of the species
in an island.
Now I would like to search the species with absence (0)
in all the islands (Island A to Island O.)
2009 Jul 02
2
matching rows in matrices
I have a matrix such as this,
[,1] [,2] [,3]
[1,] 1 1 2
[2,] 2 5 5
and a larger matrix such as this,
a b
[1,] 1 5
[2,] 2 5
[3,] 4 9
[4,] 5 8
[5,] 7 8
[6,] 7 10
[7,] 9 10
what I want to do is check the number of times the columns in the first
matrix appear as rows in the second matrix. So for instance in this example
1,5 and 2,5 appear in both so I'd want
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}))
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