Is there a way to add "." at the end of each cell of a column? something similar to : Add characters to a numeric column in dataframe but at the end of the value.
Asked
Active
Viewed 822 times
2 Answers
2
With paste
, it is easier
df1$V1 <- paste0(df1$V1, ".")
Or using sprintf
df1$V1 <- sprintf("%s.", df1$V1)

akrun
- 874,273
- 37
- 540
- 662
1
You can use regex and sub
and backreference:
a <- c("abc", "dfg", "hij", "xyz")
sub("^(.*)$", "\\1.", a)
[1] "abc." "dfg." "hij." "xyz."

Chris Ruehlemann
- 20,321
- 4
- 12
- 34
-
1or `sub("$", ".", a)` – rawr Jun 30 '20 at 20:38