Daniel Bradley
2009-May-26 23:12 UTC
[R] Finding and removing non-printable ascii characters in a file
Hi! I'm completely confusing myself attempting to solve this one. Is there a simple way of removing particular ASCII characters from a CSV file using R. Hopefully something simpler and faster than cycling through each individual character and comparing them to a list of characters to remove then deleting as necessary. As always, any help would be appreciated. Thanks! Dan [[alternative HTML version deleted]]
jim holtman
2009-May-26 23:59 UTC
[R] Finding and removing non-printable ascii characters in a file
You can use readLines to read the data in and then gsub to remove the characters you don't want and the textConnection to 'read' in the processed data.> x <- readLines("/tempxx.txt") > # show data > x[1] "al;skdjf a;lskdjf s;aldkfj asd;lfkj " "_)(*)(*&*(&^ &*(^%*&^%" [3] "a;lskdfj z,xmcvn -129037854 b qwepoiru" "1234l;kjasdfmnb5"> # now delete all numbers using regular expression (substitute yourcharacters)> # you can put any characters you want separated by '|' > x.d <- gsub("0|1|2|3|4|5|6|7|8|9", '', x) > # reread using textConnection > x.new <- readLines(textConnection(x.d)) > x.new[1] "al;skdjf a;lskdjf s;aldkfj asd;lfkj " "_)(*)(*&*(&^ &*(^%*&^%" [3] "a;lskdfj z,xmcvn - b qwepoiru" "l;kjasdfmnb">On Tue, May 26, 2009 at 7:12 PM, Daniel Bradley <dannyboy477@gmail.com>wrote:> Hi! > > I'm completely confusing myself attempting to solve this one. Is there a > simple way of removing particular ASCII characters from a CSV file using R. > Hopefully something simpler and faster than cycling through each individual > character and comparing them to a list of characters to remove then > deleting > as necessary. > > As always, any help would be appreciated. > > Thanks! > Dan > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@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<http://www.r-project.org/posting-guide.html> > and provide commented, minimal, self-contained, reproducible code. >-- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? [[alternative HTML version deleted]]
Apparently Analagous Threads
- How to set content_transfer_encoding to something other than quoted-printable?
- [PATCH] hivexregedit: Add --unsafe-printable-strings option.
- [PATCH] Coalesce printable characters in debug and trace messages (RHBZ#802109).
- Re: [PATCH nbdkit 3/5] protocol: Generate map functions from NBD protocol flags to printable strings.
- A printable PDF that documents centos 6.3