thanks
>
> m
>
>
> - Messaggio originale -
> Da: "Bert Gunter"
> A: "Massimo Bressan"
> Cc: "r-help"
> Inviato: Mercoledì, 22 novembre 2017 17:32:33
> Oggetto: Re: [R] assign NA to rows by test on multiple col
same basic
structure as the simplified example I posted
thanks
m
- Messaggio originale -
Da: "Bert Gunter"
A: "Massimo Bressan"
Cc: "r-help"
Inviato: Mercoledì, 22 novembre 2017 17:32:33
Oggetto: Re: [R] assign NA to rows by test on multiple columns of
Do you mean like this:
mydf <- within(mydf, {
is.na(A)<- !A_flag
is.na(B)<- !B_flag
}
)
> mydf
A A_flag B B_flag
1 8 10 5 12
2 NA 0 6 9
3 10 1 NA 0
4 NA 0 1 5
5 5 2 NA 0
Cheers,
Bert
Bert Gunter
"The trouble with h
Hi--
I too misread the question twice and i may have mistakenly posted non-text
answer earlier. Below is a step by step solution that works provided that
your real data frame has the same structure (alternative columns as in your
example). You could combine all the steps in 2 statements.
Best of
OPS,
Sorry i did not read the post carfully. Mine will not work if you have
zeros on columns A and B.. But you could modify it to work for specific
columns i believe.
EK
On Wed, Nov 22, 2017 at 8:37 AM, Ek Esawi wrote:
> Hi *Massimo,*
>
> *Try this.*
>
> *a <- mydf==0mydf[a] <- NAHTHEK*
>
> On
Hi *Massimo,*
*Try this.*
*a <- mydf==0mydf[a] <- NAHTHEK*
On Wed, Nov 22, 2017 at 5:34 AM, Massimo Bressan <
massimo.bres...@arpa.veneto.it> wrote:
>
>
> Given this data frame (a simplified, essential reproducible example)
>
>
>
>
> A<-c(8,7,10,1,5)
>
> A_flag<-c(10,0,1,0,2)
>
> B<-c(5,6,2,1,0
;Rui Barradas"
A: "Massimo Bressan" , "r-help"
Inviato: Mercoledì, 22 novembre 2017 11:49:08
Oggetto: Re: [R] assign NA to rows by test on multiple columns of a data frame
Hello,
Try the following.
icol <- which(grepl("flag", names(mydf)))
mydf[icol] <- lapply
p"
Inviato: Mercoledì, 22 novembre 2017 11:49:08
Oggetto: Re: [R] assign NA to rows by test on multiple columns of a data frame
Hello,
Try the following.
icol <- which(grepl("flag", names(mydf)))
mydf[icol] <- lapply(mydf[icol], function(x){
is.na(x) <- x == 0
Hello,
Try the following.
icol <- which(grepl("flag", names(mydf)))
mydf[icol] <- lapply(mydf[icol], function(x){
is.na(x) <- x == 0
x
})
mydf
# A A_flag B B_flag
#1 8 10 5 12
#2 7 NA 6 9
#3 10 1 2 NA
#4 1 NA 1 5
#5 5 2 0 NA
9 matches
Mail list logo