2

How can I replace, for example, all "-sh2", in a column (V2) with -100, as in the following dataframe:

V1  V2  V3
p1  -sh2    13
p2  23  29
p3  17  25
p4  -sh2    34

Thanks

1

2 Answers 2

4
dat$V2 <- replace(as.character(dat$V2), dat$V2 == "-sh2", "-100")
Sign up to request clarification or add additional context in comments.

Comments

2

There are many ways to do this. You can use the replace solution above. Or use ifelse. Or even:

my.df$V2[my.df$V2 == "-sh2"] <- -100

1 Comment

Many thanks Simon, Sven and rrs for the perfect solutions.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.