similar to: update matrix with subset of it where only row names match

Displaying 20 results from an estimated 1000 matches similar to: "update matrix with subset of it where only row names match"

2006 Mar 28
1
weights in glm (PR#8720)
Full_Name: Robert Pusz Version: 2.2.1 OS: Windows Submission from: (NULL) (157.25.9.126) Hello, In my opinion something is wrong with 'weights' option in glm. My code is following: ###begin of the code#### cl <- c(5012, 106, 3410, 5655, 1092, 1513, 557, 1351, 3133, 2063, 3257, 4179, 5582, 5900, 8473, 4932, 3463, 5596, 2262, 0, 2638, 1111, 4881, 4211, 6271, 5257, 6926, 6165, 0, 0,
2009 Mar 05
3
Dropping rows conditionally
Dear R-help team, I am getting addicted to using R but keep on getting many challenges on the way especially on data management (data cleaning). I have been wanting to drop all the rows if there values are `NA' or have specific values like 1 or 2 or 3. mdat <- matrix(1:21, nrow = 7, ncol=3, byrow=TRUE, dimnames = list(c("row1",
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",
2009 Dec 27
4
how to create a simple loop ?
I have a 5-row matrix called “data”. There are headers. it look like this : Row 1 Row2 Row3 Row4 Row5 Line1 … … … … Line2 … … … … Line3 … … … … … Line 1838 … … … … I want to calculate several simple arithmetic means for Row5, that
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 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 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 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
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
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
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
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) {
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 =
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
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
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