similar to: matrix elementwise average with NA's

Displaying 20 results from an estimated 3000 matches similar to: "matrix elementwise average with NA's"

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){
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
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",
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="")))
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,
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
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 <-
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
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 Jan 27
1
How to sort data.frame
Dear R heleprs   Suppose I have following data   Scenarios combination_names     series1    series2 Sc1 MAT2 GAU1 7.26554 8.409778 Sc2 MAT2 GAU2 7.438128 8.130275 Sc3 MAT3 GAU1 8.058422 8.06457 Sc4 MAT1 GAU2 8.179855 8.022071 Sc5 MAT3 GAU2 8.184033 8.191831 Sc6 MAT3 GAU2 7.50312 8.232425 Sc7 MAT1 GAU2 7.603291 8.200993 Sc8 MAT1 GAU1 8.221755 8.380097 Sc9 MAT3 GAU2 7.904908
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
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) {
2011 Oct 17
2
Reading data with 'awk' - basics?
Hi, I had a large file for which I require a subset of rows. Instead of reading it all into memory, I use the awk command to get the relevant rows. However, I'm doing it pretty inefficiently as I write the subset to disk, before reading it into R. Is there a way that I can read it into an R object without writing to disk? For example, this is what I do currently: ## write test sample file
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 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
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,
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 Mar 05
1
coxme - fitting random treatment effect nested within centre
Dear all, I am using "coxme" function in Kinship library to fit random treatment effect nested within centre. I got 3 treatments (0,1,2) and 3 centres. I used following commands, but got an error. > ugroup=paste(rep(1:3,each=3),rep(0:2,3),sep='/') > mat1=bdsmatrix(rep(c(1,1,1,1,1,1,1,1,1),3),blocksize=rep(3,3),dimnames=list(ugroup,ugroup)) >
2005 Apr 29
1
na.action
Hi, I had the following code: testp <- rcorr(t(datcm1),type = "pearson") mat1 <- testp[[1]][,] > 0.6 mat2 <- testp[[3]][,] < 0.05 mat3 <- mat1 + mat2 The resulting mat3 (smaller version) matrix looks like: NA 0 0 0 0 NA 0 NA 0 0 NA 2 0 0 2 NA To get to the number of times a '2' appears in the rows, I was
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,