I want to change the "." in the middle of each character name to _, but I dont know how to specify that when there are several ".". Does anyone have a suggestion?
Another problem is that it doesnt seem to like the "." When I try to change all "." to _, it doesnt work. How to handle this?
From: "L234.346546.24.3654" "L34.547567.78.79878" "L456.7474.22.07806"
Expected outcome:
"L234.346546_24.3654" "L34.547567_78.79878" "L456.7474_22.07806"
v <- c("L234.346546.24.3654", "L34.547567.78.79878", "L456.7474.22.07806")
vv <- gsub(".", "_", v)
vv
[1] "___________________" "___________________" "__________________"
Thanks!
This should do it:
v <- c("L234.346546.24.3654", "L34.547567.78.79878", "L456.7474.22.07806")
vv <- gsub("(\\..*?)\\.", "\\1_", v)
vv
Output:
[1] "L234.346546_24.3654" "L34.547567_78.79878" "L456.7474_22.07806"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With