Hi folks,

I would like to trim the trailing spaces in my factor variables using lapply
(described in this post by Marc Schwartz:
http://tolstoy.newcastle.edu.au/R/e2/help/07/08/22826.html) but the code is
not functioning (in this example there is only one factor with trailing
spaces):

y1 <- rnorm(20) + 6.8
y2 <- rnorm(20) + (1:20*1.7 + 1)
y3 <- rnorm(20) + (1:20*6.7 + 3.7)
y <- c(y1,y2,y3)
x <- gl(5,12)
f <- gl(3,20, labels=paste("lev", 1:3, "   ", sep=""))
d <- data.frame(x=x,y=y, f=f)
str(d)

d[] <- lapply(d, function(x) ifelse(is.factor(x), sub(" +$", "", x), x))
str(d)

How should I modify this?

-Lauri

	[[alternative HTML version deleted]]

