Message-ID: <AANLkTimjbuKZiQo28Oef3SCz1PWtdHyV3y3cCuNU7VeU@mail.gmail.com>
Date: 2011-01-17T13:14:21Z
From: jim holtman
Subject: Finding NAs in DF
In-Reply-To: <ih142e$ufq$1@dough.gmane.org>
building on the previous responses, does this give you what you want:
> x
A B
1 1 1
2 2 NA
3 NA NA
4 NA 4
> # determine where the NAs are
> row.na <- apply(x, 1, is.na)
> # now convert to list of columns with NAs
> apply(row.na, 2, function(a) paste(colnames(x)[a], collapse = ','))
[1] "" "B" "A,B" "A"
>
>
On Mon, Jan 17, 2011 at 5:01 AM, Johannes Graumann
<johannes_graumann at web.de> wrote:
> Hi,
>
> What is an efficient way to take this DF
>
> ? ? ? ?data.frame(A=c(1,2,NA,NA),B=c(1,NA,NA,4))
>
> and get
> ? ? ? ?c(NA,"TWO","BOTH","ONE")
>
> as the result, where NA corresponds to a row without "NA"s, TWO indicates NA
> in the second and ONE in the first column.
>
> Thanks for any pointers.
>
> Joh
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
--
Jim Holtman
Data Munger Guru
What is the problem that you are trying to solve?