[R] change the class of an object within with()

From: François MICHONNEAU <francois.michonneau_at_gmail.com>
Date: Tue 27 Jun 2006 - 19:54:22 EST


Hello,

Can anyone explain me what is wrong in the following code? and in particular why it is not possible to change the class of an object thanks to the function with(). Does an alternative exist?

xxx <- data.frame(x = c("a","b","c","d","e"), y = c("1","2","3","4","5")) str(xxx)
with(xxx, {

	x <- as.character(x)
	y <- as.numeric(y)

})
str(xxx) #no effect on the class of x and y

xxx$x <- as.character(xxx$x)
xxx$y <- as.numeric(xxx$y)
str(xxx)

Thanks

François Michonnneau



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 Received on Tue Jun 27 21:08:08 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 Tue 27 Jun 2006 - 22:12:29 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.