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
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
dat$V2 <- replace(as.character(dat$V2), dat$V2 == "-sh2", "-100")
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