Re: [R] read.csv issue

From: Doran, Harold <HDoran_at_air.org>
Date: Thu 17 Aug 2006 - 05:15:43 EST


OK, thanks to you and Carlos. I see how this works. Now, I just want 1 "\" (miktex doesn't work with \\). I tried tinkering around with what you have for the replacement portion of the function. Is it possible to only have only one \?


	From: jim holtman [mailto:jholtman@gmail.com] 
	Sent: Wednesday, August 16, 2006 3:10 PM
	To: Doran, Harold
	Cc: r-help@stat.math.ethz.ch
	Subject: Re: [R] read.csv issue
	
	
	Try 'gsub'
	 

> y
schid sch_name 1 331-802-7081 School One 2 464-551-7357 School Two 3 388-517-7627 School Three & Four 4 388-517-4394 School Five
> levels(y$sch_name) <- gsub("&", " \\\\&", levels(y$sch_name))
> y
schid sch_name 1 331-802-7081 School One 2 464-551-7357 School Two 3 388-517-7627 School Three \\& Four 4 388-517-4394 School Five
>
On 8/16/06, Doran, Harold <HDoran@air.org> wrote: I'm trying to read in some data from a .csv format and have come across the following issue. Here is a simple example for
replication                 
		# A sample .csv format
		schid,sch_name
		331-802-7081,School One
		464-551-7357,School Two
		388-517-7627,School Three \& Four
		388-517-4394,School Five
		
		Note the third line includes the \ character. However,
when I read the 
		data in I get
		
		> read.csv(file.choose())
		        schid              sch_name
		1 331-802-7081            School One
		2 464-551-7357            School Two
		3 388-517-7627 School Three & Four
		4 388-517-4394           School Five 
		
		It turns out to be very important to read in this
character as I have a
		program that loops through a data set and Sweave's about
30,000 files.
		The variable sch_name gets dropped into the tex file
using
		\Sexpr{tmp$sch_name}. However, if there is an &, the
latex file won't 
		compile properly. So, what I need is for the data to be
read in as                 
		        schid              sch_name
		1 331-802-7081            School One
		2 464-551-7357            School Two
		3 388-517-7627 School Three \& Four 
		4 388-517-4394           School Five
		
		I am obligated by a client to include the & in the
school name, so
		eliminating that isn't an option. I thought maybe
comment.char or quote
		would be what I needed, but they didn't resolve the
issue. I'm certain 
		I'm missing something simple, I just can't see it.
		
		Any thoughts?
		
		Harold
		
		
		
		       [[alternative HTML version deleted]]
		
		______________________________________________
		R-help@stat.math.ethz.ch 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.                 
	-- 
	Jim Holtman
	Cincinnati, OH
	+1 513 646 9390
	
	What is the problem you are trying to solve? 


	[[alternative HTML version deleted]]

______________________________________________
R-help@stat.math.ethz.ch 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. Received on Thu Aug 17 05:27:50 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Thu 17 Aug 2006 - 06:24:51 EST.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.