[R] how to delete columns with NA values?

2010-04-14 Thread muting
Hi everyone: I have a dataset: tm1 col1 col2 [1,]1 NA [2,]11 [3,]22 [4,]11 [5,]22 [6,]1 NA I need to delete entire column 2 that has NA in it(not all of them are NAs), and the result I want is tm1 col1 [1,]1 [2,]1 [3,]2

Re: [R] how to delete columns with NA values?

2010-04-14 Thread Erik Iverson
Hello, muting wrote: Hi everyone: I have a dataset: This looks like a matrix. To perform functions on each row or column of a matrix, use the apply function. If you had a data.frame, you could perform a function on each column using sapply or lapply. tm1 col1 col2 [1,]1 NA

Re: [R] how to delete columns with NA values?

2010-04-14 Thread Chuck Cleland
On 4/14/2010 10:56 AM, muting wrote: Hi everyone: I have a dataset: tm1 col1 col2 [1,]1 NA [2,]11 [3,]22 [4,]11 [5,]22 [6,]1 NA I need to delete entire column 2 that has NA in it(not all of them are NAs), and the result I want is

Re: [R] how to delete columns with NA values?

2010-04-14 Thread muting
Thank you all! It works well now -- View this message in context: http://n4.nabble.com/how-to-delete-columns-with-NA-values-tp1839902p1839953.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list

Re: [R] how to delete columns with NA values?

2010-04-14 Thread Stefan Uhmann
Hi muting, # your data muting - data.frame(col1 = c(1,1,2,1,2,1), col2=c(NA,1,2,1,2,NA)) # 1. finding rows with NA is.na(muting) # 2. counting the NAs per column colSums(is.na(muting)) # 3. keeping only the ones without NAs muting[,colSums(is.na(muting)) == 0] Regards, Stefan schrieb muting,