similar to: Removing columns that are all NA from a matrix

Displaying 20 results from an estimated 20000 matches similar to: "Removing columns that are all NA from a matrix"

2008 Feb 04
3
counts of each column that are not NA, and/or greater than column means
Hi, Given a test matrix, test <- matrix(c(1,2,3,NA,2,3,NA,NA,2), 3,3) A) How to compute the counts of each column (excluding the NA) i.e., 3, 2, 1 B) How to compute the counts of each column (excluding the NA) that are greater than the column means ? i.e., 1, 1, 0 I could write a for loop, but hope to use better alternative. [[alternative HTML version deleted]]
2005 Jan 05
8
Replacing all NA values in a matrix
OK, dumb question, and it is probably in the docs somewhere, but after 12 months working with R and quite a while looking at the docs, I still don't know (or have forgotten) how to replace all NA values in a matrix at once with some other value. I can do it column by column using is.na(), but I can't figure out how to do it for the whole matrix. My apologies, I am ashamed ;-) Michael
2005 Jan 14
5
Replacing NAs in a data frame using is.na() fails if there are no NAs
Hi This is a difference between the way matrices and data frames work I guess. I want to replace the NA values in a data frame by 0, and the code works as long as the data frame in question actually includes an NA value. If it doesn't, there is an error: df <- data.frame(c1=c(1,1,1),c2=c(2,2,NA)) df[is.na(df)] <- 0 df df <- data.frame(c1=c(1,1,1),c2=c(2,2,2)) df[is.na(df)] <-
2007 Jul 31
5
extract columns of a matrix/data frame
Hello all, I have a matrix whose column names look like a1 a2 b1 b2 b3 c1 c2 1 2 3 7 1 3 2 4 6 7 8 1 4 3 Now, I can have any number of a's. not just two as shown above and same goes for b's and c's. I need to extract all the a's columns and put them in another matrix, extract all b's columns and put them in some matrix
2005 Feb 17
6
Converting a list to a matrix - I still don't think I have it right
Hi We have touched on this before, but I don't think I quite got it right. So I have a list, each element of which is a a vector of 2 numbers: > l2 $cat000_a01 [1] 0.3429944 4.5138244 $cat000_a02 [1] 0.1929336 4.3064944 $cat000_a03 [1] -0.2607796 4.1551591 What I actually want to convert this into is a matrix with the names (cat000_a01 etc) as row names, the first element of each of
2009 Aug 26
3
changing equal values on matrix by same random number
Dear all, I have about 30,000 matrix (512x512), with values from 1 to N. Each value on a matrix represent a habitat patch on my matrix (i.e. my landscape). Non-habitat are stored as ZERO. No I need to change each 1-to-N values for the same random number. Just supose my matrix is: mymat<-matrix(c(1,1,1,0,0,0,0,0,0,0,0, 0,0,0,0,2,2,2,0,0,0,0, 0,0,0,0,2,2,2,0,0,0,0, 3,3,0,0,0,0,0,0,0,4,4,
2010 Mar 23
2
Adding matrix rows that have the same name?
Does anyone know if there is an R function that will take a matrix like this jim 1 0 0 0 0 0 jim 0 1 0 0 0 0 jim 0 0 1 0 0 0 bob 1 0 0 0 0 0 bob 0 0 1 0 0 0 harry 0 0 1 0 0 0 harry 0 0 0 1 0 0 harry 0 0 0 0 1 0 harry 0 0 0 0 0 1 and make it like this? (that is, add together rows that have the same name?) jim 1 1 1 0 0 0 bob
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
2008 Feb 11
4
Conditional rows
Hi, Given a simple example, test <- matrix(c(0.1, 0.2, 0.1, 0.2, 0.1, 0.1, 0.3, 0.1, 0.1), 3, 3) How to generate row indexes for which their corresponding row values are less than or equal to 0.2 ? For this example, row 2 and 3 are the correct ones. Thanks [[alternative HTML version deleted]]
2007 May 20
2
Number of NA's in every second column
Hi R-users, How do I calculate a number of NA's in a row of every second column in my data frame? As a starting point: dfr <- data.frame(sapply(x, function(x) sample(0:x, 6, replace = TRUE))) dfr[dfr==0] <- NA So, I would like to count the number of NA in row one, two, three etc. of columns X1, X3, X5 etc. Thanks in advance Lauri [[alternative HTML version deleted]]
2004 May 27
4
extract columns using their names
Hello, Is there a way to extract multiple columns from a dataframe using their names instead of their numbers? Currently I use: data2 <- data1[, c(1,3,9)] And I am looking for something like data2 <- data1[, c("XX","YY","ZZ")] I use the same dataframe for many purposes, and I run codes that change the order of the columns every time. Many thanks, Adrian
2006 Aug 14
3
column to row
Dear mailing list I have a data in two columns and how can i convert it to one row . thank you in advance inpute 1 2 3 4 5 6 7 8 9 1 out put 1 2 3 4 5 6 7 8 9 1 [[alternative HTML version deleted]]
2009 Nov 12
1
how to pass matrices from C to R effectively
Hi, I have C code to produce a lot of matrices to be analyzed. As these matrices are large (> 1000*10000) and are a lot (> 1000), I am thinking about how to pass them from C to R effectively. Would you think about the following solution? In R, I create a wrapper function passDataFromCToR = function(row, col) { mat = matrix(0, row, col) .C("passDataFromCToR",mat)[[1]] }
2008 Mar 02
3
elegant way to minus on each row of a matrix
How to do this in an elegant way formatrix/data frame/zoo? mat= 1 2 3 4 5 6 7 8 9 vector= 1 2 3 result= 0 1 2 2 3 4 4 5 6 ie 1-1 2-1 3-1 4-2 5-2 6-2 7-3 8-3 9-3 Thanks in advance. _________________________________________________________________ 08 [[alternative HTML version deleted]]
2007 Aug 20
1
Select rows of matrix
Hi I would appreciate if anyone could help me with an elegant solution of the following: I have a matrix that contain a small number of -Inf values. How can form a new matrix from the old one that excludes all the rows with -Inf values ? Thank you. Jacob Dept of Statistics University of Johannesburg South Africa [[alternative HTML version deleted]]
2006 Feb 14
3
Inf values in a matrix
Hello, I have some Inf values in a matrix, but I don't want to replace them with some value but rather remove the rows that contain the Inf values. Also I would like to record the rows which were removed. Is there an easy way to do this instead of writing loops over the matrix? Thanks. Ita Cirovic Donev
2008 Jul 25
3
Help with rep
Hi Is it possible to use the rep command (or maybe some other "shortcut") to create a vector with the following format: 4 3 4 2 3 4 1 2 3 4 Any help is much appreciated. Thanks Jacob Jacob L van Wyk Department of Statistics University of Johannesburg, APK Box 524 Auckland Park 2006 South Africa Office Tel: +27 11 559 3080 Fax: +27 11 559 2832 [[alternative HTML version
2005 Sep 09
3
how to do something like " subset(mat, ("col1">4 & "col2">4)) "
Dear all, I have a problem with the "subset()" function. I spent all day yesterday with a collegue to solve it and we did not find a satisfying solution (even in the archived mails), so I ask for your help. Let's say (for a simple example) a matrix mat: R> mat cola colb colc [1,] 1 4 7 [2,] 2 5 8 [3,] 3 6 9 My goal is to select the lines of the matrix on the basis of the
2008 Mar 13
2
joining matrices, vectors, scalars in one object
Hi, I have: a <- matrix(c(0,1,0,1),nrow=2) b <- matrix(c(1,1,1,0,0,0),nrow=3) c <- 1 d <- c(1,0,1) And I would like to join them in an object 'thing' so that I can access a, b, c, or d through an index in a for loop. For example: thing[4] would return [1] 1 0 1 Note however, that I have many of these 'thing' components. So many that a command like thing
2007 Jul 18
3
how to combine presence only data sets to one presence/absence table
Problem: I have a Set of samples each with a list of observed species (presence only). Data is stored in a excel spreadsheet and the columns (spl) have different numbers of observations (spcs). Now I want to organize the data in a species by sample matrix with presence/absence style in R. data style (in excel): spl_A spl_B spl_C spcs1 spcs1 spcs2 spcs2 spcs3 spcs3 spcs4 spcs5 spcs5 desired