0

So I am trying to use an if then statement in R or an if then print.

if (Futures$Edge =="NONE") {Futures$Accuracy3->"NA"}

I want to make the accuracy3 NA if the edge is NONE, but after a lot of searching online I can't find one solution that doesn't insist on using ifelse.
I do not want to use ifelse because I have another if else previously that would be negated.

the full code is

Futures$Accuracy3<- ifelse((Futures$Edge =="EDGE") & (Futures$Guess2 == Futures$Result) , 1, 0) if (Futures$Edge =="NONE") {Futures$Accuracy3->"NA"}

I continue to get the error message

Warning message: In if (Futures$Edge == "NONE") { : the condition has length > 1 and only the first element will be used

here is a screenshot of the data.

enter image description here

I do not want any of the NONE edges to print a 0 or 1, simply NA. Not trying to use mutate.

1 Answers1

0

What about:

#fake data    Futures<-data.frame(Edge=c('NONE','EDGE','EDGE','EDGE','EDGE','NONE','EDGE','NONE','EDGE')
                       ,Accuracy3=c(0,0,1,1,0,0,1,1,1))

#replace the column Accuracy3 with the ifelse    
Futures$Accuracy3 <- ifelse(Futures$Edge=='NONE', NA, Futures$Accuracy3)
> Futures
  Edge Accuracy3
1 NONE        NA
2 EDGE         0
3 EDGE         1
4 EDGE         1
5 EDGE         0
6 NONE        NA
7 EDGE         1
8 NONE        NA
9 EDGE         1
s__
  • 9,270
  • 3
  • 27
  • 45
  • Eureka! Thank you. – Arian Modarres Sep 07 '18 at 19:53
  • Glad it worked! @ArianModarres if this or any answer has solved your question please consider accepting it by clicking the check-mark. This indicates to the wider community that you've found a solution and gives some reputation to both the answerer and yourself. There is no obligation to do this. – s__ Sep 07 '18 at 19:54