[R] stripping #s in a text file prior to reading into table or dataframe

Duncan Murdoch murdoch.duncan at gmail.com
Tue Oct 26 16:49:57 CEST 2010


On 26/10/2010 10:33 AM, Donald Braman wrote:
> I'm importing a lot of text tables of data (from Latent Gold) that includes
> hashes in some of the column names ("Cluster#1", "Cluster#2", etc.).  Is
> there an easy way to strip the offending hashes out before pushing the text
> into a table or data frame?  I thought I'd use gsub, e.g., but can't figure
> out how to read in a text file without reading it into a table or data frame
> (which would be ill structured, given the hashes).  I could do it in another
> scripting language or shell script, but would like to try to do it in R.

readLines() will read it, but you may not need to do that.  Set 
comment.char="" to turn off the special meaning of # in read.table() and 
related functions.

Duncan



More information about the R-help mailing list