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
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
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
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
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,
5 matches
Mail list logo