search for: mat2

Displaying 20 results from an estimated 117 matches for "mat2".

Did you mean: mat
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){ mat1<- matrix(mat1[, colNb] ) mat2<- matrix(mat2[, colNb...
2001 Sep 27
1
cuts and breaks
Hi I'm using the "image" function to produce a plot and I want to define the breaks using "cut" and the colors using "heat.colors". > image(interp(mat2[,2],mat2[,1],mat2[,3]),breaks=cut(mat2[,3],30),col=heat.colors(29)) Error in image.default(interp(mat2[, 2], mat2[, 1], mat2[, 3]), breaks = cut(mat2[, : must have one more break than colour The error message is not clear to me because I'm using 30 to cut and 29 to heat.colors. Wh...
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", 1:5, sep="") rownames(mat2) <- paste("site", 6:9, sep="") names(mat1) <- paste("species", c(1,3,5,7), sep="") names(mat2) <- paste("species&q...
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-...
2023 Jan 27
3
implicit loop for nested list
...lt;- 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 components of simulation results > #Is it possible to do this with implicit loops? > mat2 <- matrix(nrow = 2, ncol = 1) > mat4 <- matrix(nrow = 4, ncol = 1) > for (mat.list in mysim) { > mat2 <- cbind(mat2, mat.list[["two.mat"]]) > mat4 <- cbind(mat4, mat.list[["four.mat"]]) > } > mat2 <- mat2[,-1] > mat4 <- mat4[,-1]
2005 Sep 09
3
how to do something like " subset(mat, ("col1">4 & "col2">4)) "
...[3,] 3 6 9 My goal is to select the lines of the matrix on the basis of the values of more than one column (let's say colb and colc). For example I want to select all the lines of the matrix for which values in colb and colc are more than 4. I tried several ways that did not work: R> mat2 <- subset(mat, ("colb">4 & "colc">4)) R> mat2 [1] 1 2 3 4 5 6 7 8 9 it is a vector, not a matrix. > mat2 <- subset(mat, mat[,2:3]>4) > mat2 [1] 2 3 4 5 6 8 9 tha same: it is a vector; so I tried: > mat2 <- as.matrix(subset(mat, mat[,(&quot...
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 all of column names A, B or C, etc.) (same name in both matrices if that matters - r...
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]]
2003 Oct 31
2
Summing elements in a list
...n 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, here is the code I would use with a for loop result <- list(mat1=matrix(0,nrow1,ncol1), mat2=matrix(0,nrow2,ncol2)) for (i in seq(along=matlist)) { result$mat1 <- result$mat1+w[i]*matlist[[i]]$mat1 result$mat2 <- result$mat2+w[i]*matlist[[i]]$mat2 } I apologise if this is a trivial question. Unfortunately I don't have my copy of V&R S Programming to hand. Thanks for...
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 message: Warning message: appending column names to file in: write.table(mat2, "foo.csv",...
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 say xm <- sort(c(x,x+.5)) matm <- cbind(mat[,1], mat2[,1], mat[,2], mat2[,2]) image(xm,y,t(matm)) which lacks of el...
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 does not work for the final two rows because of the NA's. Are there any elegant ways to accopmlish this without writing a loop with indices? Th...
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=""))) using what would seem to be two similar methods: Method 1: > f <- function(x,y) cor(x,y) > apply...
2010 Oct 14
1
rbind ing matrices and resetting column numbers
...row","ti","counti") > colnm2 <- c("row","tj","countj") > mat1 <- matrix(c(1,7,9,2,8,5,3,7,9),byrow=T,nrow=3) > colnames(mat1) <- colnm1 > mat1 row ti counti [1,] 1 7 9 [2,] 2 8 5 [3,] 3 7 9 > mat2 <- matrix(c(1,5,3,2,6,8,3,3,7),byrow=T,nrow=3) > colnames(mat2) <- colnm2 > mat2 row tj countj [1,] 1 5 3 [2,] 2 6 8 [3,] 3 3 7 > mat3 <- rbind(mat1,mat2) > mat3 row ti counti [1,] 1 7 9 [2,] 2 8 5 [3,] 3 7 9 [4,] 1 5...
2012 Jun 14
0
fixed trimmed mean for j-group
...nt(j) set.seed(j) n1=15 n2=15 n3=15 n4=15 miu=0 sd1=1 sd2=1 sd3=1 sd4=1 a=rnorm(n1,miu,sd1) b=rnorm(n2,miu,sd2) c=rnorm(n3,miu,sd3) d=rnorm(n4,miu,sd4) ## data transformation g=0 h=0 w<-a*exp(h*a^2/2) x<-b*exp(h*b^2/2) y<-c*exp(h*c^2/2) z<-d*exp(h*d^2/2) mat1<-sort(w) mat2<-sort(x) mat3<-sort(y) mat4<-sort(z) alpha=0.15 k1=floor(alpha*n1)+1 k2=floor(alpha*n2)+1 k3=floor(alpha*n3)+1 k4=floor(alpha*n4)+1 r1=k1-(alpha*n1) r2=k2-(alpha*n2) r3=k3-(alpha*n3) r4=k4-(alpha*n4) ## j-group trimmed mean e1=k1+1 f1=n1-k1 e2=k2+1 f2=n2-k2 e3=k3+1 f3=n3-k3 e4=k4+1...
2023 Jan 27
1
implicit loop for nested list
...t; > four.mat <- matrix(rnorm(16), nrow = 4) > > list(two.mat = two.mat, four.mat = four.mat) #results with different dimensions > > }) > > > > #Collect different components of simulation results > > #Is it possible to do this with implicit loops? > > mat2 <- matrix(nrow = 2, ncol = 1) > > mat4 <- matrix(nrow = 4, ncol = 1) > > for (mat.list in mysim) { > > mat2 <- cbind(mat2, mat.list[["two.mat"]]) > > mat4 <- cbind(mat4, mat.list[["four.mat"]]) > > } > > mat2 <- mat2[,-1]...
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...
2008 Aug 01
2
Storing Matrices into Hash
...059827 [3,] 9.892886e-01 0.010711437 [4,] 9.931660e-01 0.006833979 [5,] 9.149391e-01 0.085060890 This method I have is not favorable because it just stack the matrices together as another matrix. Makes it hard to get individual matrix later. all_mat <- NULL all_mat <- c(all_mat, mat1,mat2) - Gundala Viswanath Jakarta - Indonesia
2013 Jun 24
1
help needed with printing multiple arguments as vectors, not matrices
...ll 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 = matrix(c(n00, n01, n10, n11), nrow = 2); pval = fisher.test(a)$p.value; return(pval);} chiArray <- function(x) { apply(mat1, 1, fish, x); } sapply(1:nrow(mat2), function(j){chiArray(mat2[j, ]);}); chisq.cna.mut.test <- sapply(1:nrow(mat2), function(j){chiArray(mat2[j, ]);}); I want output to be: name1_mat1 name1_mat2 n00 n01 n10 n11 pvalue name1_mat1 name2_mat2 n00 n01 n10 n11 pvalue [[alternative HTML version deleted]]