Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Handle dots in filenames [duplicate]

Tags:

r

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!

like image 314
user11916948 Avatar asked Dec 07 '25 03:12

user11916948


1 Answers

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" 
like image 175
Johnny Avatar answered Dec 08 '25 16:12

Johnny



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!