Thank you very much got something running now based on this.
Joh
jim holtman wrote:
> 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
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] ""
Maybe something along the lines:
apply(df,1, FUN=function(x) which(is.na(x)))
It's not exactly what you want, but it might work combined with the
other solutions
HTH,
Ivan
Le 1/17/2011 12:23, Johannes Graumann a écrit :
Both versions do not do what I am looking for, as they do not differenti
Try this:
factor(sapply(apply(is.na(df), 1, which), sum), labels = c("NA", "TWO",
"BOTH", "ONE"))
On Mon, Jan 17, 2011 at 9:23 AM, Johannes Graumann wrote:
> Both versions do not do what I am looking for, as they do not differentiate
> where the NA is, if there is just one.
> My original wished
Both versions do not do what I am looking for, as they do not differentiate
where the NA is, if there is just one.
My original wished for result therefore holts, but should probably be
rewritten
c(NA,"B","AB","A")
Joh
On Monday 17 January 2011 14:06:30 Patrick Burns wrote:
> Simpler wou
Simpler would be:
rowSums(is.na(df))
On 17/01/2011 10:13, Ivan Calandra wrote:
Hi,
I hope you made a mistake in c(NA,"TWO","BOTH","ONE") because if not, I
have no idea what you're looking for...
But would that do?
df <- data.frame(A=c(1,2,NA,NA),B=c(1,NA,NA,4))
apply(df,1, FUN=function(x) le
Hi,
I hope you made a mistake in c(NA,"TWO","BOTH","ONE") because if not, I
have no idea what you're looking for...
But would that do?
df <- data.frame(A=c(1,2,NA,NA),B=c(1,NA,NA,4))
apply(df,1, FUN=function(x) length(x[is.na(x)]))
[1] 0 1 2 1
There might be better ways to do it, but it works
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
_
8 matches
Mail list logo