1

I have a little question concerning value replacement in a DF. I know how to replace value using ifelse statement but does exist some function which allows us to don't specify the else condition.

df <- data.frame(ID = paste0("ID",1:10),VAL = sample(10,10,replace=T),stringsAsFactors = F)

df$VAL <- ifelse(df$VAL == 1,"*",df$VAL)

Thanks

2
  • 4
    df$VAL[df$VAL == 1] <- '*' ? Commented Apr 3, 2018 at 10:17
  • 1
    That's work fine, thank you ! Commented Apr 3, 2018 at 10:26

1 Answer 1

1

You can simply use :

 your_val = 1 
 df[df$VAL == your_val,"VAL"] <- "*"
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.