0

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.

Kent
  • 21
  • 2

2 Answers2

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