similar to: Removing rows of zeros from a matrix

Displaying 20 results from an estimated 40000 matches similar to: "Removing rows of zeros from a matrix"

2011 Jan 05
4
Match numeric vector against rows in a matrix?
Two posts in one day is not a good day...and this question seems like it should have an obvious answer: I have a matrix where rows are unique combinations of 1's and 0's: > combs=as.matrix(expand.grid(c(0,1),c(0,1))) > combs Var1 Var2 [1,] 0 0 [2,] 1 0 [3,] 0 1 [4,] 1 1 I want a single function that will give the row index containing an exact match
2012 Feb 21
4
removing particular row from matrix
I have some data set which has some values -999.000 & I would like to remove whole row of this kind of values. e.g a<-matrix(c(1,2,3,4,4,5,6,6,-999.99,5,9,-999.00),nrow=4) a<- [,1] [,2] [,3] [1,] 1 4 -999.99 [2,] 2 5 5.00 [3,] 3 6 9.00 [4,] 4 6 -999.00 expected answer [,1] [,2] [,3] [1,] 2 5 5.00 [2,] 3 6 9.00 I
2011 Jun 02
4
generating random covariance matrices (with a uniform distribution of correlations)
List members, Via searches I've seen similar discussion of this topic but have not seen resolution of the particular issue I am experiencing. If my search on this topic failed, I apologize for the redundancy. I am attempting to generate random covariance matrices but would like the corresponding correlations to be uniformly distributed between -1 and 1. The approach I have been using is:
2007 Mar 08
2
Removing duplicated rows within a matrix, with missing data as wildcards
I'd like to remove duplicated rows within a matrix, with missing data being treated as wildcards. For example > x <- matrix((1:3), 5, 3) > x[4,2] = NA > x[3,3] = NA > x [,1] [,2] [,3] [1,] 1 3 2 [2,] 2 1 3 [3,] 3 2 NA [4,] 1 NA 2 [5,] 2 1 3 I would like to obtain [,1] [,2] [,3] [1,] 1 3 2 [2,] 2 1 3
2012 Jun 12
4
How to subset a matrix?
Hi all, Lets say I have a matrix A which is m x n. I also have a mask matrix MASK which is m x n with values in T/F, where T values make a sub-matrix in regutangular shape... I applied B=A[MASK] and it didn't work as expected... Any thoughts? [[alternative HTML version deleted]]
2011 Feb 10
3
Permuting rows of a matrix
Hi, I need to permute the rows of a matrix, where each row is independently rearranged. A simple solution is this: shuffled <- datamatrix <- matrix(1:24, ncol = 4) for (i in 1:nrow(datamatrix)) { shuffled[i, ] <- sample(datamatrix[i, ]) } > datamatrix [,1] [,2] [,3] [,4] [1,] 1 7 13 19 [2,] 2 8 14 20 [3,] 3 9 15 21 [4,] 4 10 16 22 [5,]
2012 Mar 28
6
How to get all possible combinations?
Dear all, suppose I have a vector with elements as: Vec <- c(2,3,4,5,6) Now I want to have all possible combination of length 3 using those elements and without any repetition. Like, I want to have 1 possibility like 2-3-4 but not 3-2-4. Can somebody guide me how to achieve that in R? Thanks for your help.
2011 Jan 27
2
help for a loop procedure
Hello everybody! I’m trying to define the optimal number of surveys to detect the highest number of species within a monitoring season/session. To do this I want to run all the possible combinations between a set of samples and to calculate the total number of species for each combination of 2, 3, 4 …n samples events, so that at the end I will be able to define which is the lowest number of
2012 Feb 09
3
how to exclude rows with not-connected coalitions
Dear all, I have question but cannot explain without providing some context first: I want to calculate how many policy-connected coalitions between 7 parties are possible. I have positions on an one-dimensional scale for each party and I have sorted the parties on the positions (it is sorted from extreme left to extreme right, hence using a left-right scale). A policy-connected coalition
2011 Jan 16
2
how to add a derived column to a data frame?
I have a data frame with 10 columns: A:J and I want to have the output as a data frame with 11 columns, the value of 11th column is£º for each row, if any column can be divided by 13, then the 11th column has a values of 1, otherwise, it has a value of 0. How to do that? input is a=matrix(1:10000,1000,10) dimnames(a)=list(NULL,LETTERS[1:10]) [[alternative HTML version deleted]]
2009 Apr 05
3
number of zeros in a matrix -row by row
Hi. I have an n x m matrix M some of who's entries are zeros. I want to know how many zeros there are in each row -perhaps stored in a 1 x n vector which lists the number of zeros for each row of M. Before I had a vector V and I was able to get the number of zeros in V by doing length(V[ V==0]) but when I try something similar for M, like M[ M==0] it creates a vector not a matrix and so
2011 Apr 04
1
Support Counting
Hi, I'm new to R and trying to some simple analysis. I have a data set with about 88000 transactions and i want to perform a simple support count analysis of an itemset which is say not a complete transaction but a subset of a transaction. say {A,B,D} is a transaction and i want to find support of {A,B} even though it never occurs as only A,B in the entire set To this i needed to create
2010 Feb 03
2
Delete missing value rows from a matrix
Hi everyone, I have a matrix with many Na's. Some rows contain some Na's and some others are entirely composed of Na's. I want to delete the rows that are entirely composed of Na's but not the other ones so I can't use a simple removeNA. Has any one an idea? ----- Anna Lippel -- View this message in context:
2011 Feb 04
2
Avoiding two loops
Hello, I have a R code for doing convolution of two functions: convolveSlow <- function(x, y) { nx <- length(x); ny <- length(y) xy <- numeric(nx + ny - 1) for(i in seq(length = nx)) { xi <- x[[i]] for(j in seq(length = ny)) { ij <- i+j-1 xy[[ij]] <- xy[[ij]] + xi * y[[j]] } } xy } How do I reduce the 2
2012 Feb 28
7
indexing??
Hello All, My algorithm as follows; y <- c(1,1,1,0,0,1,0,1,0,0) x <- c(1,0,0,1,1,0,0,1,1,0) n <- length(x) t <- matrix(cbind(y,x), ncol=2) z = x+y for(j in 1:length(x)) { out <- vector("list", ) for(i in 1:10) { t.s <- t[sample(n,n,replace=T),] y.s <- t.s[,1] x.s <- t.s[,2] z.s <- y.s+x.s out[[i]] <- list(ff <- (z.s), finding=any (y.s==y[j])) kk
2011 Mar 17
2
Counting
I have a matrix say: 23 1 12 12 0 0 0 1 0 1 0 2 23 2 I want to count of number of distinct rows and the number of disinct element in the second column and put these counts in a column. SO at the end of the day I should have: c(1, 1, 1, 2, 2, 1, 1) for the distinct rows and c(1, 1, 1, 2, 2, 2, 2) for the counts of how many times the elements in the second column exists. Any help is
2012 Mar 08
4
Correlation between 2 matrices but with subset of variables
Dear All, I have two matrices A (40 x 732) and B (40 x 1230) and would like to calculate correlation between them.  I can use: cor(A,B, method="pearson") to calculate correlation between all possible pairs. But the issue is that there is one-many specific mappings between A and B and I just need to calculate correlations for those pairs (not all). Some variables in A (proteins, say p1)
2011 Jan 06
4
Creating a Matrix from a vector with some conditions
Hi Suppose we have an object with strings: A<-c("a","b","c","d") Now I do: B<-matrix(A,4,4, byrow=F) and I get a a a a b b b b c c c c d d d d But what I really want is: a b c d b c d a c d a b d a b c How can I do this? thank you A. Dias -- View this message in context:
2011 Nov 04
4
How to delete only those rows in a dataframe in which all records are missing
Hi, Imagine I have the following data frame: > a <- c(1,NA,3) > b <- c(2,NA,NA) > c <- data.frame(cbind(a,b)) > c a b 1 1 2 2 NA NA 3 3 NA I want to delete the second row. If I use na.omit, that would also affect the third row. I tried to use a loop and an ifelse clause with is.na to get R identify that row in which all records are missing, as opposed to the first
2008 Nov 09
2
Delete rows from matrix having at least one zero value
Hi, I have a further question about matrix manipulation. Imagine the following two matrices: > test [,1] [,2] [,3] [,4] [1,] 1 0 6 4 [2,] 2 5 7 5 [3,] 3 6 8 6 [4,] 4 0 0 0 > matrix(is.element(test,0), ncol=4) [,1] [,2] [,3] [,4] [1,] FALSE TRUE FALSE FALSE [2,] FALSE FALSE FALSE FALSE [3,] FALSE FALSE FALSE FALSE [4,] FALSE