-2

I am trying to remove all the period characters (.) from a data.table using gsub. Unfortunately, it isn't working. How do you propperly express the pattern to describe the periods to then replace them by nothing?

My code:

dt[, Address := gsub(".", "", Address)]

Result:

head(dt$Address)
[1] "" "" "" "" "" ""

I'm guessing that when pattern = "." R thinks I'm refering to the entire content of the object in question. What am I doing wrong?

Arturo Sbr
  • 5,567
  • 4
  • 38
  • 76

1 Answers1

2

I think you just need to escape the period. Try:

dt[, Address := gsub("\\.", "", Address)]
jalind
  • 491
  • 1
  • 5
  • 11