[R] Removing backslashes from data
Duncan Murdoch
murdoch at stats.uwo.ca
Fri Apr 3 21:01:54 CEST 2009
On 4/3/2009 2:33 PM, Andrew Conway wrote:
> I am trying to check for backslashes in data, then remove them when I
> find them, but am having a difficult time figuring out the best way to
> do it. I know the backslash is the escape character in R, and I
> should be able to use 'gsub' to accomplish this, but I all I seem to
> be getting are errors. For example:
>
> If entry is:
> "Hello\World"
>
> I want:
> "HelloWorld"
>
> There are several entries with backslashes, and I need to find them
> and delete them. All help is welcome, thank you.
This gets a little confusing because print() automatically doubles
backslashes. To see what's really going on, you need to use cat. Then
the following can be seen to work:
input <- "\"Hello\\World\""
cat(input, "\n")
output <- gsub("\\\\", "", input)
cat(output, "\n")
Duncan Murdoch
>
> ___________________________________
> Drew Conway
> Ph.D. Student
> Department of Politics, New York University
> agc282 at nyu.edu
> http://homepages.nyu.edu/~agc282
>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help
mailing list