0

I have a large data frame with a character value in various columns and rows. The character is [subnet].

I am trying to get rid of it by writing the following code

new_data[]=lapply(new_data, gsub, pattern="[subnet]", replacement='')

However, it seems like although "subnet" is disappearing, I am ending up with "[]" for every instance of the character.

Any idea or fix would be appreciated.

J Doe
  • 317
  • 1
  • 4
  • 12
  • 2
    You need to remove the square bracket because it is looking for character 's', 'u', 'b', 'n', 'e' and 't' instead of subnet `lapply(new_data, gsub, pattern="subnet", replacement='')`. Think about how we use `[a-z]` looling for characters from a through z. Here, it is replacing with those letters specified – akrun Jan 31 '19 at 19:00
  • 3
    In addition to @akrun 's comment, if your character is really `"[subnet]"`, try to escape the brackets like so: `pattern="\\[subnet\\]"`. – jay.sf Jan 31 '19 at 19:05
  • 3
    ... or use `fixed = TRUE`. – markus Jan 31 '19 at 19:06
  • Another option would be `new_data[new_data == '[subnet]'] <- ""` – markus Jan 31 '19 at 19:11

0 Answers0